From 8ef2032035e2d2127af02b3e70ddb250c234043d Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Wed, 15 Jun 2016 07:08:35 +0000 Subject: [PATCH] Makefile: Revamp setup of all things SDL. Highlights: *Building with msys2 can now take advantage of sdl-config and sdl2-config if present. *Add a header check to error out if SDL_mixer's major version does not match SDL. *Building with frameworks on OS X works again. Notes: *Those cross compiling, particularly targeting Windows, may need to invoke make with SDLCONFIG='' to avoid bringing in libs and headers from the host. git-svn-id: https://svn.eduke32.com/eduke32@5778 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/Makefile | 4 +- polymer/eduke32/Makefile.common | 144 ++++++++---------------- polymer/eduke32/Makefile.msvc | 2 +- polymer/eduke32/build/include/SDLMain.h | 16 --- polymer/eduke32/build/include/sdl_inc.h | 52 +++++---- polymer/eduke32/build/src/SDLMain.m | 18 ++- polymer/eduke32/eduke32.vcxproj | 8 +- polymer/synthesis.sh | 4 +- 8 files changed, 98 insertions(+), 150 deletions(-) delete mode 100644 polymer/eduke32/build/include/SDLMain.h diff --git a/polymer/eduke32/Makefile b/polymer/eduke32/Makefile index 343514606..92f32b908 100644 --- a/polymer/eduke32/Makefile +++ b/polymer/eduke32/Makefile @@ -88,7 +88,7 @@ ifeq ($(PLATFORM),DARWIN) ENGINE_EDITOR_OBJS += startosx.editor endif ifeq ($(SDL_TARGET),1) - ifeq (1,$(SDL_FRAMEWORK)) + ifneq ($(SDL_FRAMEWORK),0) ENGINE_OBJS+=SDLMain endif endif @@ -805,7 +805,7 @@ getdxdidf$(EXESUFFIX): $(ENGINE_OBJ)/getdxdidf.$o $(RECIPE_IF) $(LINKER) -o $@ $^ $(COMMONFLAGS) $(LINKERFLAGS) $(LIBDIRS) $(LIBS) -ldinput $(RECIPE_RESULT_ONESTEP) makesdlkeytrans$(EXESUFFIX): $(ENGINE_OBJ)/makesdlkeytrans.$o $(ONESTEP_STATUS) - $(RECIPE_IF) $(LINKER) -o $@ $^ $(COMMONFLAGS) $(LINKERFLAGS) $(LIBDIRS) $(LIBS) $(SDL_INCLUDES) $(RECIPE_RESULT_ONESTEP) + $(RECIPE_IF) $(LINKER) -o $@ $^ $(COMMONFLAGS) $(LINKERFLAGS) $(LIBDIRS) $(LIBS) $(RECIPE_RESULT_ONESTEP) arttool$(EXESUFFIX): $(ENGINE_OBJ)/arttool.$o $(ONESTEP_STATUS) $(RECIPE_IF) $(L_CXX) $(CXXONLYFLAGS) $(L_CXXONLYFLAGS) -o $@ $^ $(COMMONFLAGS) $(LINKERFLAGS) $(LIBDIRS) $(LIBS) $(STDCPPLIB) $(RECIPE_RESULT_ONESTEP) diff --git a/polymer/eduke32/Makefile.common b/polymer/eduke32/Makefile.common index 63f08c413..e1036d20f 100644 --- a/polymer/eduke32/Makefile.common +++ b/polymer/eduke32/Makefile.common @@ -385,9 +385,6 @@ else ifneq (0,$(KRANDDEBUG)) COMMONFLAGS += -fno-inline -fno-inline-functions -fno-inline-functions-called-once endif - ifeq (1,$(SDL_TARGET)) - COMPILERFLAGS += -DNOSDLPARACHUTE - endif endif ifndef OPTOPT @@ -684,16 +681,9 @@ endif # NOTE: If your setup doesn't have libstdc++, you can try using libsupc++. # Search for STDCPPLIB below and change it to -lsupc++. -SDL_INCLUDES=-I$(SDLROOT)/include -I$(SDLROOT)/include/SDL -SDL_LIB=-l$(SDLNAME) -SDL_MIXER_LIB=-l$(SDLNAME)_mixer - ifeq ($(SUBPLATFORM),LINUX) - RENDERTYPE=SDL - MIXERTYPE=SDL COMPILERFLAGS+= -DHAVE_INTTYPES GTKCOMPAT32=0 - SDL_FRAMEWORK=0 # On Linux, we don't need to specify libstdc++ manually, the linker will # presumably take care for us. @@ -749,20 +739,12 @@ ifeq ($(PLATFORM),DARWIN) COMPILERFLAGS+= -I/sw/include endif - RENDERTYPE = SDL - MIXERTYPE = SDL STDCPPLIB:=-lstdc++ COMPILERFLAGS += -DHAVE_INTTYPES DLLSUFFIX=.dylib GTKCOMPAT32 = 0 WITHOUT_GTK ?= 1 - ifeq (1,$(SDL_FRAMEWORK)) - SDL_INCLUDES=-I$(APPLE_FRAMEWORKS)/SDL.framework/Headers -I$(APPLE_FRAMEWORKS)/SDL_mixer.framework/Headers - SDL_LIB=-l$(SDLNAME)main -Wl,-framework,SDL -Wl,-rpath -Wl,"@loader_path/../Frameworks" - SDL_MIXER_LIB=-Wl,-framework,SDL_mixer - endif - ifeq (1,$(DARWIN9)) COMPILERFLAGS += -DDARWIN9 endif @@ -789,18 +771,11 @@ ifeq ($(PLATFORM),WINDOWS) MIXERTYPE?=WIN ifneq ($(RENDERTYPE),SDL) ifeq ($(MIXERTYPE),SDL) - MIXERTYPE:=WIN + override MIXERTYPE:=WIN endif endif - SDL_INCLUDES= - ifeq ($(SDL_TARGET),1) - SDL_MIXER_LIB=platform/Windows/lib$(WINLIB)/SDL_mixer.lib - endif - WITHOUT_GTK?=1 - SDLCONFIG= - SDL_FRAMEWORK=1 EXESUFFIX=.exe DLLSUFFIX=.dll LIBDIRS+= -Lplatform/Windows/lib$(WINLIB) @@ -812,25 +787,22 @@ ifeq ($(PLATFORM),WINDOWS) STDCPPLIB:=-lstdc++ COMMONFLAGS += -fno-pic +else + RENDERTYPE?=SDL + MIXERTYPE?=SDL endif ifeq ($(PLATFORM),BSD) COMPILERFLAGS+= -I/usr/local/include - RENDERTYPE=SDL - MIXERTYPE=SDL COMPILERFLAGS+= -DHAVE_INTTYPES STDCPPLIB:=-lstdc++ endif ifeq ($(PLATFORM),BEOS) override NOASM=1 - RENDERTYPE=SDL - MIXERTYPE=SDL STDCPPLIB:=-lstdc++ endif ifeq ($(PLATFORM),SKYOS) - RENDERTYPE=SDL - MIXERTYPE=SDL EXESUFFIX=.app override NOASM=1 COMPILERFLAGS+= -DUNDERSCORES -I/boot/programs/sdk/include/sdl @@ -838,9 +810,6 @@ ifeq ($(PLATFORM),SKYOS) LIBS+= -lSDL -lnet endif ifeq ($(PLATFORM),WII) - RENDERTYPE=SDL - MIXERTYPE=SDL - SDL_INCLUDES= EXESUFFIX=.elf override USE_OPENGL=0 override POLYMER=0 @@ -851,28 +820,21 @@ ifeq ($(PLATFORM),WII) COMPILERFLAGS+= -DGEKKO -DHAVE_INTTYPES -D__POWERPC__ -I$(LIBOGC_INC) -I$(PORTLIBS)/include -Iplatform/Wii/include SDLCONFIG= SDL_TARGET=1 - SDL_FRAMEWORK=1 LIBDIRS += -L$(LIBOGC_LIB) -L$(PORTLIBS)/lib -Lplatform/Wii/lib endif ifeq ($(PLATFORM),QNX) - RENDERTYPE=SDL - MIXERTYPE=SDL override USE_OPENGL=0 override NOASM=1 STDCPPLIB:=-lstdc++ LIBS+= -lsocket endif ifeq ($(PLATFORM),SUNOS) - RENDERTYPE=SDL - MIXERTYPE=SDL override USE_OPENGL=0 override NOASM=1 STDCPPLIB:=-lstdc++ LIBS+= -lsocket -lnsl endif ifeq ($(PLATFORM),SYLLABLE) - RENDERTYPE=SDL - MIXERTYPE=SDL override USE_OPENGL=0 override NOASM=1 endif @@ -897,55 +859,54 @@ ifneq (0,$(CLANG)) endif endif -ifeq ($(SDL_TARGET),2) - SDLCONFIG ?= sdl2-config - SDLNAME ?= SDL2 -endif -ifeq ($(SDL_TARGET),1) - SDLCONFIG ?= sdl-config - SDLNAME ?= SDL -endif - -ifneq ($(SDLCONFIG),) - SDLVERSION:=$(strip $(shell $(SDLCONFIG) --version)) - ifneq ($(SDLVERSION),) - SDLROOT:=$(strip $(shell $(SDLCONFIG) --prefix)) - endif -endif - -SDL_STATIC?=1 - ifeq ($(RENDERTYPE),SDL) + ifeq ($(SDL_TARGET),2) + SDLCONFIG ?= sdl2-config + SDLNAME ?= SDL2 + endif + ifeq ($(SDL_TARGET),1) + SDLCONFIG ?= sdl-config + SDLNAME ?= SDL + ifeq (0,$(RELEASE)) + COMPILERFLAGS += -DNOSDLPARACHUTE + endif + endif + + ifneq ($(strip $(SDLCONFIG)),) + ifeq ($(strip $(shell $(SDLCONFIG) --version $(DONT_PRINT_STDERR))),) + override SDLCONFIG = + endif + endif + COMPILERFLAGS += -DSDL_TARGET=$(SDL_TARGET) - ifeq ($(SDL_FRAMEWORK),1) - COMPILERFLAGS += -DSDL_FRAMEWORK - endif - - ifneq ($(PLATFORM),WINDOWS) - ifeq ($(SDL_FRAMEWORK),1) - ifeq ($(PLATFORM),DARWIN) - LIBS += -Wl,-framework,SDL - COMPILERFLAGS+= -I$(APPLE_FRAMEWORKS)/SDL.framework/Headers \ - -I$(APPLE_FRAMEWORKS)/SDL_mixer.framework/Headers - endif - else - ifneq ($(SDLCONFIG),) - SDLCONFIG_COMMONFLAGS:=$(subst -Dmain=SDL_main,,$(strip $(shell $(SDLCONFIG) --cflags))) - SDLCONFIG_LIBS:=$(strip $(shell $(SDLCONFIG) --libs)) - - LIBS+= $(SDLCONFIG_LIBS) - COMMONFLAGS+= $(SDLCONFIG_COMMONFLAGS) + ifneq ($(SDL_FRAMEWORK),0) + ifeq ($(PLATFORM),DARWIN) + LIBDIRS += -F$(APPLE_FRAMEWORKS) + ifeq ($(MIXERTYPE),SDL) + COMPILERFLAGS += -I$(APPLE_FRAMEWORKS)/$(SDLNAME)_mixer.framework/Headers + LIBS += -Wl,-framework,$(SDLNAME)_mixer endif + COMPILERFLAGS += -I$(APPLE_FRAMEWORKS)/$(SDLNAME).framework/Headers + LIBS += -Wl,-framework,$(SDLNAME) -Wl,-rpath -Wl,"@loader_path/../Frameworks" endif else - COMPILERFLAGS += -D_GNU_SOURCE=1 - ifneq ($(SDL_STATIC),0) - ifneq ($(SDL_TARGET),1) # Since SDL2 is under the zlib license, link statically if possible. - LIBS+= -static - endif + ifeq ($(MIXERTYPE),SDL) + LIBS += -l$(SDLNAME)_mixer + endif + ifneq ($(SDLCONFIG),) + SDLCONFIG_CFLAGS := $(strip $(subst -Dmain=SDL_main,,$(shell $(SDLCONFIG) --cflags))) + SDLCONFIG_LIBS := $(strip $(subst -mwindows,,$(shell $(SDLCONFIG) --libs))) + + COMMONFLAGS += $(SDLCONFIG_CFLAGS) + LIBS += $(SDLCONFIG_LIBS) + else + ifeq ($(SDL_TARGET),1) + COMPILERFLAGS += -D_GNU_SOURCE=1 + endif + COMPILERFLAGS += -D_REENTRANT -DSDL_USEFOLDER + LIBS+= -l$(SDLNAME) endif - LIBS+= -l$(SDLNAME)main -l$(SDLNAME) -lmingw32 -lgdi32 -limm32 -lole32 -loleaut32 -lwinmm -lversion endif ifeq (1,$(WITHOUT_GTK)) @@ -969,25 +930,14 @@ ifeq ($(RENDERTYPE),SDL) endif endif - COMPILERFLAGS += $(SDL_INCLUDES) - ifneq ($(MIXERTYPE),WIN) - LIBS += $(SDL_MIXER_LIB) + ifeq ($(PLATFORM),WINDOWS) + LIBS += -ldxguid_sdl -lmingw32 -lgdi32 -limm32 -lole32 -loleaut32 -lwinmm -lversion endif - LIBS += $(SDL_LIB) endif ifeq ($(RENDERTYPE),WIN) LIBS+= -ldxguid endif -# SDL depends on these -ifeq ($(PLATFORM),WINDOWS) - ifeq ($(RENDERTYPE),SDL) - SDL_LIB:=-l$(SDLNAME)main $(SDL_LIB) - ifeq ($(MIXERTYPE),WIN) - LIBS+= -ldxguid_sdl - endif - endif -endif ifeq ($(PLATFORM),WII) LIBS+= -laesnd_tueidj -lpng -lfat -lwiiuse -lbte -logc -lm -lwiikeyboard endif diff --git a/polymer/eduke32/Makefile.msvc b/polymer/eduke32/Makefile.msvc index 172f468c7..1430ebd5a 100644 --- a/polymer/eduke32/Makefile.msvc +++ b/polymer/eduke32/Makefile.msvc @@ -92,7 +92,7 @@ MT=mt CFLAGS= /MT /J /nologo $(flags_cl) \ /I$(DUKE3D_INC) /I$(ENGINE_INC)\msvc /I$(ENGINE_INC) /I$(MACT_ROOT) /I$(AUDIOLIB_ROOT)\include /I$(ENET_ROOT)\include \ /W2 $(ENGINEOPTS) \ - /I$(PLATFORM)\include /I$(AUDIOINC)\include /DRENDERTYPE$(RENDERTYPE)=1 /DMIXERTYPE$(MIXERTYPE)=1 /DSDL_FRAMEWORK /DSDL_TARGET=2 + /I$(PLATFORM)\include /I$(AUDIOINC)\include /DRENDERTYPE$(RENDERTYPE)=1 /DMIXERTYPE$(MIXERTYPE)=1 /DSDL_USEFOLDER /DSDL_TARGET=2 ENET_CFLAGS=/I$(ENET_INC) /I$(ENET_SRC) AUDIOLIB_CFLAGS=/I$(AUDIOLIB_INC) /I$(AUDIOLIB_SRC) diff --git a/polymer/eduke32/build/include/SDLMain.h b/polymer/eduke32/build/include/SDLMain.h deleted file mode 100644 index c56d90cbe..000000000 --- a/polymer/eduke32/build/include/SDLMain.h +++ /dev/null @@ -1,16 +0,0 @@ -/* SDLMain.m - main entry point for our Cocoa-ized SDL app - Initial Version: Darrell Walisser - Non-NIB-Code & other changes: Max Horn - - Feel free to customize this file to suit your needs -*/ - -#ifndef _SDLMain_h_ -#define _SDLMain_h_ - -#import - -@interface SDLMain : NSObject -@end - -#endif /* _SDLMain_h_ */ diff --git a/polymer/eduke32/build/include/sdl_inc.h b/polymer/eduke32/build/include/sdl_inc.h index 9efad1d5a..ff783892f 100644 --- a/polymer/eduke32/build/include/sdl_inc.h +++ b/polymer/eduke32/build/include/sdl_inc.h @@ -7,8 +7,8 @@ # undef __MINGW64_VERSION_MAJOR #endif -#if defined(SDL_FRAMEWORK) -# if (SDL_TARGET == 2) +#if defined SDL_USEFOLDER +# if SDL_TARGET == 2 # include # include # else @@ -17,6 +17,9 @@ # endif #else # include "SDL.h" +# if !defined __APPLE__ +# include "SDL_syswm.h" +# endif #endif #if defined __MINGW64_VERSION_MAJOR_BACKUP && !defined __MINGW64__ @@ -43,38 +46,37 @@ Minimum required SDL versions: #error SDL version found is too old #endif -#if defined(_NEED_SDLMIXER) -# if defined(SDL_FRAMEWORK) -# if defined(_WIN32) || defined(GEKKO) -# if (SDL_TARGET == 2) -# include -# else -# include -# endif +#if defined _NEED_SDLMIXER + +# if defined SDL_USEFOLDER +# if SDL_TARGET == 2 +# include # else -# if (SDL_TARGET == 2) -# include -# else -# include -# endif +# include # endif # else # include "SDL_mixer.h" # endif + /* starting with 1.2.1, SDL_mixer provides MIX_xxx version macros. the new SDL_MIXER_xxx version macros start with 1.2.6 but they keep backwards compatibility. 1.2.0 does not even have any version macros, so let's reject it */ -#if !defined(MIX_MAJOR_VERSION) || !defined(MIX_MINOR_VERSION) || !defined(MIX_PATCHLEVEL) -#error SDL_mixer version found is too old +# if !defined(MIX_MAJOR_VERSION) || !defined(MIX_MINOR_VERSION) || !defined(MIX_PATCHLEVEL) +# error SDL_mixer version found is too old +# endif + +# ifndef MIX_COMPILEDVERSION +# define MIX_COMPILEDVERSION (SDL_VERSIONNUM(MIX_MAJOR_VERSION,MIX_MINOR_VERSION,MIX_PATCHLEVEL)) +# endif +# if MIX_COMPILEDVERSION < MIX_REQUIREDVERSION +# error SDL_mixer version found is too old +# endif + +# if SDL_MAJOR_VERSION != MIX_MAJOR_VERSION +# error Major version of SDL_mixer headers does not match SDL headers +# endif + #endif -#ifndef MIX_COMPILEDVERSION -#define MIX_COMPILEDVERSION (SDL_VERSIONNUM(MIX_MAJOR_VERSION,MIX_MINOR_VERSION,MIX_PATCHLEVEL)) -#endif -#if MIX_COMPILEDVERSION < MIX_REQUIREDVERSION -#error SDL_mixer version found is too old -#endif /* end of bad version error */ -#endif /* end of SDL_mixer checks */ #endif /* SDL_INC_H_ */ - diff --git a/polymer/eduke32/build/src/SDLMain.m b/polymer/eduke32/build/src/SDLMain.m index 84d6346a8..93970d135 100644 --- a/polymer/eduke32/build/src/SDLMain.m +++ b/polymer/eduke32/build/src/SDLMain.m @@ -3,6 +3,8 @@ Non-NIB-Code & other changes: Max Horn Feel free to customize this file to suit your needs + + Modified for EDuke32 */ #import @@ -15,7 +17,8 @@ #import #include "sdl_inc.h" -#include "SDLMain.h" + +#import #include /* for MAXPATHLEN */ #include @@ -31,6 +34,11 @@ /* Use this flag to determine whether we use CPS (docking) or not */ #define SDL_USE_CPS #ifdef SDL_USE_CPS + +#ifdef __cplusplus +extern "C" { +#endif + /* Portions of CPS.h */ typedef struct CPSProcessSerNum { @@ -42,6 +50,10 @@ extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn); extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5); extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn); +#ifdef __cplusplus +} +#endif + #endif /* SDL_USE_CPS */ static int gArgc; @@ -83,11 +95,11 @@ static NSString *getApplicationName(void) } @end -@interface SDLMain (NSObject) +@interface SDLMain : NSObject @end /* The main class of the application, the application's delegate */ -@implementation SDLMain (NSObject) +@implementation SDLMain /* Set the working directory to the .app's parent directory */ - (void) setupWorkingDirectory:(BOOL)shouldChdir diff --git a/polymer/eduke32/eduke32.vcxproj b/polymer/eduke32/eduke32.vcxproj index 0497cf473..7e7e1242c 100644 --- a/polymer/eduke32/eduke32.vcxproj +++ b/polymer/eduke32/eduke32.vcxproj @@ -73,19 +73,19 @@ nmake /f Makefile.msvc DEBUG=1 WINBITS=32 RENDERTYPE=SDL nmake /f Makefile.msvc veryclean all DEBUG=1 WINBITS=32 RENDERTYPE=SDL nmake /f Makefile.msvc veryclean DEBUG=1 WINBITS=32 RENDERTYPE=SDL - USE_OPENGL;POLYMER;SDL_FRAMEWORK;SDL_TARGET=2 + USE_OPENGL;POLYMER;SDL_USEFOLDER;SDL_TARGET=2 nmake /f Makefile.msvc WINBITS=32 RENDERTYPE=SDL nmake /f Makefile.msvc veryclean all WINBITS=32 RENDERTYPE=SDL nmake /f Makefile.msvc veryclean WINBITS=32 RENDERTYPE=SDL - USE_OPENGL;POLYMER;SDL_FRAMEWORK;SDL_TARGET=2 + USE_OPENGL;POLYMER;SDL_USEFOLDER;SDL_TARGET=2 nmake /f Makefile.msvc DEBUG=1 WINBITS=64 RENDERTYPE=SDL nmake /f Makefile.msvc veryclean all DEBUG=1 WINBITS=64 RENDERTYPE=SDL nmake /f Makefile.msvc veryclean DEBUG=1 WINBITS=64 RENDERTYPE=SDL - USE_OPENGL;POLYMER;NOASM;HAVE_INTTYPES;SDL_FRAMEWORK;SDL_TARGET=2 + USE_OPENGL;POLYMER;NOASM;HAVE_INTTYPES;SDL_USEFOLDER;SDL_TARGET=2 nmake /f Makefile.msvc WINBITS=64 RENDERTYPE=SDL nmake /f Makefile.msvc veryclean all WINBITS=64 RENDERTYPE=SDL nmake /f Makefile.msvc veryclean WINBITS=64 RENDERTYPE=SDL - USE_OPENGL;POLYMER;NOASM;SDL_FRAMEWORK;SDL_TARGET=2 + USE_OPENGL;POLYMER;NOASM;SDL_USEFOLDER;SDL_TARGET=2 $(VC_IncludePath);$(WindowsSDK_IncludePath);build\include;source\jmact;source\jaudiolib\include;source\enet\include; diff --git a/polymer/synthesis.sh b/polymer/synthesis.sh index 58fc6c6a8..2e1ebf16f 100755 --- a/polymer/synthesis.sh +++ b/polymer/synthesis.sh @@ -8,8 +8,8 @@ top=/var/www/synthesis/eduke32 lockfile=$top/synthesis_building source=eduke32 output=/var/www/dukeworld.duke4.net/eduke32/synthesis -make=( make SYNTHESIS=1 PLATFORM=WINDOWS CROSS='i686-w64-mingw32-' CC='i686-w64-mingw32-gcc-4.8.0' AS='nasm' PRETTY_OUTPUT=0 ) -make64=( make SYNTHESIS=1 PLATFORM=WINDOWS CROSS='x86_64-w64-mingw32-' CC='x86_64-w64-mingw32-gcc-4.8.0' AS='nasm' PRETTY_OUTPUT=0 ) +make=( make SYNTHESIS=1 PLATFORM=WINDOWS CROSS='i686-w64-mingw32-' CC='i686-w64-mingw32-gcc-4.8.0' AS='nasm' SDLCONFIG='' PRETTY_OUTPUT=0 ) +make64=( make SYNTHESIS=1 PLATFORM=WINDOWS CROSS='x86_64-w64-mingw32-' CC='x86_64-w64-mingw32-gcc-4.8.0' AS='nasm' SDLCONFIG='' PRETTY_OUTPUT=0 ) clean=veryclean # the following file paths are relative to $source