I have a C++ small project using GNU Make. I\'d like to be able to turn the following source files:
src/
a.cpp
b/
b.cpp
c/
c.cpp
Creating the flat directory structure as initially requested.
Does use vpath
to track down the source files, but all the bookeeping is done automagically from the SRC
list.
SRC = a/a.c a/aa.c b/b.c
TARGET = done
FILES = $(notdir $(SRC) )
#make list of source paths, sort also removes duplicates
PATHS = $(sort $(dir $(SRC) ) )
BUILD_DIR = build
OBJ = $(addprefix $(BUILD_DIR)/, $(FILES:.c=.o))
DEP = $(OBJ:.o=.d)
# default target before includes
all: $(TARGET)
include $(DEP)
vpath %.c $(PATHS)
# create dummy dependency files to bootstrap the process
%.d:
echo a=1 >$@
$(BUILD_DIR)/%.o:%.c
echo $@: $< > $(patsubst %.o,%.d,$@)
echo $< >$@
$(TARGET): $(OBJ)
echo $^ > $@
.PHONY: clean
clean:
del $(BUILD_DIR)/*.o
del $(BUILD_DIR)/*.d
Sorry about the ugly echo
's but I only had my win box to test it on.