Makefile: One-size-fits all (due to http://boost.2283326.n4.nabble.com/mkmakefile-td4702883.html)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This makefile was handwritten by Seth Heeren | |
# Replicates 90% of http://www.multi.fi/~ghaga/mymakefile/ | |
###################################### | |
TARGET_NAME=mymakemaker | |
## Targets | |
########## | |
all: exe dynamic static objs | |
clean: | |
rm -vf $(TARGET_ALL) $(OBJS:%.o=%.d) | |
## COMMON overrides/customizations: | |
################################### | |
CC = gcc | |
CXX = clang++ | |
CXXFLAGS += -std=c++1z | |
LDFLAGS += -l"stdc++fs" | |
BOOST_DIR = /home/sehe/custom/boost | |
CPPFLAGS += -I$(BOOST_DIR) | |
LDFLAGS += -L$(BOOST_DIR)/stage/lib -l"boost_program_options" | |
## GENERIC Rules and variables | |
SOURCES += $(wildcard *.cpp *.CPP *.c++ *.cxx *.C *.c) | |
OBJS += $(SOURCES:=.o) | |
CFLAGS += $(CPPFLAGS) | |
CXXFLAGS += $(CFLAGS) | |
CPPFLAGS += -MMD # automatic .d dependency file generation | |
CFLAGS += -fPIC # required for shared libraries | |
## Targets | |
########## | |
TARGET_ALL = $(TARGET_EXE) $(TARGET_DYNAMIC) $(TARGET_STATIC) $(OBJS) | |
TARGET_EXE = $(TARGET_NAME) | |
TARGET_DYNAMIC = lib$(TARGET_NAME).so | |
TARGET_STATIC = lib$(TARGET_NAME).a | |
exe: $(TARGET_EXE) | |
dynamic: $(TARGET_DYNAMIC) | |
static: $(TARGET_STATIC) | |
objs: $(OBJS) | |
$(TARGET_EXE): | |
$(CXX) $(CXXFLAGS) $^ $(STATICLIBS) $(LDFLAGS) -o $@ | |
$(TARGET_DYNAMIC): | |
$(CXX) $(CXXFLAGS) $^ $(LDFLAGS) -o $@ | |
$(TARGET_STATIC): | |
ar rvs $@ $^ | |
$(TARGET_EXE) $(TARGET_DYNAMIC) $(TARGET_STATIC): $(OBJS) $(STATICLIBS) | |
$(TARGET_DYNAMIC): LDFLAGS+=-shared | |
# Intermediate targets | |
###################### | |
%.c.o:%.c | |
$(CC) $(CFLAGS) -c $< -o $@ | |
%.C.o:%.C | |
$(CC) $(CFLAGS) -c $< -o $@ | |
%.cpp.o:%.cpp | |
$(CXX) $(CXXFLAGS) -c $< -o $@ | |
%.CPP.o:%.CPP | |
$(CXX) $(CXXFLAGS) -c $< -o $@ | |
%.c++.o:%.c++ | |
$(CXX) $(CXXFLAGS) -c $< -o $@ | |
%.cxx.o:%.cxx | |
$(CXX) $(CXXFLAGS) -c $< -o $@ | |
# Include dependencies | |
###################### | |
-include $(OBJS:%.o=%.d) | |
.PHONY: all clean exe dynamic static objs | |
.PRECIOUS: $(OBJS) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment