123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463 |
- ##
- # MegaZeux Build System (GNU Make)
- #
- # NOTE: This build system was recently re-designed to not use recursive
- # Makefiles. The rationale for this is documented here:
- # http://aegis.sourceforge.net/auug97.pdf
- ##
- #
- # Remove all built-in rules.
- #
- .SUFFIXES:
- ifeq ($(filter -r,$(MAKEFLAGS)),)
- MAKEFLAGS += -r
- endif
- .PHONY: all clean help_check test test_clean mzx mzx.debug build build_clean source
- -include platform.inc
- include version.inc
- all: mzx
- debuglink: all mzx.debug
- -include arch/${PLATFORM}/Makefile.in
- CC ?= gcc
- CXX ?= g++
- AR ?= ar
- STRIP ?= strip --strip-unneeded
- OBJCOPY ?= objcopy
- PEFIX ?= true
- CHMOD ?= chmod
- CP ?= cp
- HOST_CC ?= gcc
- LN ?= ln
- MKDIR ?= mkdir
- MV ?= mv
- RM ?= rm
- #
- # Set up CFLAGS/LDFLAGS for all MegaZeux external dependencies.
- #
- ifeq (${BUILD_SDL},1)
- #
- # SDL 2
- #
- ifneq (${BUILD_LIBSDL2},)
- # Check PREFIX for sdl2-config.
- ifneq ($(wildcard ${SDL_PREFIX}/bin/sdl2-config),)
- SDL_CONFIG := ${SDL_PREFIX}/bin/sdl2-config
- else ifneq ($(wildcard ${PREFIX}/bin/sdl2-config),)
- SDL_CONFIG := ${PREFIX}/bin/sdl2-config
- else
- SDL_CONFIG := sdl2-config
- endif
- SDL_PREFIX ?= $(shell ${SDL_CONFIG} --prefix)
- SDL_CFLAGS ?= $(shell ${SDL_CONFIG} --prefix=${SDL_PREFIX} --cflags | sed 's,-I,-isystem ,g')
- SDL_LDFLAGS ?= $(shell ${SDL_CONFIG} --prefix=${SDL_PREFIX} --libs)
- endif
- #
- # SDL 1.2
- #
- ifeq (${BUILD_LIBSDL2},)
- # Check PREFIX for sdl-config.
- ifneq ($(wildcard ${SDL_PREFIX}/bin/sdl-config),)
- SDL_CONFIG := ${SDL_PREFIX}/bin/sdl-config
- else ifneq ($(wildcard ${PREFIX}/bin/sdl-config),)
- SDL_CONFIG := ${PREFIX}/bin/sdl-config
- else
- SDL_CONFIG := sdl-config
- endif
- SDL_PREFIX ?= $(shell ${SDL_CONFIG} --prefix)
- SDL_CFLAGS ?= $(shell ${SDL_CONFIG} --prefix=${SDL_PREFIX} --cflags)
- SDL_LDFLAGS ?= $(shell ${SDL_CONFIG} --prefix=${SDL_PREFIX} --libs)
- endif
- # Make these immediate so the scripts run only once.
- SDL_PREFIX := $(SDL_PREFIX)
- SDL_CFLAGS := $(SDL_CFLAGS)
- SDL_LDFLAGS := $(LINK_DYNAMIC_IF_MIXED) $(SDL_LDFLAGS)
- endif
- #
- # libvorbis/tremor
- #
- VORBIS_CFLAGS ?= -I${PREFIX}/include -DOV_EXCLUDE_STATIC_CALLBACKS
- ifeq (${VORBIS},vorbis)
- VORBIS_LDFLAGS ?= $(LINK_STATIC_IF_MIXED) -L${PREFIX}/lib -lvorbisfile -lvorbis -logg
- else ifeq (${VORBIS},tremor)
- VORBIS_LDFLAGS ?= $(LINK_STATIC_IF_MIXED) -L${PREFIX}/lib -lvorbisidec -logg
- else ifeq (${VORBIS},tremor-lowmem)
- VORBIS_LDFLAGS ?= $(LINK_STATIC_IF_MIXED) -L${PREFIX}/lib -lvorbisidec
- endif
- #
- # MikMod (optional mod engine)
- #
- MIKMOD_CFLAGS ?= -I${PREFIX}/include
- MIKMOD_LDFLAGS ?= $(LINK_STATIC_IF_MIXED) -L${PREFIX}/lib -lmikmod
- #
- # libopenmpt (optional mod engine)
- #
- OPENMPT_CFLAGS ?= -I${PREFIX}/include
- OPENMPT_LDFLAGS ?= $(LINK_STATIC_IF_MIXED) -L${PREFIX}/lib -lopenmpt
- #
- # zlib
- #
- ZLIB_CFLAGS ?= -I${PREFIX}/include \
- -D_FILE_OFFSET_BITS=32 -U_LARGEFILE64_SOURCE
- ZLIB_LDFLAGS ?= $(LINK_STATIC_IF_MIXED) -L${PREFIX}/lib -lz
- #
- # libpng
- #
- ifeq (${LIBPNG},1)
- # Check PREFIX for libpng-config.
- ifneq ($(wildcard ${PREFIX}/bin/libpng-config),)
- LIBPNG_CONFIG := ${PREFIX}/bin/libpng-config
- else
- LIBPNG_CONFIG := libpng-config
- endif
- LIBPNG_CFLAGS ?= $(shell ${LIBPNG_CONFIG} --cflags)
- LIBPNG_LDFLAGS ?= $(shell ${LIBPNG_CONFIG} --ldflags)
- # Make these immediate so the scripts run only once.
- LIBPNG_CFLAGS := $(LIBPNG_CFLAGS)
- LIBPNG_LDFLAGS := $(LINK_STATIC_IF_MIXED) $(LIBPNG_LDFLAGS)
- endif
- #
- # X11
- #
- ifneq (${X11DIR},)
- X11_CFLAGS ?= -I${X11DIR}/../include
- X11_LDFLAGS ?= -L${X11DIR}/../lib -lX11
- # Make these immediate
- X11_CFLAGS := $(X11_CFLAGS)
- X11_LDFLAGS := $(X11_LDFLAGS)
- endif
- #
- # pthread
- #
- PTHREAD_LDFLAGS ?= -lpthread
- #
- # Set up general CFLAGS/LDFLAGS
- #
- OPTIMIZE_CFLAGS ?= -O3
- ifeq (${DEBUG},1)
- #
- # Disable the optimizer for "true" debug builds
- #
- CFLAGS = -O0 -DDEBUG
- CXXFLAGS = -O0 -DDEBUG
- else
- #
- # Optimized builds have assert() compiled out
- #
- CFLAGS += ${OPTIMIZE_CFLAGS} -DNDEBUG
- CXXFLAGS += ${OPTIMIZE_CFLAGS} -DNDEBUG
- endif
- #
- # Android headers are busted and we get too many warnings..
- #
- ifneq (${PLATFORM},android)
- CFLAGS += -Wundef -Wunused-macros
- CXXFLAGS += -Wundef -Wunused-macros
- endif
- #
- # Always generate debug information; this may end up being
- # stripped (on embedded platforms) or objcopy'ed out.
- #
- CFLAGS += -g -W -Wall -Wno-unused-parameter -std=gnu99
- CFLAGS += -Wdeclaration-after-statement ${ARCH_CFLAGS}
- CXXFLAGS += -g -W -Wall -Wno-unused-parameter -std=gnu++98
- CXXFLAGS += -fno-exceptions -fno-rtti ${ARCH_CXXFLAGS}
- LDFLAGS += ${ARCH_LDFLAGS}
- #
- # GCC version >= 7.x
- #
- GCC_VER := ${shell ${CC} -dumpversion}
- GCC_VER_MAJOR := ${shell ${CC} -dumpversion | cut -d. -f1}
- GCC_VER_MAJOR_GE_7 := ${shell test $(GCC_VER_MAJOR) -ge 7; echo $$?}
- ifeq ($(GCC_VER_MAJOR_GE_7),0)
- # This gives spurious warnings on Linux. The snprintf implementation on Linux
- # will terminate even in the case of truncation, making this largely useless.
- # It does not trigger using mingw, where it would actually matter.
- CFLAGS += -Wno-format-truncation
- endif
- #
- # GCC version >= 4.x
- #
- GCC_VER_MAJOR_GE_4 := ${shell test $(GCC_VER_MAJOR) -ge 4; echo $$?}
- ifeq ($(GCC_VER_MAJOR_GE_4),0)
- ifeq (${DEBUG},1)
- ifneq (${GCC_VER},4.2.1)
- CFLAGS += -fbounds-check
- CXXFLAGS += -fbounds-check
- endif
- endif
- #
- # We enable pedantic warnings here, but this ends up turning on some things
- # we must disable by hand.
- #
- # Variadic macros are arguably less portable, but all the compilers we
- # support have them.
- #
- ifneq (${PLATFORM},android)
- CFLAGS += -pedantic -Wno-variadic-macros
- CXXFLAGS += -pedantic -fpermissive -Wno-variadic-macros
- endif
- ifneq (${PLATFORM},mingw)
- #
- # Symbols in COFF binaries are implicitly hidden unless exported; this
- # flag just confuses GCC and must be disabled.
- #
- CFLAGS += -fvisibility=hidden
- CXXFLAGS += -fvisibility=hidden
- #
- # Skip the stack protector on embedded platforms; it just unnecessarily
- # slows things down, and there's no easy way to write a convincing
- # __stack_chk_fail function. MinGW may or may not have a __stack_chk_fail
- # function. Skip android, too.
- #
- ifeq ($(or ${BUILD_GP2X},${BUILD_NDS},${BUILD_3DS},${BUILD_PSP},${BUILD_WII}),)
- ifneq (${PLATFORM},android)
- CFLAGS += -fstack-protector-all
- CXXFLAGS += -fstack-protector-all
- endif
- endif
- endif
- endif
- #
- # Enable position-independent code across the board for modular builds.
- #
- ifeq (${BUILD_MODULAR},1)
- CFLAGS += -fPIC
- CXXFLAGS += -fPIC
- endif
- #
- # We don't want these commands to be echo'ed in non-verbose mode
- #
- ifneq (${V},1)
- override V:=
- CC := @${CC}
- CXX := @${CXX}
- AR := @${AR}
- STRIP := @${STRIP}
- OBJCOPY := @${OBJCOPY}
- PEFIX := @${PEFIX}
- CHMOD := @${CHMOD}
- CP := @${CP}
- HOST_CC := @${HOST_CC}
- LN := @${LN}
- MKDIR := @${MKDIR}
- MV := @${MV}
- RM := @${RM}
- endif
- build_clean:
- $(if ${V},,@echo " RM " build)
- ${RM} -r build
- source: build/${TARGET}src
- #
- # Build source target
- # Targetting unix primarily, so turn off autocrlf if necessary
- #
- ifneq ($(shell which git),)
- USER_AUTOCRLF=$(shell git config core.autocrlf)
- endif
- build/${TARGET}src:
- ${RM} -r build/${TARGET}
- ${MKDIR} -p build/dist/source
- @git config core.autocrlf false
- @git checkout-index -a --prefix build/${TARGET}/
- @git config core.autocrlf ${USER_AUTOCRLF}
- ${RM} -r build/${TARGET}/scripts
- ${RM} build/${TARGET}/.gitignore build/${TARGET}/.gitattributes
- @cd build/${TARGET} && make distclean
- @tar -C build -Jcf build/dist/source/${TARGET}src.tar.xz ${TARGET}
- #
- # The SUPPRESS_BUILD hack is required to allow the placebo "dist"
- # Makefile to provide an 'all:' target, which allows it to print
- # a message. We don't want to pull in other targets, confusing Make.
- #
- ifneq (${SUPPRESS_BUILD},1)
- mzxrun = mzxrun${BINEXT}
- mzx = megazeux${BINEXT}
- mzx: ${mzxrun} ${mzx}
- mzx.debug: ${mzxrun}.debug ${mzx}.debug
- ifeq (${BUILD_MODPLUG},1)
- BUILD_GDM2S3M=1
- endif
- %/.build:
- $(if ${V},,@echo " MKDIR " $@)
- ${MKDIR} $@
- %.debug: %
- $(if ${V},,@echo " OBJCOPY " --only-keep-debug $< $@)
- ${OBJCOPY} --only-keep-debug $< $@
- ${PEFIX} $@
- ${CHMOD} a-x $@
- $(if ${V},,@echo " STRIP " $<)
- ${STRIP} $<
- $(if ${V},,@echo " OBJCOPY " --add-gnu-debuglink $@ $<)
- ${OBJCOPY} --add-gnu-debuglink=$@ $<
- ${PEFIX} $<
- @touch $@
- include src/Makefile.in
- clean: mzx_clean test_clean
- ifeq (${BUILD_UTILS},1)
- include src/utils/Makefile.in
- debuglink: utils utils.debug
- clean: utils_clean
- all: utils
- endif
- ifeq (${build},)
- build := build/${SUBPLATFORM}
- endif
- build: ${build}
- ${build}:
- ${MKDIR} -p ${build}/docs
- ${MKDIR} -p ${build}/assets
- ${CP} config.txt LICENSE ${build}
- ${CP} assets/default.chr assets/edit.chr ${build}/assets
- ${CP} assets/smzx.pal ${build}/assets
- ${CP} docs/macro.txt docs/keycodes.html docs/mzxhelp.html ${build}/docs
- ${CP} docs/changelog.txt docs/platform_matrix.html ${build}/docs
- ${CP} ${mzxrun} ${build}
- @if test -f ${mzxrun}.debug; then \
- cp ${mzxrun}.debug ${build}; \
- fi
- ifeq (${BUILD_EDITOR},1)
- ${CP} assets/ascii.chr assets/blank.chr ${build}/assets
- ${CP} assets/smzx.chr ${build}/assets
- ${CP} ${mzx} ${build}
- @if test -f ${mzx}.debug; then \
- cp ${mzx}.debug ${build}; \
- fi
- endif
- ifeq (${BUILD_HELPSYS},1)
- ${CP} assets/help.fil ${build}/assets
- endif
- ifeq (${BUILD_MODULAR},1)
- ${CP} ${core_target} ${editor_target} ${build}
- @if test -f ${core_target}.debug; then \
- cp ${core_target}.debug ${build}; \
- fi
- @if test -f ${editor_target}.debug; then \
- cp ${editor_target}.debug ${build}; \
- fi
- endif
- ifeq (${BUILD_UTILS},1)
- ${MKDIR} ${build}/utils
- ${CP} ${checkres} ${downver} ${build}/utils
- ${CP} ${hlp2txt} ${txt2hlp} ${build}/utils
- ifeq (${LIBPNG},1)
- ${CP} ${png2smzx} ${build}/utils
- endif
- ${CP} ${ccv} ${build}/utils
- @if test -f ${checkres}.debug; then \
- cp ${checkres}.debug ${downver}.debug ${build}/utils; \
- cp ${hlp2txt}.debug ${txt2hlp}.debug ${build}/utils; \
- cp ${png2smzx}.debug ${build}/utils; \
- fi
- endif
- ifeq (${BUILD_RENDER_GL_PROGRAM},1)
- ${MKDIR} -p ${build}/assets/glsl/scalers
- ${CP} assets/glsl/*.vert ${build}/assets/glsl
- ${CP} assets/glsl/*.frag ${build}/assets/glsl
- ${CP} assets/glsl/README.md ${build}/assets/glsl
- ${CP} assets/glsl/scalers/*.frag assets/glsl/scalers/*.vert \
- ${build}/assets/glsl/scalers
- endif
- ifeq (${BUILD_GAMECONTROLLERDB},1)
- ${CP} assets/gamecontrollerdb.txt assets/gamecontrollerdb.LICENSE \
- ${build}/assets
- endif
- distclean: clean
- @echo " DISTCLEAN"
- @rm -f src/config.h
- @echo "PLATFORM=none" > platform.inc
- assets/help.fil: ${txt2hlp} docs/WIPHelp.txt
- $(if ${V},,@echo " txt2hlp " $@)
- @src/utils/txt2hlp docs/WIPHelp.txt $@
- docs/mzxhelp.html: ${hlp2html} docs/WIPHelp.txt
- $(if ${V},,@echo " hlp2html" $@)
- @src/utils/hlp2html docs/WIPHelp.txt docs/mzxhelp.html
- help_check: ${hlp2txt} assets/help.fil
- @src/utils/hlp2txt assets/help.fil help.txt
- @echo @ >> help.txt
- @diff --strip-trailing-cr -q docs/WIPHelp.txt help.txt
- @rm -f help.txt
- test:
- @testworlds/run.sh @{PLATFORM} @{LIBDIR}
- test_clean:
- @rm -rf testworlds/log
- endif
|