From 33d419e4d54d969798af80f05e05f0c447a99594 Mon Sep 17 00:00:00 2001 From: cathook Date: Fri, 2 May 2014 04:10:56 +0800 Subject: big change about dir structure --- GNUmakefile/GNUmakefile | 77 +++++++++++++++++++++++++++++++++ GNUmakefile/GNUmakefile.dependency.bash | 21 +++++++++ 2 files changed, 98 insertions(+) create mode 100644 GNUmakefile/GNUmakefile create mode 100755 GNUmakefile/GNUmakefile.dependency.bash (limited to 'GNUmakefile') diff --git a/GNUmakefile/GNUmakefile b/GNUmakefile/GNUmakefile new file mode 100644 index 0000000..8c3d2ef --- /dev/null +++ b/GNUmakefile/GNUmakefile @@ -0,0 +1,77 @@ +INC := inc +SRC := src +OBJ := obj +BIN := bin +DEP := dep + +LIB_INCS := +CXX := g++ +CXXFLAGS := -O2 -Wall -I$(INC) $(LIB_INCS) +CXX_OBJ := $(CXX) -c +CXX_DEP := $(CXX) -MM + +DEPENDENCY_CREATER := ./GNUmakefile.dependency.bash + +OBJECTS := $(patsubst $(SRC)/%.cpp,$(OBJ)/%.o,$(wildcard $(SRC)/*.cpp)) +DEPENDENCYS := $(patsubst $(SRC)/%.cpp,$(DEP)/%.d,$(wildcard $(SRC)/*.cpp)) + +TARGET_FILE := GNUmakefile.targets +TARGETS := + +NAME := empty + +.PHONY: all dep clean init new del add sub + +-include $(TARGET_FILE) + +all: $(TARGETS); + +init: + -@mkdir -p $(BIN) + -@mkdir -p $(SRC) + -@mkdir -p $(INC) + -@mkdir -p $(OBJ) + -@mkdir -p $(DEP) + -@echo '' > $(TARGET_FILE) + +new: + @set -e; echo "Add target '$(NAME)'"; \ + echo 'TARGETS := $$(TARGETS) $$(BIN)/$(NAME)' >> $(TARGET_FILE); \ + echo '$(NAME)_OBJS := $(foreach n,$(OBJS),$$(OBJ)/$(n).o)' >> $(TARGET_FILE); \ + echo '$(NAME)_LIBS := $(LIBS)' >> $(TARGET_FILE); \ + echo '$$(BIN)/$(NAME): $$(OBJ)/$(NAME).o $$($(NAME)_OBJS)' >> $(TARGET_FILE); \ + echo '\t@echo Target: $$@...' >> $(TARGET_FILE); \ + echo '\t@$$(CXX) $$^ $$(CXXFLAGS) `pkg-config --cflags --libs $$($(NAME)_LIBS) 2>/dev/null` -o $$@' >> $(TARGET_FILE); \ + echo '' >> $(TARGET_FILE) + +add: + @set -e; echo "Add Objects $(OBJS) to Target '$(NAME)'"; \ + sed '/^$(NAME)_OBJS :=/s/$$/& $(foreach n,$(OBJS),\$$(OBJ)\/$(n).o)/' $(TARGET_FILE) >$(TARGET_FILE).$$$$; \ + mv -f $(TARGET_FILE).$$$$ $(TARGET_FILE) + @set -e; echo "Add Libraries $(LIBS) to Target '$(NAME)'"; \ + sed '/^$(NAME)_LIBS :=/s/$$/& $(subst /,\/,$(LIBS))/' $(TARGET_FILE) >$(TARGET_FILE).$$$$; \ + mv -f $(TARGET_FILE).$$$$ $(TARGET_FILE) + +sub: + @set -e; echo "Remove Objects $(OBJS) from Target '$(NAME)'"; \ + sed '/^$(NAME)_OBJS :=/s/$(subst \ ,|,$(foreach n,$(OBJS),\$$(OBJ)\/$(n).o))//' $(TARGET_FILE) >$(TARGET_FILE).$$$$; \ + mv -f $(TARGET_FILE).$$$$ $(TARGET_FILE) + @set -e; echo "Remove Libraries $(LIBS) from Target '$(NAME)'"; \ + sed '/^$(NAME)_OBJS :=/s/$(subst \ ,|,$(foreach n,$(LIBS),\$$(OBJ)\/$(n).o))//' $(TARGET_FILE) >$(TARGET_FILE).$$$$; \ + mv -f $(TARGET_FILE).$$$$ $(TARGET_FILE) + +clean: + -rm -f $(BIN)/* + -rm -f $(OBJ)/* 2>/dev/null + -rm -f $(DEP)/* + +dep: $(DEPENDENCY); + +-include $(DEPENDENCYS) + +$(DEPENDENCYS):: $(DEP)/%.d: $(SRC)/%.cpp + $(DEPENDENCY_CREATER) "`$(CXX_DEP) $(CXXFLAGS) $<`" $@ + +$(OBJECTS): $(OBJ)/%.o: $(SRC)/%.cpp $(DEP)/%.d $(DEP)/%.d + @echo 'Objects: $@...' + @$(CXX_OBJ) $(CXXFLAGS) -o $@ $< diff --git a/GNUmakefile/GNUmakefile.dependency.bash b/GNUmakefile/GNUmakefile.dependency.bash new file mode 100755 index 0000000..6d83ca4 --- /dev/null +++ b/GNUmakefile/GNUmakefile.dependency.bash @@ -0,0 +1,21 @@ +#! /bin/bash + +out=`echo $2 | sed -e 's/\\//\\\\\//g'` + +echo $1 \ + | sed -e 's/\\ / /g' \ + | sed -e ':x; /\\$/ {N;s/\\\n//; tx};' \ + | sed -e 's/.*://g' \ + > $2.$$ +rm -f $2 +cat $2.$$ \ + | sed -e 's/^/'$out'::/g' \ + >> $2 +echo -e '\t$(DEPENDENCY_CREATER) "`$(CXX_DEP) $(CXXFLAGS) $<`" $@\n' \ + >> $2 +cat $2.$$ \ + | sed -e 's/ */\n/g' \ + | sed -e 's/$/::;/g' \ + | sed -e 's/^::;$//g' \ + >> $2 +rm -f $2.$$ -- cgit v1.2.3