My Makefile is not deleting intermediate files. I've set .INTERMEDIATE. Here is my Makefile:
OBJECTS=prefixer.o stack.o
CFLAGS=-Werror -Wmissing-prototypes -g
LIBS=-lm
CC=gcc
prefixer : $(OBJECTS)
$(CC) -o prefixer $(OBJECTS) $(LIBS)
prefixer.o : stack.h
$(CC) -c prefixer.c -o $@ $(CFLAGS)
stack.o : stack.c stack.h
$(CC) -c stack.c -o $@ $(CFLAGS)
.INTERMEDIATE: %.o
.PHONY: clean
clean :
-rm prefixer *.o
What is wrong with .INTERMEDIATE?
See Gnu make special targets for role of .INTERMEDIATE
You probably mean
.SECONDARY: $(OBJECTS)
because I think that if you put .INTERMEDIATE then the objects will always be removed, and you probably don't want that. I don't think you can meaningfully put %.o as prerequisites of special targets.
I would suggest to keep the object files so you don't waste time recompiling them.
Running once make -p will teach you a lot about the rules that make knows about.
Using remake -x (i.e. remake) is very helpful, at least to debug complex Makefile-s. You could also use make -d but I find it too verbose.
You may want to use better builders than make e.g. omake.
The special target .INTERMEDIATE doesn't work with the % wildcard. Try this:
.INTERMEDIATE: stack.o prefixer.o
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With