From 589d7fcda6ee17542ab75854ea824970b10248d7 Mon Sep 17 00:00:00 2001 From: katja Date: Sat, 5 Dec 2015 11:31:43 +0100 Subject: [PATCH 1/3] 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. --- Makefile.pdlibbuilder | 48 +++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/Makefile.pdlibbuilder b/Makefile.pdlibbuilder index b97e2b5..1c214b7 100644 --- a/Makefile.pdlibbuilder +++ b/Makefile.pdlibbuilder @@ -393,29 +393,29 @@ endif #=== flags per architecture ==================================================== -# Set architecture-dependent flags, mainly for Linux. For Mac and Windows, -# arch.flags are overriden below. +# Set architecture-dependent cflags, mainly for Linux. For Mac and Windows, +# arch.c.flags are overriden below. machine := $(shell uname -m) # Raspberry Pi 1st generation ifeq ($(machine), armv6l) - arch.flags = -march=armv6 -mfpu=vfp -mfloat-abi=hard + arch.c.flags = -march=armv6 -mfpu=vfp -mfloat-abi=hard endif # Beagle, Udoo, RPi2 etc. 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 # Intel 32 bit, build with SSE and SSE2 instructions ifeq ($(findstring $(machine), i386 i686), $(machine)) - arch.flags = -march=pentium4 -mfpmath=sse -msse -msse2 + arch.c.flags = -march=pentium4 -mfpmath=sse -msse -msse2 endif # Intel/AMD 64 bit, build with SSE, SSE2 and SSE3 instructions 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 @@ -482,7 +482,6 @@ ifeq ($(system), Darwin) /Applications/Pd-extended.app/Contents/Resources/include/pdextended/m_pd.h \ /Applications/Pd.app/Contents/Resources/src/m_pd.h))) extension = pd_darwin - arch.flags = cpp.flags := -DUNIX -DMACOSX -I /sw/include c.flags := c.ldflags := -undefined suppress -flat_namespace -bundle @@ -496,10 +495,12 @@ ifeq ($(system), Darwin) stripflags = -x ifeq ($(machine), i386) 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 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 @@ -537,7 +538,7 @@ ifeq ($(system), Windows) extension = dll CC = gcc CXX = g++ - arch.flags := -march=pentium4 -msse -msse2 -mfpmath=sse + arch.c.flags := -march=pentium4 -msse -msse2 -mfpmath=sse cpp.flags := -DMSW -DNT c.flags := 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 -# themselves.' So we use CFLAGS to define platform-independent options which -# are not strictly required for compilation: optimizations and warnings. CFLAGS -# can be safely overriden using a make command argument. +# themselves.' So we use CFLAGS to define options which are not strictly +# required for compilation: optimizations, architecture specifications, and +# warnings. CFLAGS can be safely overriden using a make command argument. # Variables cflags, ldflags and ldlibs may be defined in including makefile. 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) endif -CFLAGS = $(warn.flags) $(optimization.flags) +CFLAGS = $(warn.flags) $(optimization.flags) $(arch.c.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.ldflags := $(c.ldflags) $(ldflags) +c.ldflags := $(c.ldflags) $(ldflags) $(LDFLAGS) 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.ldflags := $(cxx.ldflags) $(ldflags) +cxx.ldflags := $(cxx.ldflags) $(ldflags) $(LDFLAGS) cxx.ldlibs := $(cxx.ldlibs) $(ldlibs) @@ -706,7 +710,6 @@ alldebug: all # argument $2 = class basename define link-class $(compile-$1) \ - $(arch.flags) \ $($1.ldflags) $($2.class.ldflags) \ -o $2.$(extension) \ $(addsuffix .o, $(basename $($2.class.sources))) \ @@ -733,7 +736,6 @@ build-lib: $(lib.name).$(extension) # argument $1 = compiler type (c or cxx) define link-lib $(compile-$1) \ - $(arch.flags) \ $($1.ldflags) $(lib.ldflags) \ -o $(lib.name).$(extension) $(all.objects) \ $($1.ldlibs) $(lib.ldlibs) @@ -756,7 +758,6 @@ endif # argument $1 = compiler type (c or cxx) define link-shared $(compile-$1) \ - $(arch.flags) \ $(shared.ldflags) \ -o lib$(lib.name).$(shared.extension) $(shared.objects) \ $($1.ldlibs) $(shared.ldlibs) @@ -780,7 +781,7 @@ define make-object-file $(info ++++ info: making $@ in lib $(lib.name)) $(compile-$1) \ $($1.flags) \ - $(arch.flags) -o $@ -c $< + -o $@ -c $< endef # Three rules to create .o files. These are double colon 'terminal' rules, @@ -904,7 +905,6 @@ define make-assembly-file $(compile-$1) \ -c -Wa,-a,-ad -fverbose-asm \ $($1.flags) \ - $(arch.flags) \ $< > $(notdir $*.lst) endef From 15832b5e0793f953c85203169237281e2dd46f8d Mon Sep 17 00:00:00 2001 From: katja Date: Sun, 6 Dec 2015 18:00:01 +0100 Subject: [PATCH 2/3] Small fix: add LDFLAGS to shared.ldflags too. --- Makefile.pdlibbuilder | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile.pdlibbuilder b/Makefile.pdlibbuilder index 1c214b7..df60884 100644 --- a/Makefile.pdlibbuilder +++ b/Makefile.pdlibbuilder @@ -596,6 +596,9 @@ cpp.flags += -DPD -I "$(pdincludepath)" $(CPPFLAGS) # architecture specifications for linker are overridable by LDFLAGS LDFLAGS := $(arch.ld.flags) +# now add the same ld flags to shared dynamic lib +shared.ldflags := $(shared.ldflags) $(LDFLAGS) + # accumulated flags for C compiler / linker c.flags := $(cpp.flags) $(c.flags) $(cflags) $(CFLAGS) c.ldflags := $(c.ldflags) $(ldflags) $(LDFLAGS) From c6fe1832fc6f604b58e7ab696954e0a1bbb77cf2 Mon Sep 17 00:00:00 2001 From: katja Date: Tue, 22 Dec 2015 00:45:26 +0100 Subject: [PATCH 3/3] Document CPPFLAGS, CFLAGS, LDFLAGS --- Makefile.pdlibbuilder | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Makefile.pdlibbuilder b/Makefile.pdlibbuilder index df60884..094db78 100644 --- a/Makefile.pdlibbuilder +++ b/Makefile.pdlibbuilder @@ -74,7 +74,9 @@ # - prefix # - libdir # - pkglibdir +# - CPPFLAGS # - CFLAGS +# - LDFLAGS # - CC # - CXX # - INSTALL @@ -161,9 +163,18 @@ # Alias of pkglibdir. Can be defined in your makefile to enable project- # dependent relative install locations. # +# CPPFLAGS: +# Preprocessor flags which are not strictly required for building. +# # CFLAGS: -# Compiler (notably optimization) flags which are defined by -# Makefile.pdlibbuilder, but may be overriden via command argument. +# Compiler flags which are not strictly required for building. Compiler flags +# defined by Makefile.pdlibbuilder for warning, optimization and architecture +# specification are overriden by CFLAGS. +# +# LDFLAGS: +# Linker flags which are not strictly required for building. Linker flags +# defined by Makefile.pdlibbuilder for architecture specification are overriden +# by LDFLAGS. # # CC and CXX: # C and C++ compiler programs as defined in your build environment.