cookiecutter-make-cpp/{{cookiecutter.project_name}}/Makefile

58 lines
1.2 KiB
Makefile
Raw Permalink Normal View History

2021-02-23 21:54:24 +00:00
CC = gcc
CXX = g++
LD = g++
CXXFLAGS := -std=gnu++20 -Wall -Werror -Wpointer-arith -Wfatal-errors
CXXFLAGS += -flto -O3
#CXXFLAGS += -ggdb3
CFLAGS = -Wall -Werror -Wpointer-arith -Wfatal-errors
ifdef LINK_MOSTLY_STATIC
LDFLAGS := -static-libstdc++ -Wl,-Bstatic -lboost_program_options
LDFLAGS += -Wl,-Bdynamic -lpthread -ldl
LDFLAGS += -Wl,--exclude-libs,ALL
else
LDFLAGS = -lboost_program_options
endif
BUILDDIR = build
OBJECTS =
DEPS := $(OBJECTS:.o=.d) $(BUILDDIR)/{{cookiecutter.app_name}}.d
all: $(BUILDDIR)/{{cookiecutter.app_name}}
$(BUILDDIR)/{{cookiecutter.app_name}}: $(OBJECTS) $(BUILDDIR)/{{cookiecutter.app_name}}.o
@mkdir -p $(dir $@)
@echo link $@
@$(LD) $(CXXFLAGS) $^ -o $@ $(LDFLAGS)
$(BUILDDIR)/%.o: src/%.cpp Makefile
@mkdir -p $(dir $@)
@echo compile $@
@$(CXX) $(CXXFLAGS) -MQ $@ -MM -MF $(patsubst %.o,%.d,$@) $<
@$(CXX) $(CXXFLAGS) -c $< -o $@
$(BUILDDIR)/%.o: src/%.c Makefile
@mkdir -p $(dir $@)
@echo compile $@
@$(CC) $(CFLAGS) -MQ $@ -MM -MF $(patsubst %.o,%.d,$@) $<
@$(CC) $(CFLAGS) -c $< -o $@
install: $(BUILDDIR)/{{cookiecutter.app_name}}
install -m 0755 $^ $(DESTDIR)/usr/bin
clean:
rm -r build/
-include $(DEPS)