Destructo-Makefile

I have discovered a most marvelous way to shoot myself in the foot.

Consider a makefile:

PRODUCT = executable
SOURCES = source1.cpp source2.cc
OBJECTS := $(SOURCES:.cpp=.o) $(SOURCES:.cc=.o)

all : $(PRODUCT)

clean : 
    rm -f $(OBJECTS) $(PRODUCT)

$(PRODUCT) : $(OBJECTS)
    $(CXX) $(CPPFLAGS) $(OBJECTS) $(LDFLAGS) -o $(PRODUCT)

%.o : %.cpp
    $(CXX) -c $(CPPFLAGS) $< -o $@

Besides the fact that this won't actually do the compilation correctly, this has a charming little behavior when it carries out the clean target, which goes something like this:

person@machine$ make clean
rm -f source1.o source2.cc source1.cpp source2.o executable

Blammo! You've just rendered the current directory really clean. At some point I'll have to figure out how to do this right, but for now I just gave up and hard coded everything.

No Comments

Comment on this post