common.mk 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #
  2. # meg4/platform/common.mk
  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 common Makefile for all platforms
  21. #
  22. # --- set these according to your configuration ---
  23. #DEBUG = 1
  24. # -------------------------------------------------
  25. TARGET ?= meg4
  26. SRCS = $(filter-out data.c,$(wildcard *.c))
  27. OBJS = $(SRCS:.c=.o)
  28. PREFIX ?= usr/
  29. INSTDIR=$(DESTDIR:/=)/$(PREFIX:/=)
  30. ARCH = $(shell uname -m)
  31. TMP = $(ARCH:x86_64=amd64)
  32. TMP2 = $(TMP:aarch64=arm64)
  33. DEBARCH = $(TMP2:armv7l=armhf)
  34. VERSION = $(shell cat ../../src/meg4.h|grep MEG4_VERSION|cut -d '"' -f 2)
  35. ifeq ($(USE_EMCC)$(USE_C99),)
  36. CFLAGS += -ansi -pedantic
  37. endif
  38. ifneq ($(USE_C99),)
  39. CFLAGS += --std=c99
  40. endif
  41. CFLAGS += -Wall -Wextra -Wno-pragmas -ffunction-sections -I../../src -DBUILD="$(shell date +"%Y%j")"
  42. ifneq ($(NOEDITORS),)
  43. CFLAGS += -Os -DNOEDITORS=1
  44. DEBUG =
  45. endif
  46. ifeq ($(DEBUG),)
  47. CFLAGS += -O3
  48. else
  49. CFLAGS += -g -DDEBUG=1
  50. endif
  51. ifneq ($(EMBED),)
  52. CFLAGS += -DEMBED=1
  53. endif
  54. ifeq ("$(PACKAGE)","Win")
  55. OBJS += resource.o
  56. endif
  57. all: libmeg4 $(TARGET)
  58. libmeg4:
  59. ifeq ($(USE_EMCC),)
  60. @make -C ../../src todo all DEBUG=$(DEBUG) EMBED=$(EMBED) NOEDITORS=$(NOEDITORS) NOLUA=$(NOLUA)
  61. else
  62. CC=emcc USE_EMCC=1 make -C ../../src all DEBUG=$(DEBUG) EMBED=$(EMBED) NOEDITORS=$(NOEDITORS) NOLUA=$(NOLUA)
  63. endif
  64. resource.o:
  65. windres -i ../../src/misc/resource.rc -o resource.o
  66. %: %.c
  67. $(CC) $(CFLAGS) $< -c $@
  68. $(TARGET): ../../src/libmeg4.a $(EXTRA) $(OBJS)
  69. ifeq ($(USE_EMCC),)
  70. $(CC) $(LDFLAGS) $(OBJS) ../../src/libmeg4.a -o $(TARGET) $(EXTRA) $(LIBS) -Wl,--gc-sections
  71. ifeq ($(DEBUG),)
  72. ifeq ("$(PACKAGE)","Win")
  73. @strip $(TARGET).exe
  74. else
  75. @strip $(TARGET)
  76. endif
  77. ifneq ($(NOEDITORS),)
  78. ifneq ($(wildcard ../../src/editors/pro.c),)
  79. @cc ../../src/bin2h.c -o bin2h
  80. ifeq ("$(PACKAGE)","Win")
  81. ./bin2h -o ../../src/editors/pro.exe $(TARGET).exe
  82. else
  83. ./bin2h -o ../../src/editors/pro.elf $(TARGET)
  84. endif
  85. @rm bin2h bin2h.exe 2>/dev/null || true
  86. endif
  87. endif
  88. endif
  89. endif
  90. install: $(TARGET)
  91. ifneq ("$(INSTDIR)","")
  92. @strip $(TARGET)
  93. install -m 755 -g bin $(TARGET) $(INSTDIR)/bin
  94. @mkdir -p $(INSTDIR)/share/man/man1 $(INSTDIR)/share/applications $(INSTDIR)/share/icons/hicolor/16x16/apps $(INSTDIR)/share/icons/hicolor/64x64/apps $(INSTDIR)/share/icons/hicolor/128x128/apps 2>/dev/null || true
  95. cp ../../src/misc/meg4.1.gz $(INSTDIR)/share/man/man1
  96. cp ../../src/misc/meg4.desktop $(INSTDIR)/share/applications
  97. cp ../../src/misc/logo16.png $(INSTDIR)/share/icons/hicolor/16x16/apps/meg4.png
  98. cp ../../src/misc/logo32.png $(INSTDIR)/share/icons/hicolor/32x32/apps/meg4.png
  99. cp ../../src/misc/logo64.png $(INSTDIR)/share/icons/hicolor/64x64/apps/meg4.png
  100. cp ../../src/misc/logo128.png $(INSTDIR)/share/icons/hicolor/128x128/apps/meg4.png
  101. else
  102. @echo "INSTDIR variable not set, not installing."
  103. @false
  104. endif
  105. package:
  106. ifeq ("$(TARGET)","meg4.js")
  107. @rm ../meg4-wasm-emscripten.zip 2>/dev/null || true
  108. @printf "<!DOCTYPE html>\n<html>\n <head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\">\n <title>MEG-4</title>\n <style>\nbody { text-align:center; vertical-align:middle; }\na { text-decoration:none; }\n#canvas { width:320px; height:200px; background:#444; }\n@media (min-width:768px){#canvas { width:640px; height:400px; }}\n@media (min-width:1024px){#canvas { width:960px; height:600px; }}\n@media (min-width:1500px){#canvas { width:1280px; height:800px; }}\n </style>\n </head>\n <body>\n <canvas id=\"canvas\"></canvas>\n <script src=\"meg4.js\"></script>\n <br><a href=\"https://bztsrc.gitlab.io/meg4\" target=\"new\">Visit MEG-4 website</a>\n </body>\n</html>\n" >index.html
  109. zip -r ../../meg4-wasm-emscripten.zip index.html meg4.js meg4.wasm
  110. @rm index.html
  111. else
  112. ifeq ("$(PACKAGE)","Linux")
  113. @strip $(TARGET)
  114. @mkdir -p bin share/man/man1 share/applications share/icons/hicolor/16x16/apps share/icons/hicolor/32x32/apps share/icons/hicolor/64x64/apps share/icons/hicolor/128x128/apps
  115. @cp $(TARGET) bin
  116. @cp ../../src/misc/meg4.1.gz share/man/man1
  117. @cp ../../src/misc/meg4.desktop share/applications
  118. @cp ../../src/misc/logo16.png share/icons/hicolor/16x16/apps/meg4.png
  119. @cp ../../src/misc/logo32.png share/icons/hicolor/32x32/apps/meg4.png
  120. @cp ../../src/misc/logo64.png share/icons/hicolor/64x64/apps/meg4.png
  121. @cp ../../src/misc/logo128.png share/icons/hicolor/128x128/apps/meg4.png
  122. tar -czvf ../../$(TARGET)-$(ARCH)-linux-$(BACKEND).tgz bin share
  123. @rm -rf bin share
  124. else
  125. ifeq ("$(PACKAGE)","Win")
  126. @strip $(TARGET).exe
  127. @mkdir MEG-4
  128. @cp $(TARGET).exe MEG-4/$(TARGET).exe
  129. @rm ../../$(TARGET)-i686-win-$(BACKEND).zip 2>/dev/null || true
  130. zip -r ../../$(TARGET)-i686-win-$(BACKEND).zip MEG-4
  131. @rm -rf MEG-4
  132. else
  133. ifeq ("$(PACKAGE)","MacOS")
  134. @strip $(TARGET)
  135. @mkdir MEG-4.app MEG-4.app/Contents MEG-4.app/Contents/MacOS MEG-4.app/Contents/Resources
  136. @cp $(TARGET) MEG-4.app/Contents/MacOS
  137. @cp ../../src/misc/meg4.icns MEG-4.app/Contents/Resources
  138. @rm ../../$(TARGET)-intel-macos-$(BACKEND).zip
  139. zip -r ../../$(TARGET)-intel-macos-$(BACKEND).zip MEG-4.app
  140. @rm -rf MEG-4.app
  141. else
  142. endif
  143. endif
  144. endif
  145. endif
  146. deb:
  147. ifeq ("$(PACKAGE)$(BACKEND)","Linuxsdl")
  148. @strip $(TARGET)
  149. @rm -rf DEBIAN usr 2>/dev/null || true
  150. @mkdir -p DEBIAN usr/bin usr/share/applications usr/share/man/man1 usr/share/icons/hicolor/16x16/apps usr/share/icons/hicolor/32x32/apps usr/share/icons/hicolor/64x64/apps usr/share/icons/hicolor/128x128/apps
  151. @cp $(TARGET) usr/bin
  152. @cp ../../src/misc/meg4.1.gz usr/share/man/man1
  153. @cp ../../src/misc/meg4.desktop usr/share/applications
  154. @cp ../../src/misc/logo16.png usr/share/icons/hicolor/16x16/apps/meg4.png
  155. @cp ../../src/misc/logo32.png usr/share/icons/hicolor/32x32/apps/meg4.png
  156. @cp ../../src/misc/logo64.png usr/share/icons/hicolor/64x64/apps/meg4.png
  157. @cp ../../src/misc/logo128.png usr/share/icons/hicolor/128x128/apps/meg4.png
  158. @cat ../../src/misc/deb_control | sed s/ARCH/$(DEBARCH)/g | sed s/VERSION/$(VERSION)/g | sed s/SIZE/`du -s usr|cut -f 1`/g >DEBIAN/control
  159. @md5sum `find usr -type f` >DEBIAN/md5sums
  160. @cp ../../LICENSE DEBIAN/copyright
  161. @echo "2.0" >debian-binary
  162. @tar -czvf data.tar.gz usr
  163. @tar -C DEBIAN -czvf control.tar.gz control copyright md5sums
  164. ar r ../../meg4_$(VERSION)-$(DEBARCH).deb debian-binary control.tar.gz data.tar.gz
  165. @rm -rf debian-binary control.tar.gz data.tar.gz DEBIAN usr
  166. else
  167. @echo "Only available under Linux with the SDL2 backend."
  168. @false
  169. endif
  170. clean:
  171. @rm $(TARGET) meg4.* *.o data.c data.h 2>/dev/null || true
  172. distclean: clean
  173. @make --no-print-directory -C ../../src distclean 2>/dev/null || true