Created
February 6, 2014 08:16
-
-
Save zeph1e/8840168 to your computer and use it in GitHub Desktop.
Makefile Template for small project
This file contains hidden or 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
# Makefile template for small project | |
# Yunsik Jang <[email protected]> | |
SYSROOT=/ | |
# If you use custom toolchain specify it | |
TOOLCHAIN_PATH := | |
TOOLCHAIN_PREFIX := | |
ifneq ($(strip $(TOOLCHAIN_PATH)),) | |
CC := $(TOOLCHAIN_PATH)/bin/$(TOOLCHAIN_PREFIX)$(CC) | |
CXX := $(TOOLCHAIN_PATH)/bin/$(TOOLCHAIN_PREFIX)$(CXX) | |
LD := $(TOOLCHAIN_PATH)/bin/$(TOOLCHAIN_PREFIX)$(LD) | |
AR := $(TOOLCHAIN_PATH)/bin/$(TOOLCHAIN_PREFIX)$(AR) | |
endif | |
# specify target binary names: | |
# the source filename which have main function should be same to target name | |
# ex) aa.c or aa.cpp --> aa (binary) | |
TARGETS := \ | |
# If you want to build shared lib, use this. | |
# Also, binaries in $(TARGET) will be linked with this lib | |
TARGETLIBS := \ | |
TARGETLIBOBJS := \ | |
UTILOBJS := \ | |
# specify objects being referenced from $(TARGETS) | |
COMMONOBJ := \ | |
$(UTILOBJS) | |
# specify package name being known to pkg-config | |
PKG_DEPENDENCIES := | |
# if pkg-config path is differ from default one. give it here | |
PKG_CONFIG_PATH := | |
PKG_CFLAGS := \ | |
$(shell export PKG_CONFIG_PATH=$(PKG_CONFIG_PATH); \ | |
$(patsubst %,pkg-config --cflags %,$(PKG_DEPENDENCIES))) | |
PKG_LDFLAGS := \ | |
$(shell export PKG_CONFIG_PATH=$(PKG_CONFIG_PATH); \ | |
$(patsubst %,pkg-config --libs %,$(PKG_DEPENDENCIES))) | |
# write some include and lib flags | |
INCLUDES := \ | |
LIBS := \ | |
DEFINES := \ | |
# some other compiler/linker flags here | |
CFLAGS := -fPIC -rdynamic | |
CXXFLAGS := -fPIC -fpermissive | |
LDFLAGS := | |
all: $(TARGETLIBS) $(TARGETS) | |
%.o:%.c | |
$(CC) -c $< $(INCLUDES) $(PKG_CFLAGS) $(DEFINES) $(CFLAGS) | |
%.o:%.cpp | |
$(CXX) -c $< $(INCLUDES) $(PKG_CFLAGS) $(DEFINES) $(CXXFLAGS) | |
$(TARGETS) : $(COMMONOBJ) $(patsubst %,%.o,$(TARGETS)) $(TARGETLIBS) | |
$(CXX) -o $@ [email protected] $(COMMONOBJ) $(PKG_LDFLAGS) $(LDFLAGS) $(LIBS) $(patsubst %,-l%,$(TARGETLIBS)) | |
$(TARGETLIBS) : $(TARGETLIBOBJS) $(COMMONOBJ) | |
$(CXX) -shared -o [email protected] $(COMMONOBJ) $(TARGETLIBOBJS) $(PKG_LDFLAGS) $(LDFLAGS) $(LIBS) | |
clean: | |
rm -f *.o $(TARGETS) $(patsubst %,lib%.so,$(TARGETLIBS)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment