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 :=
|
|
|
|
|
|
|
|
# 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.
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
ifeq "$(ARCH)" ""
|
|
|
|
ARCH = x86_64
|
|
|
|
endif
|
|
|
|
|
2010-08-24 07:56:08 +08:00
|
|
|
#----------------------------------------------------------------------
|
|
|
|
# Change any build/tool options needed
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
DS := /usr/bin/dsymutil
|
|
|
|
DSFLAGS =
|
2010-10-01 01:11:58 +08:00
|
|
|
CC ?= gcc
|
2010-09-17 04:54:06 +08:00
|
|
|
CFLAGS ?=-arch $(ARCH) -gdwarf-2 -O0
|
2010-09-30 09:22:34 +08:00
|
|
|
CXXFLAGS +=$(CFLAGS)
|
2010-09-14 04:54:30 +08:00
|
|
|
LD = $(CC)
|
2010-08-24 07:56:08 +08:00
|
|
|
LDFLAGS ?= $(CFLAGS)
|
|
|
|
OBJECTS =
|
|
|
|
EXE = a.out
|
|
|
|
DSYM = $(EXE).dSYM
|
|
|
|
|
2010-09-30 09:22:34 +08:00
|
|
|
# Function that returns the counterpart C++ compiler.
|
|
|
|
cxx_compiler = $(if $(findstring clang,$(1)), clang++, $(if $(findstring llvm-gcc,$(1)), llvm-g++, g++))
|
|
|
|
|
2010-08-24 07:56:08 +08:00
|
|
|
#----------------------------------------------------------------------
|
|
|
|
# dylib settings
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
ifneq "$(strip $(DYLIB_C_SOURCES))" ""
|
|
|
|
DYLIB_OBJECTS +=$(strip $(DYLIB_C_SOURCES:.c=.o))
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
# 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))
|
2010-08-24 07:56:08 +08:00
|
|
|
LD = g++
|
|
|
|
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))
|
2010-08-24 07:56:08 +08:00
|
|
|
LD = g++
|
|
|
|
ifeq $(findstring lobjc,$(LDFLAGS)) ""
|
|
|
|
LDFLAGS +=-lobjc
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
# Make the dSYM file from the executable if $(MAKE_DSYM) != "NO"
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
ifneq "$(MAKE_DSYM)" "NO"
|
|
|
|
$(DSYM) : $(EXE)
|
|
|
|
$(DS) $(DSFLAGS) -o "$(DSYM)" "$(EXE)"
|
|
|
|
endif
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
# Compile the executable from all the objects.
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
ifeq "$(DYLIB_NAME)" ""
|
|
|
|
$(EXE) : $(OBJECTS)
|
|
|
|
$(LD) $(LDFLAGS) $(OBJECTS) -o "$(EXE)"
|
|
|
|
else
|
|
|
|
$(EXE) : $(OBJECTS) $(DYLIB_NAME)
|
|
|
|
$(LD) $(LDFLAGS) $(OBJECTS) -L. -l$(subst lib,,$(basename $(DYLIB_NAME))) -o "$(EXE)"
|
|
|
|
endif
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
# Make the dylib
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
$(DYLIB_NAME) : $(DYLIB_OBJECTS)
|
|
|
|
$(LD) $(LDFLAGS) $(DYLIB_OBJECTS) -install_name "@executable_path/$(DYLIB_NAME)" -dynamiclib -o "$(DYLIB_NAME)"
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
# 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 $@; \
|
|
|
|
$(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
|
|
|
|
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
|
|
|
|
rm -f $@.$$$$
|
|
|
|
|
|
|
|
%.d: %.cpp
|
|
|
|
@set -e; rm -f $@; \
|
|
|
|
$(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
|
|
|
|
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
|
|
|
|
rm -f $@.$$$$
|
|
|
|
|
|
|
|
%.d: %.m
|
|
|
|
@set -e; rm -f $@; \
|
|
|
|
$(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
|
|
|
|
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
|
|
|
|
rm -f $@.$$$$
|
|
|
|
|
|
|
|
%.d: %.mm
|
|
|
|
@set -e; rm -f $@; \
|
|
|
|
$(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
|
|
|
|
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
|
|
|
|
|
|
|
.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)" ""
|
|
|
|
rm -rf "$(EXE)" "$(DSYM)" $(OBJECTS) $(PREREQS)
|
|
|
|
else
|
|
|
|
rm -rf "$(EXE)" "$(DSYM)" $(OBJECTS) $(PREREQS) $(DYLIB_OBJECTS) $(DYLIB_NAME) $(DYLIB_NAME).dSYM
|
|
|
|
endif
|