Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile not deleting intermediate files

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?

like image 772
darksky Avatar asked Jun 08 '26 10:06

darksky


2 Answers

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.

like image 129
Basile Starynkevitch Avatar answered Jun 11 '26 03:06

Basile Starynkevitch


The special target .INTERMEDIATE doesn't work with the % wildcard. Try this:

.INTERMEDIATE: stack.o prefixer.o
like image 35
Beta Avatar answered Jun 11 '26 03:06

Beta