aboutsummaryrefslogblamecommitdiffstats
path: root/meowpp.test/GNUmakefile
blob: 2e503b8effcf64fcef4427b02d12bc6c9df37271 (plain) (tree)














































































                                                                                                                                    
INC := inc
SRC := src
OBJ := obj
BIN := bin
DEP := dep

LIB_INCS  := 
CXX       := g++
CXXFLAGS  := -Wall -I$(INC) $(LIB_INCS) -g -pedantic -lstdc++ -lm
CXX_OBJ   := $(CXX) -c
CXX_DEP   := $(CXX) -MM

DEPENDENCY_CREATER := ./GNUmakefile.dependency.sh

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 all2 dep clean init new del add sub

all: all2

-include $(TARGET_FILE)

all2: $(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 $@ $<