2010-08-24 07:56:08 +08:00
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
# Clients fill in the source files to build
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
# C_SOURCES := main.c
|
|
|
|
|
# CXX_SOURCES :=
|
|
|
|
|
# OBJC_SOURCES :=
|
|
|
|
|
# OBJCXX_SOURCES :=
|
|
|
|
|
# DYLIB_C_SOURCES :=
|
2012-01-11 09:42:58 +08:00
|
|
|
|
# DYLIB_CXX_SOURCES :=
|
|
|
|
|
#
|
|
|
|
|
# Specifying DYLIB_ONLY has the effect of building dylib only, skipping
|
|
|
|
|
# the building of the a.out executable program. For example,
|
|
|
|
|
# DYLIB_ONLY := YES
|
|
|
|
|
#
|
2012-01-17 08:58:08 +08:00
|
|
|
|
# Also might be of interest:
|
2012-01-11 09:59:55 +08:00
|
|
|
|
# FRAMEWORK_INCLUDES (Darwin only) :=
|
|
|
|
|
# CFLAGS_EXTRAS :=
|
|
|
|
|
# LD_EXTRAS :=
|
2012-01-17 08:58:08 +08:00
|
|
|
|
#
|
|
|
|
|
# And test/functionalities/archives/Makefile:
|
|
|
|
|
# MAKE_DSYM := NO
|
|
|
|
|
# ARCHIVE_NAME := libfoo.a
|
|
|
|
|
# ARCHIVE_C_SOURCES := a.c b.c
|
2010-08-24 07:56:08 +08:00
|
|
|
|
|
|
|
|
|
# Uncomment line below for debugging shell commands
|
|
|
|
|
# SHELL = /bin/sh -x
|
|
|
|
|
|
2010-09-17 04:54:06 +08:00
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
# If ARCH is not defined, default to x86_64.
|
2011-06-21 03:06:04 +08:00
|
|
|
|
# If OS is not defined, use 'uname -s' to determine the OS name.
|
2010-09-17 04:54:06 +08:00
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
ifeq "$(ARCH)" ""
|
|
|
|
|
ARCH = x86_64
|
|
|
|
|
endif
|
|
|
|
|
|
2011-06-21 03:06:04 +08:00
|
|
|
|
ifeq "$(OS)" ""
|
|
|
|
|
OS = $(shell uname -s)
|
|
|
|
|
endif
|
|
|
|
|
|
2011-01-15 04:46:49 +08:00
|
|
|
|
#----------------------------------------------------------------------
|
2011-08-24 05:54:10 +08:00
|
|
|
|
# CC defaults to clang.
|
2011-08-25 02:12:53 +08:00
|
|
|
|
#
|
|
|
|
|
# If you change the defaults of CC, be sure to also change it in the file
|
|
|
|
|
# test/plugins/builder_base.py, which provides a Python way to return the
|
|
|
|
|
# value of the make variable CC -- getCompiler().
|
|
|
|
|
#
|
2011-01-15 04:55:13 +08:00
|
|
|
|
# See also these functions:
|
|
|
|
|
# o cxx_compiler
|
|
|
|
|
# o cxx_linker
|
2011-01-15 04:46:49 +08:00
|
|
|
|
#----------------------------------------------------------------------
|
2011-08-24 05:54:10 +08:00
|
|
|
|
CC ?= clang
|
2011-01-15 04:46:49 +08:00
|
|
|
|
ifeq "$(CC)" "cc"
|
2011-08-24 05:54:10 +08:00
|
|
|
|
CC = clang
|
2011-01-15 04:46:49 +08:00
|
|
|
|
endif
|
|
|
|
|
|
2010-08-24 07:56:08 +08:00
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
# Change any build/tool options needed
|
|
|
|
|
#----------------------------------------------------------------------
|
2011-06-21 03:06:04 +08:00
|
|
|
|
CFLAGS ?= -gdwarf-2 -O0
|
2012-01-10 08:41:11 +08:00
|
|
|
|
CFLAGS += $(FRAMEWORK_INCLUDES) $(CFLAGS_EXTRAS)
|
2011-06-21 03:06:04 +08:00
|
|
|
|
ifeq "$(OS)" "Darwin"
|
|
|
|
|
CFLAGS += -arch $(ARCH)
|
2011-12-10 10:15:28 +08:00
|
|
|
|
DS := dsymutil
|
2011-06-21 03:06:04 +08:00
|
|
|
|
DSFLAGS =
|
|
|
|
|
DSYM = $(EXE).dSYM
|
2012-01-13 07:09:42 +08:00
|
|
|
|
AR := libtool
|
|
|
|
|
ARFLAGS := -static -o
|
2011-06-21 03:06:04 +08:00
|
|
|
|
endif
|
|
|
|
|
|
2011-08-10 04:07:16 +08:00
|
|
|
|
CXXFLAGS +=$(CFLAGS)
|
|
|
|
|
LD = $(CC)
|
|
|
|
|
LDFLAGS ?= $(CFLAGS)
|
2012-04-13 08:13:35 +08:00
|
|
|
|
LDFLAGS += $(LD_EXTRAS) -arch $(ARCH)
|
2011-08-10 04:07:16 +08:00
|
|
|
|
OBJECTS =
|
|
|
|
|
EXE ?= a.out
|
|
|
|
|
|
2011-06-21 03:06:04 +08:00
|
|
|
|
ifneq "$(DYLIB_NAME)" ""
|
|
|
|
|
ifeq "$(OS)" "Darwin"
|
|
|
|
|
DYLIB_FILENAME = lib$(DYLIB_NAME).dylib
|
|
|
|
|
else
|
|
|
|
|
DYLIB_FILENAME = lib$(DYLIB_NAME).so
|
|
|
|
|
endif
|
|
|
|
|
endif
|
2010-08-24 07:56:08 +08:00
|
|
|
|
|
2011-01-15 02:19:53 +08:00
|
|
|
|
# Function that returns the counterpart C++ compiler, given $(CC) as arg.
|
|
|
|
|
cxx_compiler = $(if $(findstring clang,$(1)), $(subst clang,clang++,$(1)), $(if $(findstring llvm-gcc,$(1)), $(subst llvm-gcc,llvm-g++,$(1)), $(subst gcc,g++,$(1))))
|
|
|
|
|
|
|
|
|
|
# Function that returns the C++ linker, given $(CC) as arg.
|
2012-01-10 08:00:15 +08:00
|
|
|
|
cxx_linker = $(if $(findstring clang,$(1)), $(subst clang,clang++,$(1)), $(if $(findstring llvm-gcc,$(1)), $(subst llvm-gcc,llvm-g++,$(1)), $(subst gcc,g++,$(1))))
|
2010-09-30 09:22:34 +08:00
|
|
|
|
|
2010-08-24 07:56:08 +08:00
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
# dylib settings
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
ifneq "$(strip $(DYLIB_C_SOURCES))" ""
|
|
|
|
|
DYLIB_OBJECTS +=$(strip $(DYLIB_C_SOURCES:.c=.o))
|
|
|
|
|
endif
|
|
|
|
|
|
2012-02-23 07:57:45 +08:00
|
|
|
|
ifneq "$(strip $(DYLIB_OBJC_SOURCES))" ""
|
|
|
|
|
DYLIB_OBJECTS +=$(strip $(DYLIB_OBJC_SOURCES:.m=.o))
|
|
|
|
|
endif
|
|
|
|
|
|
2012-01-10 08:00:15 +08:00
|
|
|
|
ifneq "$(strip $(DYLIB_CXX_SOURCES))" ""
|
|
|
|
|
DYLIB_OBJECTS +=$(strip $(DYLIB_CXX_SOURCES:.cpp=.o))
|
|
|
|
|
CXX = $(call cxx_compiler,$(CC))
|
|
|
|
|
LD = $(call cxx_linker,$(CC))
|
|
|
|
|
endif
|
2010-08-24 07:56:08 +08:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
# Check if we have any C source files
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
ifneq "$(strip $(C_SOURCES))" ""
|
|
|
|
|
OBJECTS +=$(strip $(C_SOURCES:.c=.o))
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
# Check if we have any C++ source files
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
ifneq "$(strip $(CXX_SOURCES))" ""
|
|
|
|
|
OBJECTS +=$(strip $(CXX_SOURCES:.cpp=.o))
|
2010-09-30 09:22:34 +08:00
|
|
|
|
CXX = $(call cxx_compiler,$(CC))
|
2011-01-15 02:19:53 +08:00
|
|
|
|
LD = $(call cxx_linker,$(CC))
|
2010-08-24 07:56:08 +08:00
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
# Check if we have any ObjC source files
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
ifneq "$(strip $(OBJC_SOURCES))" ""
|
|
|
|
|
OBJECTS +=$(strip $(OBJC_SOURCES:.m=.o))
|
|
|
|
|
LDFLAGS +=-lobjc
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
# Check if we have any ObjC++ source files
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
ifneq "$(strip $(OBJCXX_SOURCES))" ""
|
|
|
|
|
OBJECTS +=$(strip $(OBJCXX_SOURCES:.mm=.o))
|
2010-09-30 09:22:34 +08:00
|
|
|
|
CXX = $(call cxx_compiler,$(CC))
|
2011-01-15 02:19:53 +08:00
|
|
|
|
LD = $(call cxx_linker,$(CC))
|
2012-04-25 07:05:07 +08:00
|
|
|
|
ifeq "$(findstring lobjc,$(LDFLAGS))" ""
|
2010-08-24 07:56:08 +08:00
|
|
|
|
LDFLAGS +=-lobjc
|
|
|
|
|
endif
|
|
|
|
|
endif
|
|
|
|
|
|
2012-01-13 07:09:42 +08:00
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
# Check if we have any C source files for archive
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
ifneq "$(strip $(ARCHIVE_C_SOURCES))" ""
|
|
|
|
|
ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_C_SOURCES:.c=.o))
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
# Check if we have any C++ source files for archive
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
ifneq "$(strip $(ARCHIVE_CXX_SOURCES))" ""
|
|
|
|
|
ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_CXX_SOURCES:.cpp=.o))
|
|
|
|
|
CXX = $(call cxx_compiler,$(CC))
|
|
|
|
|
LD = $(call cxx_linker,$(CC))
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
# Check if we have any ObjC source files for archive
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
ifneq "$(strip $(ARCHIVE_OBJC_SOURCES))" ""
|
|
|
|
|
ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJC_SOURCES:.m=.o))
|
|
|
|
|
LDFLAGS +=-lobjc
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
# Check if we have any ObjC++ source files for archive
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
ifneq "$(strip $(ARCHIVE_OBJCXX_SOURCES))" ""
|
|
|
|
|
ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJCXX_SOURCES:.mm=.o))
|
|
|
|
|
CXX = $(call cxx_compiler,$(CC))
|
|
|
|
|
LD = $(call cxx_linker,$(CC))
|
2012-04-25 07:05:07 +08:00
|
|
|
|
ifeq "$(findstring lobjc,$(LDFLAGS))" ""
|
2012-01-13 07:09:42 +08:00
|
|
|
|
LDFLAGS +=-lobjc
|
|
|
|
|
endif
|
|
|
|
|
endif
|
|
|
|
|
|
2010-08-24 07:56:08 +08:00
|
|
|
|
|
2012-01-10 08:41:11 +08:00
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
# DYLIB_ONLY variable can be used to skip the building of a.out.
|
|
|
|
|
# See the sections below regarding dSYM file as well as the building of
|
|
|
|
|
# EXE from all the objects.
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
2010-08-24 07:56:08 +08:00
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
# Make the dSYM file from the executable if $(MAKE_DSYM) != "NO"
|
|
|
|
|
#----------------------------------------------------------------------
|
2011-06-21 03:06:04 +08:00
|
|
|
|
ifeq "$(OS)" "Darwin"
|
2011-06-21 04:08:26 +08:00
|
|
|
|
ifneq "$(MAKE_DSYM)" "NO"
|
2012-01-10 08:41:11 +08:00
|
|
|
|
ifeq "$(DYLIB_ONLY)" ""
|
2010-08-24 07:56:08 +08:00
|
|
|
|
$(DSYM) : $(EXE)
|
|
|
|
|
$(DS) $(DSFLAGS) -o "$(DSYM)" "$(EXE)"
|
2011-06-21 04:08:26 +08:00
|
|
|
|
endif
|
2010-08-24 07:56:08 +08:00
|
|
|
|
endif
|
2012-01-10 08:41:11 +08:00
|
|
|
|
endif
|
2010-08-24 07:56:08 +08:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
# Compile the executable from all the objects.
|
|
|
|
|
#----------------------------------------------------------------------
|
2012-01-10 08:41:11 +08:00
|
|
|
|
ifneq "$(DYLIB_NAME)" ""
|
|
|
|
|
ifeq "$(DYLIB_ONLY)" ""
|
2012-01-13 07:09:42 +08:00
|
|
|
|
$(EXE) : $(OBJECTS) $(ARCHIVE_NAME) $(DYLIB_FILENAME)
|
|
|
|
|
$(LD) $(LDFLAGS) $(OBJECTS) $(ARCHIVE_NAME) -L. -l$(DYLIB_NAME) -o "$(EXE)"
|
2012-01-10 08:41:11 +08:00
|
|
|
|
else
|
|
|
|
|
EXE = $(DYLIB_FILENAME)
|
|
|
|
|
endif
|
|
|
|
|
else
|
2012-01-13 07:09:42 +08:00
|
|
|
|
$(EXE) : $(OBJECTS) $(ARCHIVE_NAME)
|
|
|
|
|
$(LD) $(LDFLAGS) $(OBJECTS) $(ARCHIVE_NAME) -o "$(EXE)"
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
# Make the archive
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
ifneq "$(ARCHIVE_NAME)" ""
|
|
|
|
|
ifeq "$(OS)" "Darwin"
|
|
|
|
|
$(ARCHIVE_NAME) : $(ARCHIVE_OBJECTS)
|
|
|
|
|
$(AR) $(ARFLAGS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS)
|
|
|
|
|
$(RM) $(ARCHIVE_OBJECTS)
|
|
|
|
|
else
|
|
|
|
|
$(ARCHIVE_NAME) : $(foreach ar_obj,$(ARCHIVE_OBJECTS),$(ARCHIVE_NAME)($(ar_obj)))
|
|
|
|
|
endif
|
2010-08-24 07:56:08 +08:00
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
# Make the dylib
|
|
|
|
|
#----------------------------------------------------------------------
|
2011-06-21 03:06:04 +08:00
|
|
|
|
$(DYLIB_FILENAME) : $(DYLIB_OBJECTS)
|
|
|
|
|
ifeq "$(OS)" "Darwin"
|
|
|
|
|
$(LD) $(LDFLAGS) $(DYLIB_OBJECTS) -install_name "@executable_path/$(DYLIB_FILENAME)" -dynamiclib -o "$(DYLIB_FILENAME)"
|
2012-09-21 05:43:11 +08:00
|
|
|
|
ifneq "$(MAKE_DSYM)" "NO"
|
|
|
|
|
ifneq "$(DS)" ""
|
|
|
|
|
$(DS) $(DSFLAGS) "$(DYLIB_FILENAME)"
|
|
|
|
|
endif
|
|
|
|
|
endif
|
2011-06-21 03:06:04 +08:00
|
|
|
|
else
|
|
|
|
|
$(LD) $(LDFLAGS) $(DYLIB_OBJECTS) -shared -o "$(DYLIB_FILENAME)"
|
|
|
|
|
endif
|
2010-08-24 07:56:08 +08:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
# Automatic variables based on items already entered. Below we create
|
|
|
|
|
# an objects lists from the list of sources by replacing all entries
|
|
|
|
|
# that end with .c with .o, and we also create a list of prerequisite
|
|
|
|
|
# files by replacing all .c files with .d.
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
PREREQS := $(OBJECTS:.o=.d)
|
2010-08-25 00:35:00 +08:00
|
|
|
|
ifneq "$(DYLIB_NAME)" ""
|
|
|
|
|
DYLIB_PREREQS := $(DYLIB_OBJECTS:.o=.d)
|
|
|
|
|
endif
|
2010-08-24 07:56:08 +08:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
# Rule for Generating Prerequisites Automatically using .d files and
|
|
|
|
|
# the compiler -MM option. The -M option will list all system headers,
|
|
|
|
|
# and the -MM option will list all non-system dependencies.
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
%.d: %.c
|
|
|
|
|
@set -e; rm -f $@; \
|
2011-08-05 04:44:56 +08:00
|
|
|
|
$(CC) -M $(CFLAGS) $< > $@.$$$$; \
|
2010-08-24 07:56:08 +08:00
|
|
|
|
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
|
|
|
|
|
rm -f $@.$$$$
|
|
|
|
|
|
|
|
|
|
%.d: %.cpp
|
|
|
|
|
@set -e; rm -f $@; \
|
2011-08-05 04:44:56 +08:00
|
|
|
|
$(CC) -M $(CXXFLAGS) $< > $@.$$$$; \
|
2010-08-24 07:56:08 +08:00
|
|
|
|
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
|
|
|
|
|
rm -f $@.$$$$
|
|
|
|
|
|
|
|
|
|
%.d: %.m
|
|
|
|
|
@set -e; rm -f $@; \
|
2011-08-05 04:44:56 +08:00
|
|
|
|
$(CC) -M $(CFLAGS) $< > $@.$$$$; \
|
2010-08-24 07:56:08 +08:00
|
|
|
|
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
|
|
|
|
|
rm -f $@.$$$$
|
|
|
|
|
|
|
|
|
|
%.d: %.mm
|
|
|
|
|
@set -e; rm -f $@; \
|
2011-08-05 04:44:56 +08:00
|
|
|
|
$(CC) -M $(CXXFLAGS) $< > $@.$$$$; \
|
2010-08-24 07:56:08 +08:00
|
|
|
|
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
|
|
|
|
|
rm -f $@.$$$$
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
# Include all of the makefiles for each source file so we don't have
|
|
|
|
|
# to manually track all of the prerequisites for each source file.
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
sinclude $(PREREQS)
|
2010-08-25 00:35:00 +08:00
|
|
|
|
ifneq "$(DYLIB_NAME)" ""
|
|
|
|
|
sinclude $(DYLIB_PREREQS)
|
|
|
|
|
endif
|
2010-08-24 07:56:08 +08:00
|
|
|
|
|
2012-04-25 07:05:07 +08:00
|
|
|
|
# Define a suffix rule for .mm -> .o
|
|
|
|
|
.SUFFIXES: .mm .o
|
|
|
|
|
.mm.o:
|
|
|
|
|
$(CXX) $(CXXFLAGS) -c $<
|
|
|
|
|
|
2010-08-24 07:56:08 +08:00
|
|
|
|
.PHONY: clean
|
|
|
|
|
dsym: $(DSYM)
|
|
|
|
|
all: $(EXE) $(DSYM)
|
2010-09-28 04:44:46 +08:00
|
|
|
|
clean::
|
2010-08-24 07:56:08 +08:00
|
|
|
|
ifeq "$(DYLIB_NAME)" ""
|
2012-01-13 07:09:42 +08:00
|
|
|
|
rm -rf "$(EXE)" "$(DSYM)" $(OBJECTS) $(PREREQS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS)
|
2010-08-24 07:56:08 +08:00
|
|
|
|
else
|
2012-01-13 07:09:42 +08:00
|
|
|
|
rm -rf "$(EXE)" "$(DSYM)" $(OBJECTS) $(PREREQS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS) $(DYLIB_OBJECTS) $(DYLIB_PREREQS) $(DYLIB_FILENAME) $(DYLIB_FILENAME).dSYM
|
2010-08-24 07:56:08 +08:00
|
|
|
|
endif
|
2011-01-15 05:18:12 +08:00
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
# From http://blog.melski.net/tag/debugging-makefiles/
|
|
|
|
|
#
|
|
|
|
|
# Usage: make print-CC print-CXX print-LD
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
print-%:
|
|
|
|
|
@echo '$*=$($*)'
|
|
|
|
|
@echo ' origin = $(origin $*)'
|
|
|
|
|
@echo ' flavor = $(flavor $*)'
|
|
|
|
|
@echo ' value = $(value $*)'
|
2011-01-29 01:22:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Local Variables: ###
|
|
|
|
|
### mode:makefile ###
|
|
|
|
|
### End: ###
|