diff options
author | cathook <b01902109@csie.ntu.edu.tw> | 2014-05-02 04:10:56 +0800 |
---|---|---|
committer | cathook <b01902109@csie.ntu.edu.tw> | 2014-05-02 04:10:56 +0800 |
commit | 33d419e4d54d969798af80f05e05f0c447a99594 (patch) | |
tree | c78355a2d334e34df865aca865dbb4864a85820c /GNUmakefile | |
parent | d2d7a49563a8f04bd07264a4a989d5656313d375 (diff) | |
download | meow-33d419e4d54d969798af80f05e05f0c447a99594.tar meow-33d419e4d54d969798af80f05e05f0c447a99594.tar.gz meow-33d419e4d54d969798af80f05e05f0c447a99594.tar.bz2 meow-33d419e4d54d969798af80f05e05f0c447a99594.tar.lz meow-33d419e4d54d969798af80f05e05f0c447a99594.tar.xz meow-33d419e4d54d969798af80f05e05f0c447a99594.tar.zst meow-33d419e4d54d969798af80f05e05f0c447a99594.zip |
big change about dir structure
Diffstat (limited to 'GNUmakefile')
-rw-r--r-- | GNUmakefile/GNUmakefile | 77 | ||||
-rwxr-xr-x | GNUmakefile/GNUmakefile.dependency.bash | 21 |
2 files changed, 98 insertions, 0 deletions
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.$$ |