Makefile 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #
  2. # meg4/platform/sdl/Makefile
  3. #
  4. # Copyright (C) 2023 bzt
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. #
  20. # @brief The SDL Makefile
  21. #
  22. #USE_MINGWSDL = ../../SDL2-mingw
  23. BACKEND=sdl
  24. # Emscripten
  25. ifneq ($(USE_EMCC),)
  26. PACKAGE = emscripten
  27. CFLAGS = -s USE_SDL=2 -I/usr/include/SDL2 -I/usr/include/SDL -Wno-unknown-warning-option
  28. # wasm crashes in browser if compiled with -g
  29. DEBUG=
  30. else
  31. # MacOS
  32. ifneq ("$(wildcard /Library/Frameworks/SDL*)","")
  33. PACKAGE = MacOS
  34. CFLAGS = -I/Library/Frameworks/SDL2.framework/Headers -I/Library/Frameworks/SDL2.framework/Versions/A/Headers -D_MACOS_=1 -x objective-c -fobjc-exceptions
  35. LIBS = -F/Library/Frameworks -framework SDL2 -framework AppKit
  36. else
  37. # Windows MinGW
  38. ifneq ("$(wildcard /bin/*.exe)","")
  39. PACKAGE = Win
  40. LDFLAGS += -mwindows -static-libgcc
  41. LIBS += -Wl,--nxcompat -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive -luser32 -lcomdlg32 -lole32 -lshlwapi \
  42. -lws2_32 -loleaut32 -lwinmm -limm32 -lsetupapi -luuid -lversion -lm
  43. ifneq ("$(wildcard $(USE_MINGWSDL)/build/.libs/libSDL2.a)","")
  44. CFLAGS += -I$(USE_MINGWSDL)/include
  45. EXTRA += $(USE_MINGWSDL)/build/.libs/libSDL2.a
  46. else
  47. ifneq ("$(wildcard SDL3/*)","")
  48. CFLAGS += -I./SDL3/include/SDL3 -I./SDL3/include
  49. EXTRA += ./SDL3/build/libSDL3.a
  50. else
  51. ifneq ("$(wildcard SDL2/*)","")
  52. CFLAGS += -I./SDL2/include
  53. EXTRA += ./SDL2/build/.libs/libSDL2.a
  54. else
  55. CFLAGS = -I/usr/include/SDL2
  56. LIBS += -lSDL2
  57. endif
  58. endif
  59. endif
  60. else
  61. # Linux
  62. PACKAGE = Linux
  63. ifneq ($(USE_DYNSDL),)
  64. CFLAGS = -I/usr/include/SDL2
  65. LIBS += -lSDL2
  66. else
  67. ifneq ("$(wildcard SDL3/*)","")
  68. CFLAGS += -I./SDL3/include/SDL3 -I./SDL3/include
  69. EXTRA += ./SDL3/build/libSDL3.a
  70. else
  71. ifneq ("$(wildcard SDL2/*)","")
  72. CFLAGS += -I./SDL2/include
  73. EXTRA += ./SDL2/build/.libs/libSDL2.a
  74. else
  75. CFLAGS = -I/usr/include/SDL2
  76. LIBS += -lSDL2
  77. endif
  78. endif
  79. endif
  80. LIBS += -lm -ldl -lpthread
  81. endif
  82. endif
  83. endif
  84. ifneq ($(FINGEREVENTS),)
  85. CFLAGS += -DFINGEREVENTS=1
  86. endif
  87. ifneq ($(NOEDITORS),)
  88. CFLAGS += -DNOEDITORS=1
  89. endif
  90. ifneq ($(EMBED),)
  91. CFLAGS += -DEMBED=1
  92. endif
  93. EXTRA += data.o
  94. include ../common.mk
  95. ifneq ("$(wildcard SDL2/*)","")
  96. SDL2/build/.libs/libSDL2.a:
  97. ifeq ($(wildcard SDL2/configure),)
  98. @cd SDL2 && ./autogen.sh
  99. endif
  100. ifeq ($(wildcard SDL2/Makefile),)
  101. @#dbus call in SDL2/src/core/linux/SDL_dbus.c:140 is leaking pretty badly. We don't need dbus anyway
  102. @#can't compile SDL2 with the latest wayland, the wl tools are buggy. Remove --disable-video-wayland once wl gets fixed
  103. @cd SDL2 && ./configure --disable-shared --enable-static --disable-dbus --disable-video-wayland
  104. endif
  105. @make --no-print-directory -s -C SDL2 all
  106. endif
  107. ifneq ("$(wildcard SDL3/*)","")
  108. SDL3/build/libSDL3.a:
  109. ifeq ($(wildcard SDL3/build/Makefile),)
  110. @cd SDL3 && mkdir build && cd build && cmake -S .. -B ../build && cmake . -DCMAKE_BUILD_TYPE=Release -DSDL_SHARED=false -DSDL_STATIC=true -DSDL_DBUS=false -DSDL_IBUS=false
  111. endif
  112. @make --no-print-directory -s -C SDL3/build all
  113. endif
  114. gamecontrollerdb.txt:
  115. curl -L "https://github.com/gabomdq/SDL_GameControllerDB/raw/master/gamecontrollerdb.txt" --output gamecontrollerdb.txt
  116. data.c: gamecontrollerdb.txt
  117. ifneq ($(USE_EMCC),)
  118. @cc ../../src/bin2h.c -o bin2h
  119. else
  120. @$(CC) ../../src/bin2h.c -o bin2h
  121. endif
  122. @cat gamecontrollerdb.txt | grep "platform:" | gzip >gamecontrollerdb
  123. ./bin2h gamecontrollerdb
  124. @rm bin2h bin2h.exe gamecontrollerdb 2>/dev/null || true
  125. data.o: data.c
  126. static-sdl2:
  127. git clone --branch SDL2 https://github.com/libsdl-org/SDL.git
  128. mv SDL SDL2
  129. printf "#ifndef SDL_dynapi_h_\n#define SDL_dynapi_h_\n#define SDL_DYNAMIC_API 0\n#endif" >SDL2/src/dynapi/SDL_dynapi.h
  130. static-sdl3:
  131. git clone https://github.com/libsdl-org/SDL.git
  132. mv SDL SDL3