Use CPPFLAGS, CFLAGS and LDFLAGS to override/add build flags
This commit reorganizes the accumulation of build flags in such a way that non-obligatory build flags can be overriden or added by specifying CPPFLAGS, CFLAGS and LDFLAGS as arguments from command line or environment.
This commit is contained in:
parent
974b6174ce
commit
589d7fcda6
1 changed files with 24 additions and 24 deletions
|
|
@ -393,29 +393,29 @@ endif
|
||||||
#=== flags per architecture ====================================================
|
#=== flags per architecture ====================================================
|
||||||
|
|
||||||
|
|
||||||
# Set architecture-dependent flags, mainly for Linux. For Mac and Windows,
|
# Set architecture-dependent cflags, mainly for Linux. For Mac and Windows,
|
||||||
# arch.flags are overriden below.
|
# arch.c.flags are overriden below.
|
||||||
|
|
||||||
machine := $(shell uname -m)
|
machine := $(shell uname -m)
|
||||||
|
|
||||||
# Raspberry Pi 1st generation
|
# Raspberry Pi 1st generation
|
||||||
ifeq ($(machine), armv6l)
|
ifeq ($(machine), armv6l)
|
||||||
arch.flags = -march=armv6 -mfpu=vfp -mfloat-abi=hard
|
arch.c.flags = -march=armv6 -mfpu=vfp -mfloat-abi=hard
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Beagle, Udoo, RPi2 etc.
|
# Beagle, Udoo, RPi2 etc.
|
||||||
ifeq ($(machine), armv7l)
|
ifeq ($(machine), armv7l)
|
||||||
arch.flags = -march=armv7-a -mfpu=vfpv3 -mfloat-abi=hard
|
arch.c.flags = -march=armv7-a -mfpu=vfpv3 -mfloat-abi=hard
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Intel 32 bit, build with SSE and SSE2 instructions
|
# Intel 32 bit, build with SSE and SSE2 instructions
|
||||||
ifeq ($(findstring $(machine), i386 i686), $(machine))
|
ifeq ($(findstring $(machine), i386 i686), $(machine))
|
||||||
arch.flags = -march=pentium4 -mfpmath=sse -msse -msse2
|
arch.c.flags = -march=pentium4 -mfpmath=sse -msse -msse2
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Intel/AMD 64 bit, build with SSE, SSE2 and SSE3 instructions
|
# Intel/AMD 64 bit, build with SSE, SSE2 and SSE3 instructions
|
||||||
ifeq ($(findstring $(machine), ia64 x86_64), $(machine))
|
ifeq ($(findstring $(machine), ia64 x86_64), $(machine))
|
||||||
arch.flags = -march=core2 -mfpmath=sse -msse -msse2 -msse3
|
arch.c.flags = -march=core2 -mfpmath=sse -msse -msse2 -msse3
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -482,7 +482,6 @@ ifeq ($(system), Darwin)
|
||||||
/Applications/Pd-extended.app/Contents/Resources/include/pdextended/m_pd.h \
|
/Applications/Pd-extended.app/Contents/Resources/include/pdextended/m_pd.h \
|
||||||
/Applications/Pd.app/Contents/Resources/src/m_pd.h)))
|
/Applications/Pd.app/Contents/Resources/src/m_pd.h)))
|
||||||
extension = pd_darwin
|
extension = pd_darwin
|
||||||
arch.flags =
|
|
||||||
cpp.flags := -DUNIX -DMACOSX -I /sw/include
|
cpp.flags := -DUNIX -DMACOSX -I /sw/include
|
||||||
c.flags :=
|
c.flags :=
|
||||||
c.ldflags := -undefined suppress -flat_namespace -bundle
|
c.ldflags := -undefined suppress -flat_namespace -bundle
|
||||||
|
|
@ -496,10 +495,12 @@ ifeq ($(system), Darwin)
|
||||||
stripflags = -x
|
stripflags = -x
|
||||||
ifeq ($(machine), i386)
|
ifeq ($(machine), i386)
|
||||||
cxx.flags := -fcheck-new
|
cxx.flags := -fcheck-new
|
||||||
arch.flags := -arch ppc -arch i386 -arch x86_64 -mmacosx-version-min=10.4
|
arch.c.flags := -arch ppc -arch i386 -arch x86_64 -mmacosx-version-min=10.4
|
||||||
|
arch.ld.flags := -arch ppc -arch i386 -arch x86_64 -mmacosx-version-min=10.4
|
||||||
endif
|
endif
|
||||||
ifeq ($(machine), x86_64)
|
ifeq ($(machine), x86_64)
|
||||||
arch.flags := -arch i386 -arch x86_64 -mmacosx-version-min=10.5
|
arch.c.flags := -arch i386 -arch x86_64 -mmacosx-version-min=10.5
|
||||||
|
arch.ld.flags := -arch i386 -arch x86_64 -mmacosx-version-min=10.5
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
@ -537,7 +538,7 @@ ifeq ($(system), Windows)
|
||||||
extension = dll
|
extension = dll
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CXX = g++
|
CXX = g++
|
||||||
arch.flags := -march=pentium4 -msse -msse2 -mfpmath=sse
|
arch.c.flags := -march=pentium4 -msse -msse2 -mfpmath=sse
|
||||||
cpp.flags := -DMSW -DNT
|
cpp.flags := -DMSW -DNT
|
||||||
c.flags :=
|
c.flags :=
|
||||||
c.ldflags := -static-libgcc -shared \
|
c.ldflags := -static-libgcc -shared \
|
||||||
|
|
@ -574,9 +575,9 @@ pdincludepathwithspaces := $(if $(word 2, $(pdincludepath)), $(pdincludepath))
|
||||||
|
|
||||||
|
|
||||||
# From GNU make docs: 'Users expect to be able to specify CFLAGS freely
|
# From GNU make docs: 'Users expect to be able to specify CFLAGS freely
|
||||||
# themselves.' So we use CFLAGS to define platform-independent options which
|
# themselves.' So we use CFLAGS to define options which are not strictly
|
||||||
# are not strictly required for compilation: optimizations and warnings. CFLAGS
|
# required for compilation: optimizations, architecture specifications, and
|
||||||
# can be safely overriden using a make command argument.
|
# warnings. CFLAGS can be safely overriden using a make command argument.
|
||||||
# Variables cflags, ldflags and ldlibs may be defined in including makefile.
|
# Variables cflags, ldflags and ldlibs may be defined in including makefile.
|
||||||
|
|
||||||
optimization.flags = -O3 -ffast-math -funroll-loops -fomit-frame-pointer
|
optimization.flags = -O3 -ffast-math -funroll-loops -fomit-frame-pointer
|
||||||
|
|
@ -587,19 +588,22 @@ ifdef suppress-wunused
|
||||||
warn.flags += $(addprefix -Wno-unused-, function parameter value variable)
|
warn.flags += $(addprefix -Wno-unused-, function parameter value variable)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
CFLAGS = $(warn.flags) $(optimization.flags)
|
CFLAGS = $(warn.flags) $(optimization.flags) $(arch.c.flags)
|
||||||
|
|
||||||
# preprocessor flags
|
# preprocessor flags
|
||||||
cpp.flags += -DPD -I "$(pdincludepath)"
|
cpp.flags += -DPD -I "$(pdincludepath)" $(CPPFLAGS)
|
||||||
|
|
||||||
# flags for C compiler / linker
|
# architecture specifications for linker are overridable by LDFLAGS
|
||||||
|
LDFLAGS := $(arch.ld.flags)
|
||||||
|
|
||||||
|
# accumulated flags for C compiler / linker
|
||||||
c.flags := $(cpp.flags) $(c.flags) $(cflags) $(CFLAGS)
|
c.flags := $(cpp.flags) $(c.flags) $(cflags) $(CFLAGS)
|
||||||
c.ldflags := $(c.ldflags) $(ldflags)
|
c.ldflags := $(c.ldflags) $(ldflags) $(LDFLAGS)
|
||||||
c.ldlibs := $(c.ldlibs) $(ldlibs)
|
c.ldlibs := $(c.ldlibs) $(ldlibs)
|
||||||
|
|
||||||
# flags for C++ compiler / linker
|
# accumulated flags for C++ compiler / linker
|
||||||
cxx.flags := $(cpp.flags) $(cxx.flags) $(cflags) $(CFLAGS)
|
cxx.flags := $(cpp.flags) $(cxx.flags) $(cflags) $(CFLAGS)
|
||||||
cxx.ldflags := $(cxx.ldflags) $(ldflags)
|
cxx.ldflags := $(cxx.ldflags) $(ldflags) $(LDFLAGS)
|
||||||
cxx.ldlibs := $(cxx.ldlibs) $(ldlibs)
|
cxx.ldlibs := $(cxx.ldlibs) $(ldlibs)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -706,7 +710,6 @@ alldebug: all
|
||||||
# argument $2 = class basename
|
# argument $2 = class basename
|
||||||
define link-class
|
define link-class
|
||||||
$(compile-$1) \
|
$(compile-$1) \
|
||||||
$(arch.flags) \
|
|
||||||
$($1.ldflags) $($2.class.ldflags) \
|
$($1.ldflags) $($2.class.ldflags) \
|
||||||
-o $2.$(extension) \
|
-o $2.$(extension) \
|
||||||
$(addsuffix .o, $(basename $($2.class.sources))) \
|
$(addsuffix .o, $(basename $($2.class.sources))) \
|
||||||
|
|
@ -733,7 +736,6 @@ build-lib: $(lib.name).$(extension)
|
||||||
# argument $1 = compiler type (c or cxx)
|
# argument $1 = compiler type (c or cxx)
|
||||||
define link-lib
|
define link-lib
|
||||||
$(compile-$1) \
|
$(compile-$1) \
|
||||||
$(arch.flags) \
|
|
||||||
$($1.ldflags) $(lib.ldflags) \
|
$($1.ldflags) $(lib.ldflags) \
|
||||||
-o $(lib.name).$(extension) $(all.objects) \
|
-o $(lib.name).$(extension) $(all.objects) \
|
||||||
$($1.ldlibs) $(lib.ldlibs)
|
$($1.ldlibs) $(lib.ldlibs)
|
||||||
|
|
@ -756,7 +758,6 @@ endif
|
||||||
# argument $1 = compiler type (c or cxx)
|
# argument $1 = compiler type (c or cxx)
|
||||||
define link-shared
|
define link-shared
|
||||||
$(compile-$1) \
|
$(compile-$1) \
|
||||||
$(arch.flags) \
|
|
||||||
$(shared.ldflags) \
|
$(shared.ldflags) \
|
||||||
-o lib$(lib.name).$(shared.extension) $(shared.objects) \
|
-o lib$(lib.name).$(shared.extension) $(shared.objects) \
|
||||||
$($1.ldlibs) $(shared.ldlibs)
|
$($1.ldlibs) $(shared.ldlibs)
|
||||||
|
|
@ -780,7 +781,7 @@ define make-object-file
|
||||||
$(info ++++ info: making $@ in lib $(lib.name))
|
$(info ++++ info: making $@ in lib $(lib.name))
|
||||||
$(compile-$1) \
|
$(compile-$1) \
|
||||||
$($1.flags) \
|
$($1.flags) \
|
||||||
$(arch.flags) -o $@ -c $<
|
-o $@ -c $<
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# Three rules to create .o files. These are double colon 'terminal' rules,
|
# Three rules to create .o files. These are double colon 'terminal' rules,
|
||||||
|
|
@ -904,7 +905,6 @@ define make-assembly-file
|
||||||
$(compile-$1) \
|
$(compile-$1) \
|
||||||
-c -Wa,-a,-ad -fverbose-asm \
|
-c -Wa,-a,-ad -fverbose-asm \
|
||||||
$($1.flags) \
|
$($1.flags) \
|
||||||
$(arch.flags) \
|
|
||||||
$< > $(notdir $*.lst)
|
$< > $(notdir $*.lst)
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue