Change file name to directory name

OK, I am not sure whether anybody really needs something like this. But, in case you want to change your executable name to the same name as your directory name, try this

BASENAME := $(notdir $(CURDIR))

all: copy exe

copy:
        @cp main.cpp $(BASENAME).cpp

exe: copy $(BASENAME).cpp
        gcc -o $(BASENAME).o $(BASENAME).cpp

Leave a comment

Your comment