Makefile 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. # Makefile script to generate AppImage for LOVE
  2. # Number of processor to use when compiling
  3. NUMBER_OF_PROCESSORS := $(shell nproc)
  4. # CPU architecture, defaults to host
  5. ARCH := $(shell uname -m)
  6. # CMake URL
  7. CMAKE_VERSION := 3.26.3
  8. CMAKE_URL := https://github.com/Kitware/CMake/releases/download/v$(CMAKE_VERSION)/cmake-$(CMAKE_VERSION)-linux-$(shell uname -m).sh
  9. # Project branches (for git-based projects)
  10. LOVE_BRANCH := main
  11. SDL2_BRANCH := release-2.26.5
  12. LUAJIT_BRANCH := v2.1
  13. OPENAL_BRANCH := 1.23.1
  14. BROTLI_BRANCH := v1.0.9
  15. ZLIB_BRANCH := v1.2.13
  16. FT_BRANCH := VER-2-13-0
  17. # Project versions (for downloadable tars)
  18. LIBOGG_VERSION := 1.3.5
  19. LIBVORBIS_VERSION := 1.3.7
  20. LIBTHEORA_VERSION := 1.2.0alpha1
  21. LIBPNG_VERSION := 1.6.39
  22. BZIP2_VERSION := 1.0.8
  23. MPG123_VERSION := 1.31.3
  24. LIBMODPLUG_VERSION := 0.8.8.5
  25. # Output AppImage
  26. APPIMAGE_OUTPUT := love-$(LOVE_BRANCH).AppImage
  27. # Output tar
  28. TAR_OUTPUT := love-$(LOVE_BRANCH).tar.gz
  29. # No need to change anything beyond this line
  30. override INSTALLPREFIX := $(CURDIR)/installdir
  31. override CMAKE_PREFIX := $(CURDIR)/cmake
  32. CMAKE := $(CMAKE_PREFIX)/bin/cmake
  33. override CMAKE_OPTS := --install-prefix $(INSTALLPREFIX) -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_RPATH='$$ORIGIN/../lib'
  34. override CONFIGURE := LDFLAGS="-Wl,-rpath,'\$$\$$ORIGIN/../lib' $$LDFLAGS" LD_LIBRARY_PATH=$(INSTALLPREFIX)/lib:${LD_LIBRARY_PATH} ../configure --prefix=$(INSTALLPREFIX)
  35. # CMake setup
  36. ifeq ($(SYSTEM_CMAKE),)
  37. cmake_install.sh:
  38. curl $(CURL_DOH_URL) -Lfo cmake_install.sh $(CMAKE_URL)
  39. chmod u+x cmake_install.sh
  40. $(CMAKE): cmake_install.sh
  41. mkdir cmake
  42. bash cmake_install.sh --prefix=$(CMAKE_PREFIX) --skip-license
  43. touch $(CMAKE)
  44. else
  45. CMAKE := $(CURDIR)/cmakewrapper.sh
  46. $(CMAKE):
  47. which cmake
  48. echo $(shell which cmake) '$$@' > $(CMAKE)
  49. chmod u+x $(CMAKE)
  50. endif
  51. # cURL DoH URL
  52. ifneq ($(DOH_URL),)
  53. override CURL_DOH_URL := --doh-url $(DOH_URL)
  54. endif
  55. cmake: $(CMAKE)
  56. # AppImageTool
  57. appimagetool:
  58. curl $(CURL_DOH_URL) -Lfo appimagetool https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-$(ARCH).AppImage
  59. chmod u+x appimagetool
  60. ifneq ($(QEMU),)
  61. # Extract the AppImageTool
  62. $(QEMU) ./appimagetool --appimage-extract
  63. endif
  64. # SDL2
  65. override SDL2_PATH := SDL2-$(SDL2_BRANCH)
  66. $(SDL2_PATH)/configure:
  67. git clone --depth 1 -b $(SDL2_BRANCH) https://github.com/libsdl-org/SDL $(SDL2_PATH)
  68. $(SDL2_PATH)/build/Makefile: $(SDL2_PATH)/configure
  69. mkdir -p $(SDL2_PATH)/build
  70. cd $(SDL2_PATH)/build && $(CONFIGURE) --disable-video-wayland
  71. installdir/lib/libSDL2.so: $(SDL2_PATH)/build/Makefile
  72. cd $(SDL2_PATH)/build && $(MAKE) install -j$(NUMBER_OF_PROCESSORS)
  73. # libogg
  74. override LIBOGG_FILE := libogg-$(LIBOGG_VERSION)
  75. $(LIBOGG_FILE).tar.gz:
  76. curl $(CURL_DOH_URL) -Lfo $(LIBOGG_FILE).tar.gz http://downloads.xiph.org/releases/ogg/$(LIBOGG_FILE).tar.gz
  77. $(LIBOGG_FILE)/configure: $(LIBOGG_FILE).tar.gz
  78. tar xzf $(LIBOGG_FILE).tar.gz
  79. touch $(LIBOGG_FILE)/configure
  80. $(LIBOGG_FILE)/build/Makefile: $(LIBOGG_FILE)/configure
  81. mkdir -p $(LIBOGG_FILE)/build
  82. cd $(LIBOGG_FILE)/build && $(CONFIGURE)
  83. installdir/lib/libogg.so: $(LIBOGG_FILE)/build/Makefile
  84. cd $(LIBOGG_FILE)/build && $(MAKE) install -j$(NUMBER_OF_PROCESSORS)
  85. # libvorbis
  86. override LIBVORBIS_FILE := libvorbis-$(LIBVORBIS_VERSION)
  87. $(LIBVORBIS_FILE).tar.gz:
  88. curl $(CURL_DOH_URL) -Lfo $(LIBVORBIS_FILE).tar.gz http://downloads.xiph.org/releases/vorbis/$(LIBVORBIS_FILE).tar.gz
  89. $(LIBVORBIS_FILE)/configure: $(LIBVORBIS_FILE).tar.gz
  90. tar xzf $(LIBVORBIS_FILE).tar.gz
  91. touch $(LIBVORBIS_FILE)/configure
  92. $(LIBVORBIS_FILE)/build/Makefile: $(LIBVORBIS_FILE)/configure installdir/lib/libogg.so
  93. mkdir -p $(LIBVORBIS_FILE)/build
  94. cd $(LIBVORBIS_FILE)/build && $(CONFIGURE)
  95. installdir/lib/libvorbis.so: $(LIBVORBIS_FILE)/build/Makefile
  96. cd $(LIBVORBIS_FILE)/build && $(MAKE) install -j$(NUMBER_OF_PROCESSORS)
  97. # libtheora
  98. override LIBTHEORA_FILE := libtheora-$(LIBTHEORA_VERSION)
  99. $(LIBTHEORA_FILE).tar.gz:
  100. curl $(CURL_DOH_URL) -Lfo $(LIBTHEORA_FILE).tar.gz http://downloads.xiph.org/releases/theora/$(LIBTHEORA_FILE).tar.gz
  101. $(LIBTHEORA_FILE)/configure: $(LIBTHEORA_FILE).tar.gz
  102. tar xzf $(LIBTHEORA_FILE).tar.gz
  103. # Their config.guess and config.sub can't detect ARM64
  104. ifeq ($(ARCH),aarch64)
  105. curl $(CURL_DOH_URL) -Lfo $(LIBTHEORA_FILE)/config.guess "https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD"
  106. chmod u+x $(LIBTHEORA_FILE)/config.guess
  107. curl $(CURL_DOH_URL) -Lfo $(LIBTHEORA_FILE)/config.sub "https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD"
  108. chmod u+x $(LIBTHEORA_FILE)/config.sub
  109. endif
  110. touch $(LIBTHEORA_FILE)/configure
  111. $(LIBTHEORA_FILE)/build/Makefile: $(LIBTHEORA_FILE)/configure installdir/lib/libogg.so
  112. mkdir -p $(LIBTHEORA_FILE)/build
  113. cd $(LIBTHEORA_FILE)/build && $(CONFIGURE) --with-ogg=$(INSTALLPREFIX) --with-vorbis=$(INSTALLPREFIX) --disable-examples --disable-encode
  114. installdir/lib/libtheora.so: $(LIBTHEORA_FILE)/build/Makefile
  115. cd $(LIBTHEORA_FILE)/build && $(MAKE) install -j $(NUMBER_OF_PROCESSORS)
  116. # zlib
  117. override ZLIB_PATH := zlib-$(ZLIB_BRANCH)
  118. $(ZLIB_PATH)/configure:
  119. git clone --depth 1 -b $(ZLIB_BRANCH) https://github.com/madler/zlib $(ZLIB_PATH)
  120. $(ZLIB_PATH)/build/Makefile: $(ZLIB_PATH)/configure
  121. mkdir -p $(ZLIB_PATH)/build
  122. cd $(ZLIB_PATH)/build && $(CONFIGURE)
  123. installdir/lib/libz.so: $(ZLIB_PATH)/build/Makefile
  124. cd $(ZLIB_PATH)/build && $(MAKE) install -j$(NUMBER_OF_PROCESSORS)
  125. # libpng
  126. override LIBPNG_FILE := libpng-$(LIBPNG_VERSION)
  127. $(LIBPNG_FILE).tar.gz:
  128. curl -Lo $(LIBPNG_FILE).tar.gz http://prdownloads.sourceforge.net/libpng/$(LIBPNG_FILE).tar.gz?download
  129. $(LIBPNG_FILE)/configure: $(LIBPNG_FILE).tar.gz
  130. tar xzf $(LIBPNG_FILE).tar.gz
  131. touch $(LIBPNG_FILE)/configure
  132. $(LIBPNG_FILE)/build/Makefile: $(LIBPNG_FILE)/configure installdir/lib/libz.so
  133. mkdir -p $(LIBPNG_FILE)/build
  134. cd $(LIBPNG_FILE)/build && LDFLAGS="-L$(INSTALLPREFIX)/lib" CFLAGS="-I$(INSTALLPREFIX)/include" CPPFLAGS="-I$(INSTALLPREFIX)/include" $(CONFIGURE)
  135. installdir/lib/libpng16.so: $(LIBPNG_FILE)/build/Makefile
  136. cd $(LIBPNG_FILE)/build && CFLAGS="-I$(INSTALLPREFIX)/include" $(MAKE) install -j$(NUMBER_OF_PROCESSORS)
  137. # Brotli
  138. override BROTLI_PATH := brotli-$(BROTLI_BRANCH)
  139. $(BROTLI_PATH)/CMakeLists.txt:
  140. git clone --depth 1 -b $(BROTLI_BRANCH) https://github.com/google/brotli $(BROTLI_PATH)
  141. $(BROTLI_PATH)/build/CMakeCache.txt: $(CMAKE) $(BROTLI_PATH)/CMakeLists.txt
  142. $(CMAKE) -B$(BROTLI_PATH)/build -S$(BROTLI_PATH) $(CMAKE_OPTS)
  143. installdir/lib/libbrotlidec.so: $(BROTLI_PATH)/build/CMakeCache.txt
  144. $(CMAKE) --build $(BROTLI_PATH)/build --target install -j $(NUMBER_OF_PROCESSORS)
  145. # OpenAL-soft
  146. override OPENAL_PATH := openal-soft-$(OPENAL_BRANCH)
  147. $(OPENAL_PATH)/CMakeLists.txt:
  148. git clone --depth 1 -b $(OPENAL_BRANCH) https://github.com/kcat/openal-soft $(OPENAL_PATH)
  149. $(OPENAL_PATH)/build/CMakeCache.txt: $(CMAKE) $(OPENAL_PATH)/CMakeLists.txt
  150. $(CMAKE) -B$(OPENAL_PATH)/build -S$(OPENAL_PATH) $(CMAKE_OPTS) -DALSOFT_EXAMPLES=0 -DALSOFT_BACKEND_SNDIO=0
  151. installdir/lib/libopenal.so: $(OPENAL_PATH)/build/CMakeCache.txt
  152. $(CMAKE) --build $(OPENAL_PATH)/build --target install -j $(NUMBER_OF_PROCESSORS)
  153. # BZip2
  154. override BZIP2_FILE := bzip2-$(BZIP2_VERSION)
  155. $(BZIP2_FILE).tar.gz:
  156. curl $(CURL_DOH_URL) -Lfo $(BZIP2_FILE).tar.gz https://sourceware.org/pub/bzip2/$(BZIP2_FILE).tar.gz
  157. $(BZIP2_FILE)/Makefile: $(BZIP2_FILE).tar.gz
  158. tar xzf $(BZIP2_FILE).tar.gz
  159. touch $(BZIP2_FILE)/Makefile
  160. installdir/bzip2installed.txt: $(BZIP2_FILE)/Makefile
  161. cd $(BZIP2_FILE) && $(MAKE) install -j$(NUMBER_OF_PROCESSORS) CFLAGS="-fPIC -Wall -Winline -O2 -g -D_FILE_OFFSET_BITS=64" LDFLAGS="-Wl,-rpath,'\$ORIGIN/../lib'" PREFIX=$(INSTALLPREFIX)
  162. touch installdir/bzip2installed.txt
  163. # FreeType
  164. override FT_PATH := freetype-$(FT_BRANCH)
  165. $(FT_PATH)/configure:
  166. git clone --depth 1 -b $(FT_BRANCH) https://gitlab.freedesktop.org/freetype/freetype.git $(FT_PATH)
  167. $(FT_PATH)/build/Makefile: $(FT_PATH)/configure installdir/bzip2installed.txt installdir/lib/libpng16.so installdir/lib/libz.so installdir/lib/libbrotlidec.so
  168. mkdir -p $(FT_PATH)/build
  169. cd $(FT_PATH)/build && CFLAGS="-I$(INSTALLPREFIX)/include" LDFLAGS="-Wl,-rpath,'\$$\$$ORIGIN/../lib' -L$(INSTALLPREFIX)/lib -Wl,--no-undefined" PKG_CONFIG_PATH=$(INSTALLPREFIX)/lib/pkgconfig ../configure --prefix=$(INSTALLPREFIX)
  170. installdir/lib/libfreetype.so: $(FT_PATH)/build/Makefile
  171. cd $(FT_PATH)/build && $(MAKE) install -j$(NUMBER_OF_PROCESSORS)
  172. # Mpg123
  173. override MPG123_FILE := mpg123-$(MPG123_VERSION)
  174. $(MPG123_FILE).tar.bz2:
  175. curl $(CURL_DOH_URL) -Lfo $(MPG123_FILE).tar.bz2 https://www.mpg123.de/download/$(MPG123_FILE).tar.bz2
  176. $(MPG123_FILE)/configure: $(MPG123_FILE).tar.bz2
  177. tar xf $(MPG123_FILE).tar.bz2
  178. touch $(MPG123_FILE)/configure
  179. $(MPG123_FILE)/builddir/Makefile: $(MPG123_FILE)/configure
  180. mkdir -p $(MPG123_FILE)/builddir
  181. cd $(MPG123_FILE)/builddir && $(CONFIGURE)
  182. installdir/lib/libmpg123.so: $(MPG123_FILE)/builddir/Makefile
  183. cd $(MPG123_FILE)/builddir && $(MAKE) install -j$(NUMBER_OF_PROCESSORS)
  184. # libmodplug
  185. override LIBMODPLUG_FILE := libmodplug-$(LIBMODPLUG_VERSION)
  186. $(LIBMODPLUG_FILE).tar.gz:
  187. curl $(CURL_DOH_URL) -Lfo $(LIBMODPLUG_FILE).tar.gz http://sourceforge.net/projects/modplug-xmms/files/libmodplug/$(LIBMODPLUG_VERSION)/$(LIBMODPLUG_FILE).tar.gz/download
  188. $(LIBMODPLUG_FILE)/configure: $(LIBMODPLUG_FILE).tar.gz
  189. tar xzf $(LIBMODPLUG_FILE).tar.gz
  190. touch $(LIBMODPLUG_FILE)/configure
  191. $(LIBMODPLUG_FILE)/build/Makefile: $(LIBMODPLUG_FILE)/configure
  192. mkdir -p $(LIBMODPLUG_FILE)/build
  193. cd $(LIBMODPLUG_FILE)/build && $(CONFIGURE)
  194. installdir/lib/libmodplug.so: $(LIBMODPLUG_FILE)/build/Makefile
  195. cd $(LIBMODPLUG_FILE)/build && $(MAKE) install -j$(NUMBER_OF_PROCESSORS)
  196. # LuaJIT
  197. override LUAJIT_PATH := LuaJIT-$(LUAJIT_BRANCH)
  198. $(LUAJIT_PATH)/Makefile:
  199. git clone --depth 1 -b $(LUAJIT_BRANCH) https://github.com/LuaJIT/LuaJIT $(LUAJIT_PATH)
  200. installdir/lib/libluajit-5.1.so: $(LUAJIT_PATH)/Makefile
  201. cd $(LUAJIT_PATH) && LDFLAGS="-Wl,-rpath,'\$$\$$ORIGIN/../lib'" $(MAKE) amalg -j$(NUMBER_OF_PROCESSORS) PREFIX=/usr
  202. cd $(LUAJIT_PATH) && make install PREFIX=$(INSTALLPREFIX)
  203. cd $(LUAJIT_PATH) && make clean
  204. # LOVE
  205. override LOVE_PATH := love2d-$(LOVE_BRANCH)
  206. $(LOVE_PATH)/CMakeLists.txt:
  207. git clone --depth 1 -b $(LOVE_BRANCH) https://github.com/love2d/love $(LOVE_PATH)
  208. $(LOVE_PATH)/configure: $(LOVE_PATH)/CMakeLists.txt installdir/lib/libluajit-5.1.so installdir/lib/libmodplug.so installdir/lib/libmpg123.so installdir/lib/libfreetype.so installdir/lib/libopenal.so installdir/lib/libz.so installdir/lib/libtheora.so installdir/lib/libvorbis.so installdir/lib/libogg.so installdir/lib/libSDL2.so
  209. cd $(LOVE_PATH) && bash platform/unix/genmodules
  210. cp $(LOVE_PATH)/platform/unix/configure.ac $(LOVE_PATH) && cp $(LOVE_PATH)/platform/unix/Makefile.am $(LOVE_PATH)
  211. cd $(LOVE_PATH) && autoheader
  212. cd $(LOVE_PATH) && libtoolize --force
  213. cd $(LOVE_PATH) && aclocal -I $(INSTALLPREFIX)/share/aclocal
  214. cd $(LOVE_PATH) && autoconf -I$(INSTALLPREFIX)
  215. cd $(LOVE_PATH) && automake -a
  216. $(LOVE_PATH)/build/Makefile: $(LOVE_PATH)/configure
  217. mkdir -p $(LOVE_PATH)/build
  218. cd $(LOVE_PATH)/build && CFLAGS="-I$(INSTALLPREFIX)/include" PKG_CONFIG_PATH=$(INSTALLPREFIX)/lib/pkgconfig LDFLAGS="-Wl,-rpath,'\$$\$$ORIGIN/../lib' -L$(INSTALLPREFIX)/lib" ../configure --prefix=$(INSTALLPREFIX)
  219. installdir/bin/love: $(LOVE_PATH)/build/Makefile
  220. cd $(LOVE_PATH)/build && $(MAKE) install -j$(NUMBER_OF_PROCESSORS)
  221. installdir/love.sh: love.sh
  222. mkdir -p installdir
  223. cp love.sh installdir/love.sh
  224. touch installdir/love.sh
  225. installdir/AppRun: love.sh installdir/bin/love
  226. mkdir -p installdir
  227. cp love.sh installdir/AppRun
  228. chmod +x installdir/AppRun
  229. installdir/love.desktop: $(LOVE_PATH)/platform/unix/love.desktop.in
  230. cat $(LOVE_PATH)/platform/unix/love.desktop.in | sed 's/@bindir@\///' > installdir/love.desktop
  231. installdir/love.svg: $(LOVE_PATH)/platform/unix/love.svg
  232. cp $(LOVE_PATH)/platform/unix/love.svg installdir/love.svg
  233. installdir/license.txt: $(LOVE_PATH)/license.txt
  234. cp $(LOVE_PATH)/license.txt installdir/license.txt
  235. appimage-prepare $(APPIMAGE_OUTPUT)-debug.tar.gz: installdir/AppRun installdir/love.desktop installdir/love.svg installdir/license.txt appimagetool
  236. mkdir -p installdir2/lib installdir2/bin
  237. cp installdir/AppRun installdir2/AppRun
  238. cp installdir/license.txt installdir2/license.txt
  239. cp installdir/love.desktop installdir2/love.desktop
  240. cp installdir/love.svg installdir2/love.svg
  241. cp -L installdir/bin/love installdir2/bin/love
  242. mkdir -p debugsym
  243. bash $(CURDIR)/separate_debug.sh installdir2/bin/love debugsym/love.debug
  244. patchelf --set-rpath '$$ORIGIN/../lib' installdir2/bin/love
  245. ldd installdir/bin/love | while read line; do \
  246. dll=`echo $$line | sed 's/\s.*//'`; \
  247. if [ -f installdir/lib/$$dll ]; then \
  248. cp -L installdir/lib/$$dll installdir2/lib/$$dll; \
  249. bash $(CURDIR)/separate_debug.sh installdir2/lib/$$dll debugsym/$$dll.debug; \
  250. patchelf --set-rpath '$$ORIGIN/../lib' installdir2/lib/$$dll; \
  251. echo $$dll; \
  252. fi \
  253. done
  254. cp -r installdir/share installdir2/
  255. cd debugsym; tar -cvzf ../$(APPIMAGE_OUTPUT)-debug.tar.gz *
  256. -rm -rf installdir2/share/aclocal
  257. -rm -rf installdir2/share/man
  258. -rm -rf installdir2/share/doc
  259. -rm -rf installdir2/share/openal
  260. $(TAR_OUTPUT): installdir/AppRun installdir/love.desktop installdir/love.svg installdir/license.txt appimagetool appimage-prepare
  261. cd installdir2; tar -cvzf ../$(TAR_OUTPUT) *
  262. $(APPIMAGE_OUTPUT): installdir/AppRun installdir/love.desktop installdir/love.svg installdir/license.txt appimagetool appimage-prepare
  263. ifeq ($(QEMU),)
  264. ./appimagetool installdir2 $(APPIMAGE_OUTPUT)
  265. else
  266. cd squashfs-root/usr/lib && ../../AppRun ../../../installdir2 ../../../$(APPIMAGE_OUTPUT)
  267. endif
  268. getdeps: $(CMAKE) appimagetool $(SDL2_PATH)/configure $(LIBOGG_FILE).tar.gz $(LIBVORBIS_FILE).tar.gz $(LIBTHEORA_FILE).tar.gz $(ZLIB_PATH)/configure $(LIBPNG_FILE).tar.gz $(BROTLI_PATH)/CMakeLists.txt $(BZIP2_FILE).tar.gz $(FT_PATH)/configure $(MPG123_FILE).tar.bz2 $(LIBMODPLUG_FILE).tar.gz $(LUAJIT_PATH)/Makefile $(LOVE_PATH)/CMakeLists.txt
  269. AppImage: $(APPIMAGE_OUTPUT)
  270. tar: $(TAR_OUTPUT)
  271. default: $(APPIMAGE_OUTPUT) $(TAR_OUTPUT)
  272. .DEFAULT_GOAL := default
  273. .PHONY := default getdeps cmake appimage-prepare AppImage tar dbgsym