fix
fix

Reputation: 2175

makefile not cleaning up everything

I am trying to figure out why my makefile is leaving behind all the *.o files. The clean: section clearly has:

rm *.o *.s *.bc fib fact1 fact2 *~

I've tried adding -f and several other parameters to rm without any luck. What would be causing these to not be removed? Here is the full makefile. I call it with

make -f Makefile

OFILES= fib.o
OFILES1= fact1.o
OFILES2= fact2.o
CPATH=~/cse/llvm/bin/
LLVMASY=$(CPATH)llvm-as
LLVMOPT=$(CPATH)opt
LLVMLC=$(CPATH)llc
AS=clang -c
LD=clang

all: fib fact1 fact2

fib: $(OFILES)
        $(LD) $(OFILES) $(LIBS) -o $@

fact1: $(OFILES1)
        $(LD) $(OFILES1) $(LIBS) -o $@

fact2: $(OFILES2)
        $(LD) $(OFILES2) $(LIBS) -o $@

%.o : %.s
        $(AS) $< -o $@

%.s : %.bc
        $(LLVMLC) $< -O=3 -tailcallopt -o $@

%.bc : %.llvm
        $(LLVMASY) $< -o $@

clean:
        rm *.o *.s *.bc fib fact1 fact2 *~

EDIT: I should have added that all of the *.s and *.bc files remove successfully. It's only the *.o files that stay.


Disclaimer: This is homework but this is not the part I'm being evaluated on. My question is out of pure curiosity.

Upvotes: 0

Views: 2780

Answers (2)

Perhaps a clean file already exists. Check with ls -l clean then perhaps do rm -v clean in your terminal.

Also, check with /bin/ls -l -s *.o the ownership of such files. If at some point you did a sudo make they may be root owned so could not be rm by your ordinary user.

BTW, make will use a Makefile if it has one (it tries GNUmakefile, makefile and Makefile in that order)., so the -f Makefile is often not necessary.

Read the documentation of GNU make.

You should have clean a .PHONY target, e.g. add before your clean: rule

 .PHONY: clean

Use also remake, perhaps as remake -x (or remake -x clean in your case) to debug your Makefile

The default target in Makefile-s is the first one, so is all (which should also be marked .PHONY BTW) in your case. To clean, run make clean.

Upvotes: 0

trojanfoe
trojanfoe

Reputation: 122391

If you are invoking make using make -f Makefile then you are not invoking the clean target, you will invoke the first (all) target.

Try:

$ make clean

Upvotes: 4

Related Questions