Skip to content

Instantly share code, notes, and snippets.

@sehe
Last active Apr 5, 2018
Embed
What would you like to do?
# 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