1

First ever attempt at writing a small Makefile, but hitting a problem - how do I stop it executing make clean after every build?

TASS64=64tass
EXOMIZER=exomizer
EXOMIZERFLAGS=sfx basic -n
VICE=/Applications/VICE/x64.app/Contents/MacOS/x64
VICEFLAGS=-sidenginemodel 1803 -keybuf "\88"
SOURCES=$(wildcard *.asm)
OBJECTS=$(SOURCES:.asm=.prg)

.PRECIOUS=Calvin.prg

all: $(TARGETS)

%.prg: %.asm
    $(TASS64) -C -a -o $@ -i $<

%: %.prg
    $(VICE) $(VICEFLAGS) $<

.PHONY: clean
clean:
    rm $(OBJECTS)
Rob Cowell
  • 1,610
  • 3
  • 18
  • 34
  • 3
    Explicitly list your targets. `clean` is being consumed in your `all` rule, so it's cleaning. – erip Mar 27 '17 at 12:18
  • Hmm, even removing the all rule, it still does it. For example, issuing "make sprites" builds sprites.asm into sprites.prg and executes the prg file, but still then removes sprites.prg afterwards – Rob Cowell Mar 27 '17 at 12:48
  • Is it the whole `Makefile`? I don't see the value of `TARGETS`. – uzsolt Mar 27 '17 at 13:17
  • Well, that's because I omitted it in error. But I've solved this now - answer coming shortly. – Rob Cowell Mar 27 '17 at 13:18

2 Answers2

2

I guess, it does not execute 'make clean'. However, what may happen is that intermediate (secondary) results are deleted. GNU Make does that by default. To prevent make from doing so, mention those intermediate results X1, X2, ... in

 .SECONDARY: X1 X2 ...

Or, in order to leave any secondary result in place, simply type:

 .SECONDARY:

without any specific target.

Frank-Rene Schäfer
  • 3,182
  • 27
  • 51
0

So it turns out the default Make behaviour is to delete the output if there's a build problem. While it builds correctly in this case, my makefile then launches the PRG file in VICE (c64 emulator). It runs correctly, so I quit the emulator.

The quit action returns an exit code that Make treats as an unsuccessful build and thus deletes the output PRG

This is based on this thread - Why does GNU make delete a file - and subsequent testing by removing the target that launches VICE.

Community
  • 1
  • 1
Rob Cowell
  • 1,610
  • 3
  • 18
  • 34
  • 2
    `$(VICE) $(VICEFLAGS) $< || true` is a proposed workaround to make emulator run always 'succeed'. – Alexey Semenyuk Mar 29 '17 at 01:21
  • 1
    More research and testing this morning - because I have the "run" step as the final target, it treats the output of preceding steps as intermediate files and thus deletes them. I'm looking into marking them with the .SECONDARY flag (see https://www.gnu.org/software/make/manual/html_node/Special-Targets.html) – Rob Cowell Mar 29 '17 at 07:52