From 4be3e99acb661df7da32ef3bfc4b111dbb0a1a89 Mon Sep 17 00:00:00 2001 From: katjav Date: Sat, 20 Jan 2018 17:18:34 +0100 Subject: [PATCH 01/11] Swap OS and machine detection so OS comes first This is in preparation for target architecture detection through gcc / g++. --- Makefile.pdlibbuilder | 69 ++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/Makefile.pdlibbuilder b/Makefile.pdlibbuilder index eba47f9..2c052d2 100644 --- a/Makefile.pdlibbuilder +++ b/Makefile.pdlibbuilder @@ -425,39 +425,10 @@ endif ################################################################################ -### variables per platform ##################################################### +### platform detection ######################################################### ################################################################################ -#=== flags per architecture ==================================================== - - -# 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.c.flags = -march=armv6 -mfpu=vfp -mfloat-abi=hard -endif - -# Beagle, Udoo, RPi2 etc. -ifeq ($(machine), armv7l) - 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.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.c.flags = -march=core2 -mfpmath=sse -msse -msse2 -msse3 -endif - - #=== operating system ========================================================== @@ -485,6 +456,44 @@ $(eval $(for$(system))) # TODO: Cygwin, Android +#=== architecture ============================================================== + + +machine := $(shell uname -m) + + +################################################################################ +### variables per platform ##################################################### +################################################################################ + + +#=== flags per architecture ==================================================== + + +# Set architecture-dependent cflags, mainly for Linux. For Mac and Windows, +# arch.c.flags are overriden below. + +# Raspberry Pi 1st generation +ifeq ($(machine), armv6l) + arch.c.flags = -march=armv6 -mfpu=vfp -mfloat-abi=hard +endif + +# Beagle, Udoo, RPi2 etc. +ifeq ($(machine), armv7l) + 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.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.c.flags = -march=core2 -mfpmath=sse -msse -msse2 -msse3 +endif + + #=== flags and paths for Linux ================================================= From fa3c2ca71d231c067f07b62b689f930373737973 Mon Sep 17 00:00:00 2001 From: katjav Date: Sat, 20 Jan 2018 17:45:31 +0100 Subject: [PATCH 02/11] Introduce variable 'target.arch' It stores the first field of -- triplet as retrieved from command ' -dumpmachine' where is g++ or gcc. --- Makefile.pdlibbuilder | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Makefile.pdlibbuilder b/Makefile.pdlibbuilder index 2c052d2..d9e67a1 100644 --- a/Makefile.pdlibbuilder +++ b/Makefile.pdlibbuilder @@ -449,6 +449,14 @@ ifeq ($(findstring MINGW, $(uname)), MINGW) system = Windows endif +# Unfortunately not all Mingw versions provide a link cc > gcc, therefore +# gcc is hardcoded here (but not if CC is redefined). +ifeq ($(system), Windows) + ifeq ($(origin CC), default) + CC = gcc + endif +endif + # evaluate possible system-specific multiline defines from library makefile $(eval $(for$(system))) @@ -459,7 +467,16 @@ $(eval $(for$(system))) #=== architecture ============================================================== -machine := $(shell uname -m) +# native architecture +machine := $(shell uname --machine) + +# Target architecture as reported by compiler. Give precedence to eventual +# user-defined compiler. The first field of -- is extracted. +ifneq ($(origin CXX), default) + target.arch = $(firstword $(subst -, ,$(shell $(CXX) -dumpmachine))) +else + target.arch = $(firstword $(subst -, ,$(shell $(CC) -dumpmachine))) +endif ################################################################################ @@ -582,8 +599,6 @@ endif # TODO: decide whether -mms-bitfields should be specified. ifeq ($(system), Windows) extension = dll - CC = gcc - CXX = g++ arch.c.flags := -march=pentium4 -msse -msse2 -mfpmath=sse cpp.flags := -DMSW -DNT c.flags := From ef21a16eb0d8d5f6745a8741e8ca75a5e9caf19f Mon Sep 17 00:00:00 2001 From: katjav Date: Sat, 20 Jan 2018 23:11:15 +0100 Subject: [PATCH 03/11] Introduce architecture dependent settings for Windows --- Makefile.pdlibbuilder | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Makefile.pdlibbuilder b/Makefile.pdlibbuilder index d9e67a1..66db349 100644 --- a/Makefile.pdlibbuilder +++ b/Makefile.pdlibbuilder @@ -594,13 +594,16 @@ ifeq ($(system), Windows) endif endif -# On Windows we build 32 bit by default to match Pd(-extended) binary -# distributions. This may change in the future. # TODO: decide whether -mms-bitfields should be specified. ifeq ($(system), Windows) + ifeq ($(findstring $(target.arch), ia64 x86_64), $(target.arch)) + cpp.flags := -DMSW -DNT -DPD_LONGINTTYPE=__int64 + arch.c.flags := -march=core2 -msse -msse2 -mfpmath=sse + else + cpp.flags := -DMSW -DNT + arch.c.flags := -march=pentium4 -msse -msse2 -mfpmath=sse + endif extension = dll - arch.c.flags := -march=pentium4 -msse -msse2 -mfpmath=sse - cpp.flags := -DMSW -DNT c.flags := c.ldflags = -static-libgcc -shared \ -Wl,--enable-auto-import "$(pdbinpath)/pd.dll" From 37d23530c6be7a97e1cd29fee61db6acbe574283 Mon Sep 17 00:00:00 2001 From: katjav Date: Sun, 21 Jan 2018 11:19:43 +0100 Subject: [PATCH 04/11] Leave out architecture 'ia64' As per suggestion of Johannes Zmoelnig. It is not relevant and also not compatible with x86_64. --- Makefile.pdlibbuilder | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.pdlibbuilder b/Makefile.pdlibbuilder index 66db349..8092166 100644 --- a/Makefile.pdlibbuilder +++ b/Makefile.pdlibbuilder @@ -506,7 +506,7 @@ ifeq ($(findstring $(machine), i386 i686), $(machine)) endif # Intel/AMD 64 bit, build with SSE, SSE2 and SSE3 instructions -ifeq ($(findstring $(machine), ia64 x86_64), $(machine)) +ifeq ($(findstring $(machine), x86_64), $(machine)) arch.c.flags = -march=core2 -mfpmath=sse -msse -msse2 -msse3 endif @@ -596,7 +596,7 @@ endif # TODO: decide whether -mms-bitfields should be specified. ifeq ($(system), Windows) - ifeq ($(findstring $(target.arch), ia64 x86_64), $(target.arch)) + ifeq ($(findstring $(target.arch), x86_64), $(target.arch)) cpp.flags := -DMSW -DNT -DPD_LONGINTTYPE=__int64 arch.c.flags := -march=core2 -msse -msse2 -mfpmath=sse else From f83d4293bdf8bd8b33252ac56d30717221eb95ed Mon Sep 17 00:00:00 2001 From: katjav Date: Sun, 21 Jan 2018 11:42:55 +0100 Subject: [PATCH 05/11] Introduce remainder architecture category for Windows And explicitly specify Intel 32 bit architectures, where 'mingw32' is included to support MSYS1. --- Makefile.pdlibbuilder | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile.pdlibbuilder b/Makefile.pdlibbuilder index 8092166..8bf8328 100644 --- a/Makefile.pdlibbuilder +++ b/Makefile.pdlibbuilder @@ -596,12 +596,14 @@ endif # TODO: decide whether -mms-bitfields should be specified. ifeq ($(system), Windows) - ifeq ($(findstring $(target.arch), x86_64), $(target.arch)) + cpp.flags := -DMSW -DNT + ifeq ($(findstring $(target.arch), i%86 mingw32), $(target.arch)) + arch.c.flags := -march=pentium4 -msse -msse2 -mfpmath=sse + else ifeq (x86_64, $(target.arch)) cpp.flags := -DMSW -DNT -DPD_LONGINTTYPE=__int64 arch.c.flags := -march=core2 -msse -msse2 -mfpmath=sse else - cpp.flags := -DMSW -DNT - arch.c.flags := -march=pentium4 -msse -msse2 -mfpmath=sse + arch.c.flags = endif extension = dll c.flags := From 867ad5e8e87bfa06770ca2f4c2d26beb5133fd6a Mon Sep 17 00:00:00 2001 From: katjav Date: Sun, 21 Jan 2018 11:54:01 +0100 Subject: [PATCH 06/11] Introduce general remainder architecture category --- Makefile.pdlibbuilder | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Makefile.pdlibbuilder b/Makefile.pdlibbuilder index 8bf8328..4fc4e15 100644 --- a/Makefile.pdlibbuilder +++ b/Makefile.pdlibbuilder @@ -493,21 +493,22 @@ endif # Raspberry Pi 1st generation ifeq ($(machine), armv6l) arch.c.flags = -march=armv6 -mfpu=vfp -mfloat-abi=hard -endif # Beagle, Udoo, RPi2 etc. -ifeq ($(machine), armv7l) +else ifeq ($(machine), armv7l) 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)) +else ifeq ($(findstring $(machine), i386 i686), $(machine)) arch.c.flags = -march=pentium4 -mfpmath=sse -msse -msse2 -endif - + # Intel/AMD 64 bit, build with SSE, SSE2 and SSE3 instructions -ifeq ($(findstring $(machine), x86_64), $(machine)) +else ifeq ($(findstring $(machine), x86_64), $(machine)) arch.c.flags = -march=core2 -mfpmath=sse -msse -msse2 -msse3 + +# if none of the above architectures detected +else + arch.c.flags = endif From 231e344b440cdf32dcdda9c564a9e67101d32474 Mon Sep 17 00:00:00 2001 From: katjav Date: Sun, 21 Jan 2018 12:34:45 +0100 Subject: [PATCH 07/11] Use variables 'build.arch' and 'target.arch' consistently --- Makefile.pdlibbuilder | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/Makefile.pdlibbuilder b/Makefile.pdlibbuilder index 4fc4e15..bce69dd 100644 --- a/Makefile.pdlibbuilder +++ b/Makefile.pdlibbuilder @@ -467,15 +467,23 @@ $(eval $(for$(system))) #=== architecture ============================================================== -# native architecture -machine := $(shell uname --machine) +# native architecture of the build machine +build.arch := $(shell uname --machine) # Target architecture as reported by compiler. Give precedence to eventual # user-defined compiler. The first field of -- is extracted. ifneq ($(origin CXX), default) - target.arch = $(firstword $(subst -, ,$(shell $(CXX) -dumpmachine))) + dumpmachine.cpu = $(firstword $(subst -, ,$(shell $(CXX) -dumpmachine))) else - target.arch = $(firstword $(subst -, ,$(shell $(CC) -dumpmachine))) + dumpmachine.cpu = $(firstword $(subst -, ,$(shell $(CC) -dumpmachine))) +endif + +# Target architecture as reported by compiler is only used for Windows at the +# moment. For other systems this still has to be tested. +ifeq ($(system), Windows) + target.arch = $(dumpmachine.cpu) +else + target.arch = $(build.arch) endif @@ -491,19 +499,19 @@ endif # arch.c.flags are overriden below. # Raspberry Pi 1st generation -ifeq ($(machine), armv6l) +ifeq ($(target.arch), armv6l) arch.c.flags = -march=armv6 -mfpu=vfp -mfloat-abi=hard # Beagle, Udoo, RPi2 etc. -else ifeq ($(machine), armv7l) +else ifeq ($(target.arch), armv7l) arch.c.flags = -march=armv7-a -mfpu=vfpv3 -mfloat-abi=hard # Intel 32 bit, build with SSE and SSE2 instructions -else ifeq ($(findstring $(machine), i386 i686), $(machine)) +else ifeq ($(findstring $(target.arch), i386 i686), $(target.arch)) arch.c.flags = -march=pentium4 -mfpmath=sse -msse -msse2 # Intel/AMD 64 bit, build with SSE, SSE2 and SSE3 instructions -else ifeq ($(findstring $(machine), x86_64), $(machine)) +else ifeq ($(findstring $(target.arch), x86_64), $(target.arch)) arch.c.flags = -march=core2 -mfpmath=sse -msse -msse2 -msse3 # if none of the above architectures detected @@ -560,12 +568,12 @@ ifeq ($(system), Darwin) -compatibility_version 1 -current_version 1.0 stripflags = -x version.flag := $(filter $(cflags), -mmacosx-version-min=%) - ifeq ($(machine), i386) + ifeq ($(target.arch), i386) cxx.flags := -fcheck-new arch := ppc i386 x86_64 version.flag ?= -mmacosx-version-min=10.4 endif - ifeq ($(machine), x86_64) + ifeq ($(target.arch), x86_64) arch := i386 x86_64 version.flag ?= -mmacosx-version-min=10.5 endif From e4d42f22278d9b5a9f02408d7fab2ac94c6ffed8 Mon Sep 17 00:00:00 2001 From: katjav Date: Sun, 21 Jan 2018 14:59:38 +0100 Subject: [PATCH 08/11] Assume system is "Windows" when uname says "MSYS" Needed for building with pd-lib-builder on AppVeyor. --- Makefile.pdlibbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.pdlibbuilder b/Makefile.pdlibbuilder index bce69dd..94c4116 100644 --- a/Makefile.pdlibbuilder +++ b/Makefile.pdlibbuilder @@ -445,7 +445,7 @@ ifeq ($(uname), Darwin) system = Darwin endif -ifeq ($(findstring MINGW, $(uname)), MINGW) +ifeq ($(findstring $(uname), MINGW MSYS), $(uname)) system = Windows endif From 77ff876401d991be5af4928e7fed077a19227f6c Mon Sep 17 00:00:00 2001 From: katjav Date: Sun, 21 Jan 2018 22:42:47 +0100 Subject: [PATCH 09/11] Fix conditional checks broken in commits e4d42f2 and f83d429 --- Makefile.pdlibbuilder | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.pdlibbuilder b/Makefile.pdlibbuilder index 94c4116..ca89077 100644 --- a/Makefile.pdlibbuilder +++ b/Makefile.pdlibbuilder @@ -445,7 +445,7 @@ ifeq ($(uname), Darwin) system = Darwin endif -ifeq ($(findstring $(uname), MINGW MSYS), $(uname)) +ifeq ($(filter MINGW% MSYS, $(uname)), $(uname)) system = Windows endif @@ -606,7 +606,7 @@ endif # TODO: decide whether -mms-bitfields should be specified. ifeq ($(system), Windows) cpp.flags := -DMSW -DNT - ifeq ($(findstring $(target.arch), i%86 mingw32), $(target.arch)) + ifeq ($(filter i%86 mingw32, $(target.arch)), $(target.arch)) arch.c.flags := -march=pentium4 -msse -msse2 -mfpmath=sse else ifeq (x86_64, $(target.arch)) cpp.flags := -DMSW -DNT -DPD_LONGINTTYPE=__int64 From 13796bfee28884b8b5aff910cca2d3f6e7924f6c Mon Sep 17 00:00:00 2001 From: katjav Date: Sun, 21 Jan 2018 22:52:19 +0100 Subject: [PATCH 10/11] Add option '-msse3' for Windows on x86_64 architecture --- Makefile.pdlibbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.pdlibbuilder b/Makefile.pdlibbuilder index ca89077..f192f02 100644 --- a/Makefile.pdlibbuilder +++ b/Makefile.pdlibbuilder @@ -610,7 +610,7 @@ ifeq ($(system), Windows) arch.c.flags := -march=pentium4 -msse -msse2 -mfpmath=sse else ifeq (x86_64, $(target.arch)) cpp.flags := -DMSW -DNT -DPD_LONGINTTYPE=__int64 - arch.c.flags := -march=core2 -msse -msse2 -mfpmath=sse + arch.c.flags := -march=core2 -msse -msse2 -msse3 -mfpmath=sse else arch.c.flags = endif From a01ee169cd48e4d40f1fc7530a503a1d32fc14c7 Mon Sep 17 00:00:00 2001 From: katjav Date: Mon, 22 Jan 2018 23:19:24 +0100 Subject: [PATCH 11/11] Revert 'uname --machine' to 'uname -m' (bug fix OSX) Long option name '--machine' was introduced in commit fa3c2ca for explicitness, however it is not supported by clang / OSX. --- Makefile.pdlibbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.pdlibbuilder b/Makefile.pdlibbuilder index f192f02..1a669ab 100644 --- a/Makefile.pdlibbuilder +++ b/Makefile.pdlibbuilder @@ -468,7 +468,7 @@ $(eval $(for$(system))) # native architecture of the build machine -build.arch := $(shell uname --machine) +build.arch := $(shell uname -m) # Target architecture as reported by compiler. Give precedence to eventual # user-defined compiler. The first field of -- is extracted.