From c070e64bd49e1987ba74fb4a4924ef0574a12132 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Tue, 14 May 2019 10:44:33 +0200 Subject: [PATCH] libsdl: config tweaks, remove sdlmain lib This patch contains changes to the libSDL port that were needed to build the Hatari emulator using cmake. - Since SDL programs cannot use the posix library (because sdl's init function needs a way to get hold of the Genode env), the sdl_main library must be used instead of the posix library. The sdl_main code implements the Libc::Component::construct function for the final binary. However, 3rd-party build systems are not aware of this Genode-specific peculiarity and thereby create binaries that leave libsdl uninitialized. This patch adds the sdl_main to libsdl by default and thereby eliminates the need for specifying the extra sdl_main library. Customizing the Libc::Component::construct is still possible by overriding the library-provided implementation in the main program. - A few missing config definitions are added to compile Hatari successfully. - Avoid reliance on the include/SDL convention in SDL_config.h - Cmake relies on the upper-case naming of the library with no way to tweak this convention. So we install an symlink named `SDL.lib.so` when installing the library into the /bin/ directory. Fixes #161 --- include/SDL/SDL_config.h | 2 +- include/SDL/SDL_config_genode.h | 6 +++++- lib/mk/sdl.mk | 8 ++++++++ lib/mk/sdlmain.mk | 7 ------- lib/symbols/sdl | 1 + recipes/api/sdl/content.mk | 7 +------ recipes/api/sdl/hash | 2 +- recipes/src/sdl/hash | 2 +- src/app/abuse/target.mk | 2 +- src/app/atari800/target.mk | 2 +- src/app/avplay/target.mk | 2 +- src/app/chocolate-doom/target.inc | 2 +- src/app/dosbox/target.mk | 2 +- src/app/grafx2/target.mk | 2 +- src/app/ltris/target.mk | 2 +- src/app/numptyphysics/target.mk | 2 +- src/app/opentyrian/target.mk | 2 +- src/app/supertux/target.mk | 2 +- src/app/tuxmath/target.mk | 2 +- src/app/uhexen2/target.mk | 2 +- src/test/sdl/target.mk | 2 +- 21 files changed, 31 insertions(+), 30 deletions(-) delete mode 100644 lib/mk/sdlmain.mk diff --git a/include/SDL/SDL_config.h b/include/SDL/SDL_config.h index 0c784ac..3d826f8 100644 --- a/include/SDL/SDL_config.h +++ b/include/SDL/SDL_config.h @@ -31,7 +31,7 @@ #ifndef _SDL_config_h #define _SDL_config_h -#include +#include #include "SDL_config_genode.h" #endif /* _SDL_config_h */ diff --git a/include/SDL/SDL_config_genode.h b/include/SDL/SDL_config_genode.h index d1d21fa..74a2a05 100644 --- a/include/SDL/SDL_config_genode.h +++ b/include/SDL/SDL_config_genode.h @@ -61,6 +61,8 @@ #define SDL_VIDEO_OPENGL 1 +#define SDL_HAS_64BIT_TYPE 1 + /* #define HAVE_MREMAP 0 */ #define HAVE_MALLOC #define HAVE_CALLOC @@ -77,7 +79,9 @@ #define HAVE_SNPRINTF #define HAVE_VSNPRINTF -#define HAVE_STDIO_H 1 +#define HAVE_STDIO_H 1 +#define HAVE_INTTYPES_H 1 +#define HAVE_MATH_H 1 /* #define SDL_malloc malloc */ /* #define SDL_calloc calloc */ diff --git a/lib/mk/sdl.mk b/lib/mk/sdl.mk index fce3297..09feb21 100644 --- a/lib/mk/sdl.mk +++ b/lib/mk/sdl.mk @@ -81,6 +81,8 @@ SRC_C += cdrom/SDL_cdrom.c \ cdrom/dummy/SDL_syscdrom.c INC_DIR += $(SDL_DIR)/src/cdrom +SRC_CC += sdl_main.cc + # we need libc LIBS = libc mesa_api @@ -90,3 +92,9 @@ vpath % $(REP_DIR)/src/lib/sdl vpath % $(SDL_DIR)/src CC_CXX_WARN_STRICT = + +$(INSTALL_DIR)/sdl.lib.so: $(INSTALL_DIR)/SDL.lib.so + +$(INSTALL_DIR)/SDL.lib.so: + $(VERBOSE)ln -sf sdl.lib.so $@ + diff --git a/lib/mk/sdlmain.mk b/lib/mk/sdlmain.mk deleted file mode 100644 index 41bf547..0000000 --- a/lib/mk/sdlmain.mk +++ /dev/null @@ -1,7 +0,0 @@ -SRC_CC = sdl_main.cc - -LIBS += libc - -vpath sdl_main.cc $(REP_DIR)/src/lib/sdl - -CC_CXX_WARN_STRICT = diff --git a/lib/symbols/sdl b/lib/symbols/sdl index 4c29286..041c065 100644 --- a/lib/symbols/sdl +++ b/lib/symbols/sdl @@ -1,3 +1,4 @@ +_ZN4Libc9Component9constructERNS_3EnvE T SDL_AddTimer T SDL_AllocBlitMap T SDL_AllocFormat T diff --git a/recipes/api/sdl/content.mk b/recipes/api/sdl/content.mk index d9d5057..c94b9ee 100644 --- a/recipes/api/sdl/content.mk +++ b/recipes/api/sdl/content.mk @@ -1,9 +1,8 @@ MIRROR_FROM_REP_DIR := lib/symbols/sdl lib/import/import-sdl.mk \ - lib/mk/sdlmain.mk MIRROR_FROM_LIBPORTS := lib/mk/mesa_api.mk -content: $(MIRROR_FROM_REP_DIR) $(MIRROR_FROM_LIBPORTS) src/lib/sdl include LICENSE +content: $(MIRROR_FROM_REP_DIR) $(MIRROR_FROM_LIBPORTS) include LICENSE $(MIRROR_FROM_REP_DIR): $(mirror_from_rep_dir) @@ -25,9 +24,5 @@ include: cp -r $(MESA_PORT_DIR)/include/* $@/ cp -r $(GENODE_DIR)/repos/libports/include/EGL $@/ -src/lib/sdl: - mkdir -p $@ - cp -r $(REP_DIR)/src/lib/sdl/sdl_main.cc $@/ - LICENSE: cp $(SDL_PORT_DIR)/src/lib/sdl/COPYING $@ diff --git a/recipes/api/sdl/hash b/recipes/api/sdl/hash index 489fc96..bfa7d0b 100644 --- a/recipes/api/sdl/hash +++ b/recipes/api/sdl/hash @@ -1 +1 @@ -2018-03-18 2cdaa5c32a93a5acf0ee7159f96e9f01d67ab8d2 +2019-05-14 cb3175a6545ea045864baa9783f4ac54a3206826 diff --git a/recipes/src/sdl/hash b/recipes/src/sdl/hash index 2a8d6fc..3e55893 100644 --- a/recipes/src/sdl/hash +++ b/recipes/src/sdl/hash @@ -1 +1 @@ -2019-01-02 155b546298117fca760a633abcd79080e124df6c +2019-05-14 598e91be62c73d18bad160f5f2438a855c4f0ed1 diff --git a/src/app/abuse/target.mk b/src/app/abuse/target.mk index 493171f..6a2a843 100644 --- a/src/app/abuse/target.mk +++ b/src/app/abuse/target.mk @@ -30,7 +30,7 @@ INC_DIR += $(PRG_DIR) \ $(ABUSE_SRC)/net \ $(ABUSE_SRC)/ui -LIBS += base abuse_imlib libc libm stdcxx sdlmain sdl sdl_image sdl_mixer sdl_net +LIBS += base abuse_imlib libc libm stdcxx sdl sdl_image sdl_mixer sdl_net CC_WARN += \ -Wno-unused-but-set-variable \ diff --git a/src/app/atari800/target.mk b/src/app/atari800/target.mk index 449ec36..519ed3d 100644 --- a/src/app/atari800/target.mk +++ b/src/app/atari800/target.mk @@ -18,7 +18,7 @@ INC_DIR += $(ATARI800_DIR)/src $(PRG_DIR) CC_WARN := -Wall -Wno-unused-but-set-variable -Wno-logical-not-parentheses -LIBS += sdl sdlmain zlib libc libpng +LIBS += sdl zlib libc libpng $(TARGET): atari800_rom.tar atari800_rom.tar: diff --git a/src/app/avplay/target.mk b/src/app/avplay/target.mk index 1a574b5..3b2dd24 100644 --- a/src/app/avplay/target.mk +++ b/src/app/avplay/target.mk @@ -3,7 +3,7 @@ include $(REP_DIR)/lib/import/import-av.inc TARGET = avplay SRC_C = avplay.c cmdutils.c libc_dummies.c LIBS += avfilter avformat avcodec avutil avresample swscale -LIBS += base sdl sdlmain libc libm +LIBS += base sdl libc libm CC_WARN += -Wno-parentheses -Wno-switch -Wno-uninitialized \ -Wno-format-zero-length -Wno-pointer-sign diff --git a/src/app/chocolate-doom/target.inc b/src/app/chocolate-doom/target.inc index 02dd37f..9224191 100644 --- a/src/app/chocolate-doom/target.inc +++ b/src/app/chocolate-doom/target.inc @@ -83,6 +83,6 @@ INC_DIR += $(CHOCOLATE_DOOM_DIR)/src INC_DIR += $(CHOCOLATE_DOOM_DIR)/src/$(GAME) INC_DIR += $(CHOCOLATE_DOOM_DIR)/textscreen -LIBS := base sdl sdlmain libc libm sdl_mixer sdl_net +LIBS := base sdl libc libm sdl_mixer sdl_net # vi:set ft=make : diff --git a/src/app/dosbox/target.mk b/src/app/dosbox/target.mk index 130de6b..747b45a 100644 --- a/src/app/dosbox/target.mk +++ b/src/app/dosbox/target.mk @@ -55,6 +55,6 @@ CC_WARN += -Wno-unused-variable -Wno-unused-function -Wno-switch -Wno-unused-val -Wno-sign-compare -Wno-narrowing -Wno-missing-braces -Wno-array-bounds \ -Wno-parentheses -LIBS += libpng libc sdl sdlmain sdl_net stdcxx zlib +LIBS += libpng libc sdl sdl_net stdcxx zlib CC_CXX_WARN_STRICT = diff --git a/src/app/grafx2/target.mk b/src/app/grafx2/target.mk index 9a795b4..52d32c8 100644 --- a/src/app/grafx2/target.mk +++ b/src/app/grafx2/target.mk @@ -9,7 +9,7 @@ INC_DIR += $(GRAFX2_DIR) CC_OPT += -DGENODE -DNOTTF=1 -LIBS += libc libpng sdlmain sdl sdl_image libm zlib base +LIBS += libc libpng sdl sdl_image libm zlib base $(TARGET): grafx2_data.tar grafx2_data.tar: diff --git a/src/app/ltris/target.mk b/src/app/ltris/target.mk index 77e4c0f..8f3eae3 100644 --- a/src/app/ltris/target.mk +++ b/src/app/ltris/target.mk @@ -1,5 +1,5 @@ TARGET = ltris -LIBS = libc libm stdcxx sdlmain sdl sdl_mixer +LIBS = libc libm stdcxx sdl sdl_mixer LTRIS_DIR := $(call select_from_ports,ltris)/src/app/ltris diff --git a/src/app/numptyphysics/target.mk b/src/app/numptyphysics/target.mk index fff05f4..ab838c6 100644 --- a/src/app/numptyphysics/target.mk +++ b/src/app/numptyphysics/target.mk @@ -55,7 +55,7 @@ vpath getenv.cc $(PRG_DIR) INC_DIR += $(NUMPTY_DIR) $(NUMPTY_DIR)/Box2D/Include LIBS += base stdcxx libc libm -LIBS += sdlmain sdl sdl_image sdl_ttf zlib +LIBS += sdl sdl_image sdl_ttf zlib CC_OPT_Canvas := -DGENODE diff --git a/src/app/opentyrian/target.mk b/src/app/opentyrian/target.mk index aca0131..a35264c 100644 --- a/src/app/opentyrian/target.mk +++ b/src/app/opentyrian/target.mk @@ -7,7 +7,7 @@ SRC_C := $(notdir $(wildcard $(OPENTYRIAN_SRC)/*.c)) vpath %.c $(OPENTYRIAN_SRC) -LIBS += libc libm sdlmain sdl sdl_net base +LIBS += libc libm sdl sdl_net base CC_OPT += -std=c99 -DTARGET_UNIX diff --git a/src/app/supertux/target.mk b/src/app/supertux/target.mk index b6cc1b9..544093f 100644 --- a/src/app/supertux/target.mk +++ b/src/app/supertux/target.mk @@ -10,7 +10,7 @@ vpath %.cpp $(SUPERTUX_DIR)/src INC_DIR += $(SUPERTUX_DIR)/src LIBS += stdcxx -LIBS += sdl sdlmain sdl_image sdl_mixer zlib +LIBS += sdl sdl_image sdl_mixer zlib $(TARGET): supertux_data.tar supertux_data.tar: diff --git a/src/app/tuxmath/target.mk b/src/app/tuxmath/target.mk index dd75470..0c4077a 100644 --- a/src/app/tuxmath/target.mk +++ b/src/app/tuxmath/target.mk @@ -2,7 +2,7 @@ TARGET := tuxmath TUXMATH_DIR := $(call select_from_ports,tuxmath)/src/app/tuxmath -LIBS += libc libm sdlmain sdl sdl_image sdl_mixer sdl_ttf sdl_net tuxmath_t4k +LIBS += libc libm sdl sdl_image sdl_mixer sdl_ttf sdl_net tuxmath_t4k INC_DIR += $(REP_DIR)/src/app/tuxmath \ $(TUXMATH_DIR)/t4k/src diff --git a/src/app/uhexen2/target.mk b/src/app/uhexen2/target.mk index b01eb3b..5180b0a 100644 --- a/src/app/uhexen2/target.mk +++ b/src/app/uhexen2/target.mk @@ -118,7 +118,7 @@ CC_OPT += -DNO_ALSA_AUDIO -DNO_OSS_AUDIO -DNO_SUN_AUDIO CC_OPT += -DDEMOBUILD -LIBS = libc libm sdl sdlmain sdl_mixer +LIBS = libc libm sdl sdl_mixer vpath % $(UHEXEN2_DIR)/common vpath % $(UHEXEN2_DIR)/engine/hexen2 diff --git a/src/test/sdl/target.mk b/src/test/sdl/target.mk index 1c04b61..2a218bc 100644 --- a/src/test/sdl/target.mk +++ b/src/test/sdl/target.mk @@ -1,5 +1,5 @@ TARGET := test-sdl -LIBS := libc sdl sdlmain +LIBS := libc sdl SRC_CC := main.cc CC_CXX_WARN_STRICT =