From 223d700a43365adb5da57f535b76d49644bf8e29 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Wed, 23 Nov 2016 18:48:33 -0800 Subject: [PATCH] Add a Makefile for building and installing --- .gitignore | 59 +++++-------- Makefile | 215 ++++++++++++++++++++++++++++++++++++++++++++++++ congfx.pp | 4 + dist/.gitignore | 7 ++ 4 files changed, 246 insertions(+), 39 deletions(-) create mode 100644 Makefile create mode 100644 dist/.gitignore diff --git a/.gitignore b/.gitignore index 3b64a1e..19ecbcf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,45 +1,26 @@ -*.py[cod] +# Generated by `make` *.o *.ppu -SaveGame/ -arena + gharena cosplay xxran *.exe -*.dll - -# C extensions -*.so - -# Packages -*.egg -*.egg-info -dist -build -eggs -parts -bin -var -sdist -develop-eggs -.installed.cfg -lib -lib64 - -# Installer logs -pip-log.txt - -# Unit test / coverage reports -.coverage -.tox -nosetests.xml - -# Translations -*.mo - -# Mr Developer -.mr.developer.cfg -.project -.pydevproject -*.bak + +crt.pp +crth.inc + + +# Generated by `make dist` and `make bindist` +#See dist/.gitignore + + +# Generated by running the game +SaveGame/ + + +# Editor files, being personal to you, do not belong in this file. +# Instead, add them to one of: +# $XDG_CONFIG_HOME/git/ignore (if XDG_CONFIG_HOME is set) +# $HOME/.config/git/ignore (if XDG_CONFIG_HOME is not set) +# $GIT_DIR/info/exclude (where $GIT_DIR is usually .git, unless it is a file) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4844d60 --- /dev/null +++ b/Makefile @@ -0,0 +1,215 @@ +# This is a Makefile, useful for compiling GearHead on Unix platforms. + +### CONFIGURATION +# Instead of editing this file, you can create a file named `local.make` +# or pass them on the command-line. + +# TODO use `fpcmake`? + +ENABLE_SDLMODE=no +ENABLE_XTERM_BOXDRAWING=yes + +# Compiler and flags. +FPC = fpc +FPCFLAGS = -g -O2 -XD -vr +PPDEP = ppdep +PPDEPFLAGS = + +# Used for tarballs. Cross-compiling is a little more complicated. +FPC_ARCH := $(shell ${FPC} ${FPCFLAGS} -iTP) +FPC_OS := $(shell ${FPC} ${FPCFLAGS} -iTO) +# Used when applying the xterm-boxdrawing patch. +FPC_VERSION := $(shell ${FPC} ${FPCFLAGS} -iV) +FPC_SOURCE := /usr/share/fpcsrc/${FPC_VERSION}/ + +SRC_MAIN = gharena +ifeq '${ENABLE_SDLMODE}' 'yes' +# Allow co-installation, though note they do still have to be built from +# separate source directories. +# TODO allow out-of-tree builds. +BIN_MAIN = gearhead-sdl +else +BIN_MAIN = gearhead +endif +PACKAGE = ${BIN_MAIN} +PACKAGE_VERSION := $(shell if test -e .git; then git describe --dirty; else sed -n "s/^\s*Version = '\(.*\)';\r\?$$/\1/; T; p" gharena.pas; fi) + +# Name of tarballs/zips for distribution, excluding extension. +SRC_TARBALL=${PACKAGE}-${PACKAGE_VERSION}-src +BIN_TARBALL=${PACKAGE}-${PACKAGE_VERSION}-${FPC_ARCH}-${FPC_OS} + +# Prefix used for installation. Useful for making tarballs. +DISTDIR = + +PREFIX = /usr/local +EPREFIX = ${PREFIX} +BINDIR = ${EPREFIX}/games +DATAROOTDIR = ${PREFIX}/share +DATADIR = ${DATAROOTDIR}/games +DOCDIR = ${PREFIX}/doc/${PACKAGE} + +ALL_MAIN := $(patsubst %.pas,%,$(wildcard *.pas)) + +.DEFAULT_GOAL = all + +# Other autoconf directories not needed. + +-include local.make + +############################################################ +### No user-servicable parts beyond this point. ### +############################################################ + +### OVERRIDES + +ifeq '${ENABLE_SDLMODE}' 'yes' +override FPCFLAGS += -dSDLMODE +override PPDEPFLAGS += -dSDLMODE +ENABLE_XTERM_BOXDRAWING = no +else +ALL_MAIN := $(filter-out cosplay,${ALL_MAIN}) +endif + +ifeq '${ENABLE_XTERM_BOXDRAWING}' 'yes' +${ALL_MAIN}: maint-apply-xterm-boxdrawing +override FPCFLAGS += -dXTERM_BOXDRAWING +override PPDEPFLAGS += -dXTERM_BOXDRAWING +else +${ALL_MAIN}: maint-unapply-xterm-boxdrawing +endif + + +### RULES +# TODO use `ppdep` once it is no longer buggy and/or we apply the workaround. +.PHONY: all +all: ${ALL_MAIN} +.PHONY: clean +clean: + rm -f ${ALL_MAIN} *.o *.ppu +.PHONY: distclean +distclean: clean +distclean: maint-unapply-xterm-boxdrawing +%: %.pas + ${FPC} ${FPCFLAGS} $@ + +### CHECK +.PHONY: test +test: check +.PHONY: check +check: all + +### INSTALL +# Since `install` is (often) run as root, it must *not* depend on `all` +# (or anything else that might write a file outside of DESTDIR) +# Also note: we must *not* glob too aggressively, to avoid picking up +# backup files. +.PHONY: install +install: install-bin install-data install-doc +.PHONY: install-bin +install-bin: + install -d ${DESTDIR}${BINDIR} + install -T ${SRC_MAIN} ${DESTDIR}${BINDIR}/${BIN_MAIN} +.PHONY: install-data +install-data: + install -d ${DESTDIR}${DATADIR}/${PACKAGE}/Design + install -m 0644 Design/*.txt ${DESTDIR}${DATADIR}/${PACKAGE}/Design/ + install -d ${DESTDIR}${DATADIR}/${PACKAGE}/GameData + install -m 0644 GameData/*.txt ${DESTDIR}${DATADIR}/${PACKAGE}/GameData/ + install -d ${DESTDIR}${DATADIR}/${PACKAGE}/Image + install -m 0644 Image/*.png ${DESTDIR}${DATADIR}/${PACKAGE}/Image/ + install -m 0644 Image/*.ttf ${DESTDIR}${DATADIR}/${PACKAGE}/Image/ + install -m 0644 Image/*.txt ${DESTDIR}${DATADIR}/${PACKAGE}/Image/ + install -d ${DESTDIR}${DATADIR}/${PACKAGE}/Series + install -m 0644 Series/*.txt ${DESTDIR}${DATADIR}/${PACKAGE}/Series/ +.PHONY: install-doc +install-doc: + install -d ${DESTDIR}${DOCDIR} + install -m 0664 *.md ${DESTDIR}${DOCDIR}/ + install -m 0664 *.txt ${DESTDIR}${DOCDIR}/ + install -m 0664 doc/*.txt ${DESTDIR}${DOCDIR}/ + install -d ${DESTDIR}${DOCDIR}/contrib + install -m 0664 contrib/*.png ${DESTDIR}${DOCDIR}/contrib/ + install -m 0664 contrib/*.sh ${DESTDIR}${DOCDIR}/contrib/ + +### DISTRIBUTION +# Manually list everything from `git ls-files`, without relying on git. +# The fact that `make dist` can be called from within its own output is +# an important sanity check. +.PHONY: dist-temp-destdir/${SRC_TARBALL} +dist/tmp-destdir/${SRC_TARBALL}: + rm -rf $@ + mkdir -p $@ + cp -t $@ -a .gitignore *.inc *.md *.pas *.pp *.txt + mkdir -p $@/Design + cp -t $@/Design Design/*.txt + mkdir -p $@/GameData + cp -t $@/GameData GameData/*.txt + mkdir -p $@/Image + cp -t $@/Image Image/*.png Image/*.ttf Image/*.txt + mkdir -p $@/Series + cp -t $@/Series Series/*.txt + mkdir -p $@/contrib + cp -t $@/contrib contrib/*.png contrib/*.sh + mkdir -p $@/dist + cp -t $@/dist dist/.gitignore + mkdir -p $@/doc + cp -t $@/doc doc/*.txt + mkdir -p $@/boxdrawing + cp -t $@/boxdrawing xterm-boxdrawing/README xterm-boxdrawing/*.diff xterm-boxdrawing/*.inc +.PHONY: dist +dist: dist/${SRC_TARBALL}.zip +dist: dist/${SRC_TARBALL}.tar.gz +dist: dist/${SRC_TARBALL}.tar.bz2 +dist: dist/${SRC_TARBALL}.tar.xz +dist: + rm -r dist/tmp-destdir/${SRC_TARBALL} + rm dist/${SRC_TARBALL}.tar +.PHONY: dist/tmp-destdir/${BIN_TARBALL} +dist/tmp-destdir/${BIN_TARBALL}: + rm -rf $@ + ${MAKE} all + ${MAKE} install DESTDIR=$@ +.PHONY: bindist +bindist: dist/${BIN_TARBALL}.zip +bindist: dist/${BIN_TARBALL}.tar.gz +bindist: dist/${BIN_TARBALL}.tar.bz2 +bindist: dist/${BIN_TARBALL}.tar.xz +bindist: all + rm -r dist/tmp-destdir/${BIN_TARBALL} + rm dist/${BIN_TARBALL}.tar + +dist/%.tar: dist/tmp-destdir/% + rm -f $@ + (cd ./dist/tmp-destdir && tar cf ../$*.tar $*) +dist/%.zip: dist/tmp-destdir/% + rm -f $@ + (cd ./dist/tmp-destdir && zip -q -r ../$*.zip $*) +dist/%.tar.gz: dist/%.tar + gzip -n < $< > $@ +dist/%.tar.bz2: dist/%.tar + bzip2 < $< > $@ +dist/%.tar.xz: dist/%.tar + xz < $< > $@ + +# Call this during development if something went wrong previously. +.PHONY: maint-undist +maint-undist: + rm -f dist/${SRC_TARBALL}.zip dist/${SRC_TARBALL}.tar.* + rm -f dist/${BIN_TARBALL}.zip dist/${BIN_TARBALL}.tar.* +.PHONY: maint-apply-xterm-boxdrawing +maint-apply-xterm-boxdrawing: + cp ${FPC_SOURCE}/packages/rtl-console/src/unix/crt.pp ./ + cp ${FPC_SOURCE}/packages/rtl-console/src/inc/crth.inc ./ + patch ./crt.pp < xterm-boxdrawing/crt.pp.diff + +.PHONY: maint-unapply-xterm-boxdrawing +maint-unapply-xterm-boxdrawing: + rm -f ./crt.pp ./crth.inc + +# Table of contents: +### CONFIGURATION +### OVERRIDES +### RULES +### CHECK +### INSTALL +### DISTRIBUTION diff --git a/congfx.pp b/congfx.pp index 2e8a58a..7941169 100644 --- a/congfx.pp +++ b/congfx.pp @@ -145,7 +145,11 @@ implementation uses ui4gh; +{$IFDEF XTERM_BOXDRAWING} +{$I xterm-boxdrawing/boxdraw.inc} +{$ELSE} {$I boxdraw.inc} +{$ENDIF} Procedure ClipZone( ZoneNumber: Integer ); { Set the clipping bounds to this defined zone. } diff --git a/dist/.gitignore b/dist/.gitignore new file mode 100644 index 0000000..e064885 --- /dev/null +++ b/dist/.gitignore @@ -0,0 +1,7 @@ +# Deliberately do *not* ignore all of dist/, so that if something went +# wrong, it remains visible. + +*.zip +*.tar.gz +*.tar.bz2 +*.tar.xz