Makefile 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. ##
  2. # MegaZeux Build System (GNU Make)
  3. #
  4. # NOTE: This build system was recently re-designed to not use recursive
  5. # Makefiles. The rationale for this is documented here:
  6. # http://aegis.sourceforge.net/auug97.pdf
  7. ##
  8. #
  9. # Remove all built-in rules.
  10. #
  11. .SUFFIXES:
  12. ifeq ($(filter -r,$(MAKEFLAGS)),)
  13. MAKEFLAGS += -r
  14. endif
  15. .PHONY: all clean help_check mzx mzx.debug build build_clean source
  16. -include platform.inc
  17. include version.inc
  18. all: mzx
  19. debuglink: all mzx.debug
  20. -include arch/${PLATFORM}/Makefile.in
  21. CC ?= gcc
  22. CXX ?= g++
  23. AR ?= ar
  24. STRIP ?= strip --strip-unneeded
  25. OBJCOPY ?= objcopy
  26. PEFIX ?= true
  27. CHMOD ?= chmod
  28. CP ?= cp
  29. HOST_CC ?= gcc
  30. LN ?= ln
  31. MKDIR ?= mkdir
  32. MV ?= mv
  33. RM ?= rm
  34. ifeq (${BUILD_LIBSDL2},)
  35. SDL_CFLAGS ?= $(shell sdl-config --cflags)
  36. SDL_LDFLAGS ?= $(shell sdl-config --libs)
  37. else
  38. SDL_CFLAGS ?= $(shell sdl2-config --cflags | sed 's,-I,-isystem ,g')
  39. SDL_LDFLAGS ?= $(shell sdl2-config --libs)
  40. endif
  41. VORBIS_CFLAGS ?= -I${PREFIX}/include -DOV_EXCLUDE_STATIC_CALLBACKS
  42. ifneq (${TREMOR},1)
  43. VORBIS_LDFLAGS ?= -L${PREFIX}/lib -lvorbisfile -lvorbis -logg
  44. else
  45. VORBIS_LDFLAGS ?= -L${PREFIX}/lib -lvorbisidec
  46. endif
  47. MIKMOD_CFLAGS ?= -I${PREFIX}/include
  48. MIKMOD_LDFLAGS ?= -L${PREFIX}/lib -lmikmod
  49. # Uncomment these when we don't need to contrib xmp.
  50. #XMP_CFLAGS ?= -I${PREFIX}/include
  51. #XMP_LDFLAGS ?= -L${PREFIX}/lib -lxmp
  52. OPENMPT_CFLAGS ?= -I${PREFIX}/include
  53. OPENMPT_LDFLAGS ?= -L${PREFIX}/lib -lopenmpt
  54. ZLIB_CFLAGS ?= -I${PREFIX}/include \
  55. -D_FILE_OFFSET_BITS=32 -U_LARGEFILE64_SOURCE
  56. ZLIB_LDFLAGS ?= -L${PREFIX}/lib -lz
  57. ifeq (${LIBPNG},1)
  58. LIBPNG_CFLAGS ?= $(shell libpng-config --cflags)
  59. LIBPNG_LDFLAGS ?= $(shell libpng-config --ldflags)
  60. endif
  61. PTHREAD_LDFLAGS ?= -lpthread
  62. OPTIMIZE_CFLAGS ?= -O3
  63. ifeq (${DEBUG},1)
  64. #
  65. # Disable the optimizer for "true" debug builds
  66. #
  67. CFLAGS = -O0 -DDEBUG
  68. CXXFLAGS = -O0 -DDEBUG
  69. else
  70. #
  71. # Optimized builds have assert() compiled out
  72. #
  73. CFLAGS += ${OPTIMIZE_CFLAGS} -DNDEBUG
  74. CXXFLAGS += ${OPTIMIZE_CFLAGS} -DNDEBUG
  75. endif
  76. #
  77. # Android headers are busted and we get too many warnings..
  78. #
  79. ifneq (${PLATFORM},android)
  80. CFLAGS += -Wundef -Wunused-macros
  81. CXXFLAGS += -Wundef -Wunused-macros
  82. endif
  83. #
  84. # Always generate debug information; this may end up being
  85. # stripped (on embedded platforms) or objcopy'ed out.
  86. #
  87. CFLAGS += -g -W -Wall -Wno-unused-parameter -std=gnu99
  88. CFLAGS += -Wdeclaration-after-statement ${ARCH_CFLAGS}
  89. CXXFLAGS += -g -W -Wall -Wno-unused-parameter -std=gnu++98
  90. CXXFLAGS += -fno-exceptions -fno-rtti ${ARCH_CXXFLAGS}
  91. LDFLAGS += ${ARCH_LDFLAGS}
  92. #
  93. # GCC version >= 4.x
  94. #
  95. GCC_VER_MAJOR := ${shell ${CC} -dumpversion | cut -d. -f1}
  96. GCC_VER_MAJOR_GE_4 := ${shell test $(GCC_VER_MAJOR) -ge 4; echo $$?}
  97. ifeq ($(GCC_VER_MAJOR_GE_4),0)
  98. ifeq (${DEBUG},1)
  99. CFLAGS += -fbounds-check
  100. CXXFLAGS += -fbounds-check
  101. endif
  102. #
  103. # We enable pedantic warnings here, but this ends up turning on some things
  104. # we must disable by hand.
  105. #
  106. # Variadic macros are arguably less portable, but all the compilers we
  107. # support have them.
  108. #
  109. ifneq (${PLATFORM},android)
  110. CFLAGS += -pedantic -Wno-variadic-macros
  111. CXXFLAGS += -pedantic -fpermissive -Wno-variadic-macros
  112. endif
  113. ifneq (${PLATFORM},mingw)
  114. #
  115. # Symbols in COFF binaries are implicitly hidden unless exported; this
  116. # flag just confuses GCC and must be disabled.
  117. #
  118. CFLAGS += -fvisibility=hidden
  119. CXXFLAGS += -fvisibility=hidden
  120. #
  121. # Skip the stack protector on embedded platforms; it just unnecessarily
  122. # slows things down, and there's no easy way to write a convincing
  123. # __stack_chk_fail function. MinGW may or may not have a __stack_chk_fail
  124. # function. Skip android, too.
  125. #
  126. ifeq ($(or ${BUILD_GP2X},${BUILD_NDS},${BUILD_3DS},${BUILD_PSP},${BUILD_WII}),)
  127. ifneq (${PLATFORM},android)
  128. CFLAGS += -fstack-protector-all
  129. CXXFLAGS += -fstack-protector-all
  130. endif
  131. endif
  132. endif
  133. endif
  134. #
  135. # Enable position-independent code across the board for modular builds.
  136. #
  137. ifeq (${BUILD_MODULAR},1)
  138. CFLAGS += -fPIC
  139. CXXFLAGS += -fPIC
  140. endif
  141. #
  142. # We don't want these commands to be echo'ed in non-verbose mode
  143. #
  144. ifneq (${V},1)
  145. override V:=
  146. CC := @${CC}
  147. CXX := @${CXX}
  148. AR := @${AR}
  149. STRIP := @${STRIP}
  150. OBJCOPY := @${OBJCOPY}
  151. PEFIX := @${PEFIX}
  152. CHMOD := @${CHMOD}
  153. CP := @${CP}
  154. HOST_CC := @${HOST_CC}
  155. LN := @${LN}
  156. MKDIR := @${MKDIR}
  157. MV := @${MV}
  158. RM := @${RM}
  159. endif
  160. build_clean:
  161. $(if ${V},,@echo " RM " build)
  162. ${RM} -r build
  163. source: build/${TARGET}src
  164. build/${TARGET}src:
  165. ${RM} -r build/${TARGET}
  166. ${MKDIR} -p build/dist/source
  167. @git checkout-index -a --prefix build/${TARGET}/
  168. ${RM} -r build/${TARGET}/scripts
  169. ${RM} build/${TARGET}/.gitignore build/${TARGET}/.gitattributes
  170. @cd build/${TARGET} && make distclean
  171. @tar -C build -Jcf build/dist/source/${TARGET}src.tar.xz ${TARGET}
  172. #
  173. # The SUPPRESS_BUILD hack is required to allow the placebo "dist"
  174. # Makefile to provide an 'all:' target, which allows it to print
  175. # a message. We don't want to pull in other targets, confusing Make.
  176. #
  177. ifneq (${SUPPRESS_BUILD},1)
  178. mzxrun = mzxrun${BINEXT}
  179. mzx = megazeux${BINEXT}
  180. mzx: ${mzxrun} ${mzx}
  181. mzx.debug: ${mzxrun}.debug ${mzx}.debug
  182. ifeq (${BUILD_MODPLUG},1)
  183. BUILD_GDM2S3M=1
  184. endif
  185. %/.build:
  186. $(if ${V},,@echo " MKDIR " $@)
  187. ${MKDIR} $@
  188. %.debug: %
  189. $(if ${V},,@echo " OBJCOPY " --only-keep-debug $< $@)
  190. ${OBJCOPY} --only-keep-debug $< $@
  191. ${PEFIX} $@
  192. ${CHMOD} a-x $@
  193. $(if ${V},,@echo " STRIP " $<)
  194. ${STRIP} $<
  195. $(if ${V},,@echo " OBJCOPY " --add-gnu-debuglink $@ $<)
  196. ${OBJCOPY} --add-gnu-debuglink=$@ $<
  197. ${PEFIX} $<
  198. @touch $@
  199. include src/Makefile.in
  200. clean: mzx_clean
  201. ifeq (${BUILD_UTILS},1)
  202. include src/utils/Makefile.in
  203. debuglink: utils utils.debug
  204. clean: utils_clean
  205. all: utils
  206. endif
  207. ifeq (${build},)
  208. build := build/${SUBPLATFORM}
  209. endif
  210. build: ${build}
  211. ${build}:
  212. ${MKDIR} -p ${build}/docs
  213. ${MKDIR} -p ${build}/assets
  214. ${CP} config.txt LICENSE ${build}
  215. ${CP} assets/default.chr assets/edit.chr ${build}/assets
  216. ${CP} assets/smzx.pal ${build}/assets
  217. ${CP} docs/macro.txt docs/keycodes.html ${build}/docs
  218. ${CP} docs/changelog.txt docs/platform_matrix.html ${build}/docs
  219. ${CP} ${mzxrun} ${build}
  220. @if test -f ${mzxrun}.debug; then \
  221. cp ${mzxrun}.debug ${build}; \
  222. fi
  223. ifeq (${BUILD_EDITOR},1)
  224. ${CP} assets/ascii.chr assets/blank.chr ${build}/assets
  225. ${CP} assets/smzx.chr ${build}/assets
  226. ${CP} ${mzx} ${build}
  227. @if test -f ${mzx}.debug; then \
  228. cp ${mzx}.debug ${build}; \
  229. fi
  230. endif
  231. ifeq (${BUILD_HELPSYS},1)
  232. ${CP} assets/help.fil ${build}/assets
  233. endif
  234. ifeq (${BUILD_MODULAR},1)
  235. ${CP} ${core_target} ${editor_target} ${build}
  236. @if test -f ${core_target}.debug; then \
  237. cp ${core_target}.debug ${build}; \
  238. fi
  239. @if test -f ${editor_target}.debug; then \
  240. cp ${editor_target}.debug ${build}; \
  241. fi
  242. endif
  243. ifeq (${BUILD_UTILS},1)
  244. ${MKDIR} ${build}/utils
  245. ${CP} ${checkres} ${downver} ${build}/utils
  246. ${CP} ${hlp2txt} ${txt2hlp} ${build}/utils
  247. ${CP} ${png2smzx} ${build}/utils
  248. ${CP} ${ccv} ${build}/utils
  249. @if test -f ${checkres}.debug; then \
  250. cp ${checkres}.debug ${downver}.debug ${build}/utils; \
  251. cp ${hlp2txt}.debug ${txt2hlp}.debug ${build}/utils; \
  252. cp ${png2smzx}.debug ${build}/utils; \
  253. fi
  254. endif
  255. ifeq (${BUILD_RENDER_GL_PROGRAM},1)
  256. ${MKDIR} -p ${build}/assets/shaders/scalers
  257. ${CP} assets/shaders/*.vert ${build}/assets/shaders
  258. ${CP} assets/shaders/*.frag ${build}/assets/shaders
  259. ${CP} assets/shaders/scalers/*.frag assets/shaders/scalers/*.vert \
  260. assets/shaders/scalers/README.txt ${build}/assets/shaders/scalers
  261. endif
  262. distclean: clean
  263. @echo " DISTCLEAN"
  264. @rm -f src/config.h
  265. @echo "PLATFORM=none" > platform.inc
  266. assets/help.fil: ${txt2hlp} docs/WIPHelp.txt
  267. @src/utils/txt2hlp docs/WIPHelp.txt $@
  268. help_check: ${hlp2txt} assets/help.fil
  269. @src/utils/hlp2txt assets/help.fil help.txt
  270. @echo @ >> help.txt
  271. @diff --strip-trailing-cr -q docs/WIPHelp.txt help.txt
  272. @rm -f help.txt
  273. endif