# This Makefile requires GNU make.

# If you get strange errors about `missing conditional' when
# running make, try `gmake' instead of `make'.

# DO NOT edit this file unless you're a z26 developer. All the
# configuration is done via an included config.mak.

# If you can't get any of the existing targets to build, instead of
# editing this file, you run `make custom', then edit config.mak.

# If you're able to get the program to compile and run successfully
# by changing config.mak, please send the authors a copy of it, along
# with the name of your operating system, so we can add it to the
# next release.

sinclude config.mak

# This is a sneaky way to have my cake and eat it too.

# The first time you run `make' after extracting the tarball, it will
# tell you to run e.g. `make windows' or `make linux'.

# The next time, you just run `make' to build the same target as you
# did last time.

# This is done by copying `config_$target.mak' to `config.mak'
# if it doesn't already exist (which it won't, the first time),
# or else using the existing config.mak if present.



ifeq ($(CONFIG), )
all:
	@echo "Targets are:" ; \
	echo ; \
	echo "	windows"; \
	echo "	linux"; \
	echo "	linux-static"; \
	echo "	freebsd"; \
	echo "	netbsd"; \
	echo "	beos"; \
	echo "	generic-unix"; \
	echo "	custom (if you've created config_custom.mak)"; \
	echo ; \
	echo "There may be other targets for use by the z26 developers."
else
all:
	@echo "Building for $(CONFIG)"
	$(MAKE) $(EXE)
endif

ifeq ($(C_CORE), )
Z26_VERSION=2.13-X86_CORE
else
Z26_VERSION=2.13-C_CORE
endif

linux_gui:
	cp conf/config_linux_gui.mak config.mak
	$(MAKE) clean all

linux:
	cp conf/config_linux.mak config.mak
	$(MAKE) clean all

linux-static:
	cp conf/config_linux-static.mak config.mak
	$(MAKE) clean all

freebsd:
	cp conf/config_freebsd.mak config.mak
	$(MAKE) clean all

netbsd:
	cp conf/config_netbsd.mak config.mak
	$(MAKE) clean all

beos:
	cp conf/config_beos.mak config.mak
	$(MAKE) clean all

generic-unix:
	cp conf/config_generic-unix.mak config.mak
	$(MAKE) clean all

windows:
	cp conf/config_windows.mak config.mak
	$(MAKE) clean all

custom:
	cp conf/config_custom.mak config.mak
	$(MAKE) clean all

es:
	cp conf/config_es.mak config.mak
	$(MAKE) clean all



### No user-serviceable parts below (unless you know what you're doing!)

ifneq ($(CONFIG), )
# make sure everything's set:



ifeq ($(NASM), )
$(warning You didn't set NASM, using default)
NASM=nasm
endif

ifeq ($(NASMFLAGS), )
$(warning You didn't set NASMFLAGS, using default)
NASMFLAGS=-f elf
endif

ifeq ($(CC), )
$(warning You didn't set CC, using default)
CC=gcc
endif

# no defaults for SDLLIBS, SDLCFLAGS, CFLAGS, Z26OPTS
# This is reasonable for CFLAGS and Z26OPTS.

ifeq ($(SDLCFLAGS), )
$(warning You didn't set SDLCFLAGS, and there is no default.)
endif

ifeq ($(SDLLIBS), )
$(warning You didn't set SDLLIBS, and there is no default.)
endif

ifeq ($(INSTALL_TARGET), )
INSTALL_TARGET=install.unix
endif

ifeq ($(DOCTYPE), )
DOCTYPE=docs.unix
endif

ifeq ($(INSTALL_USER), )
INSTALL_USER=root
endif

ifeq ($(INSTALL_GROUP), )
INSTALL_GROUP=root
endif

ifeq ($(INSTALL_BINDIR), )
INSTALL_BINDIR=/usr/local/bin
endif

ifeq ($(INSTALL_MANDIR), )
INSTALL_MANDIR=/usr/local/man/man1
endif

# Most platforms use this:
z26: z26.o z26core.o
	$(CC) z26.o z26core.o $(SDLLIBS) -o z26 
	strip z26


# Windows uses this (and so will OS/2 if we ever support it):
z26.exe: z26.o z26core.o
	$(CC) z26.o z26core.o $(SDLLIBS) -o z26 
	strip z26.exe


# linux-static uses this:
z26-static: z26.o z26core.o
	$(CC) z26.o z26core.o -Wl,-static $(SDLLIBS) -o z26-static
	strip z26-static


z26.o: z26.h chkconfig.h bintoasm.c carts.c cli.c controls.c ct.c \
	genclr.c globals.c kidvid.c mt.c palette.c pcx.c \
	pixcopy.c sdlsrv.c text.c trace.c tracex.c winsrv.c z26.c \
	c_core.c usage.h conf/c_core.mak
	$(CC) -Wall -DZ26_VERSION=\"$(Z26_VERSION)\" $(Z26OPTS) $(C_CORE) $(CFLAGS) -DLOCK_AUDIO_SQ $(SDLCFLAGS) -c z26.c

z26core.o: banks.asm cpu.asm cpuhand.asm cpujam.asm defs.asm \
	extern.asm head.asm init.asm lincopy.asm main.asm pitfall2.asm \
	position.asm riot.asm service.asm soundq.asm starpath.asm \
	tail.asm tialine.asm tiasnd.asm tiatab.asm tiawrite.asm \
	trace.asm z26core.asm conf/c_core.mak
	$(NASM) $(NASMFLAGS) $(C_CORE) -DLOCK_AUDIO_SQ -o z26core.o z26core.asm

pixcopy.c: pixcopy.m4
	m4 pixcopy.m4 > pixcopy.c

docs.all: README.TXT z26.man doc/z26.pdf

docs.win: README.TXT doc/z26.pdf

docs.unix: docs.all

docs.minimal: README.TXT

docs: $(DOCTYPE)

# The docs are written in POD, which comes with the Perl distribution.
# This allows us to generate README.TXT, z26.pdf, and the UNIX
# man page z26.man from a single source.

# pod2man and pod2text should be present if you have perl installed.
# Worst case scenario: read the raw POD in a text editor. It's designed
# to be easy to read.

# If you want to edit the docs, edit the POD source, not the README.TXT
# or PDF versions.

z26.man: z26.pod
	pod2man -c 'z26 Documentation' -r 'z26 Pre-release' z26.pod > z26.man || echo "perl or pod2man missing - not building manual"

README.TXT: z26.pod
	@perl perl/pod2text z26.pod > README.TXT || echo "perl or pod2text missing - not building README.TXT"

# ps2pdf comes with GNU Ghostscript.
# PDF documentation is optional, you don't *need* it.

# old way of generating PDF, superseded by pod2pdf
## z26.pdf: z26.man
## 	man -t ./z26.man > z26.ps
## 	ps2pdf z26.ps z26.pdf
## 	rm -f z26.ps

# We use a modified version of Pod::Pdf module. -I./perl tells
# perl to look in our directory first, to find modules.
doc/z26.pdf: z26.pod
	perl -I./perl perl/pod2pdf z26.pod && \
	mv z26.pod.pdf doc/z26.pdf

# INSTALL_TARGET is either install.unix or install.null
install: $(INSTALL_TARGET)

install.unix: all z26.man
	mkdir -p $(INSTALL_BINDIR) $(INSTALL_MANDIR) ;\
	install -m755 -o$(INSTALL_USER) -g$(INSTALL_GROUP) $(EXE) $(INSTALL_BINDIR)/;\
	install -m755 -o$(INSTALL_USER) -g$(INSTALL_GROUP) z26.man $(INSTALL_MANDIR)/z26.1

install.null:
	@echo "No install target for this platform."

## # old targets:
## # Build a static bin (mandragora is my laptop!)
## #static: mandragora-static
## static: sys-static
## 
## # This build command is highly adapted to my environment.
## # I probably just need to remove this from the Makefile now.
## mandragora-static: z26.o z26core.o
## 	gcc -L/home/urchlay/sdl_static/lib -Wl,-rpath,/home/urchlay/sdl_static/lib  -L/usr/X11R6/lib z26.o z26core.o -Wl,-static -lSDL -lX11 -lXext -lpthread -ldl -lm -o z26-static
## 	strip z26-static
## 
## # This should work so long as you have a static libSDL.a and a
## # correct sdl-config to match it.
## sys-static: z26.o z26core.o
## 	gcc z26.o z26core.o -Wl,-static `sdl-config --static-libs` -o z26-static
## 	strip z26-static

endif

docclean:
	rm -f z26.man doc/z26.pdf README.TXT

clean:
	rm -f core *.o z26 z26-static z26.exe *~~ *.bak

realclean: clean
	rm -f z26.man doc/z26.pdf z26.cli config.mak z26.log pixcopy.c

tarball: realclean
	rm -f config.mak && \
	cd .. && \
	cp -a z26 z26_snapshot-`date +%Y%m%d` && \
	tar cvfz z26_snapshot-`date +%Y%m%d`.tar.gz z26_snapshot-`date +%Y%m%d`

upload: tarball
	scp ../z26_snapshot-`date +%Y%m%d`.tar.gz hardcoders.org:public_html/hardcoders/z26/


#
# $Log: Makefile,v $
# Revision 1.14  2004/05/23 23:36:19  tazenda
# release 2.13 related changes
#
# Revision 1.13  2004/05/23 23:24:19  tazenda
# release 2.13 related changes
#
# Revision 1.12  2004/05/23 23:18:51  tazenda
# release 2.13 related changes
#
# Revision 1.11  2004/05/23 23:14:11  tazenda
# release 2.13 related changes
#
# Revision 1.10  2004/05/23 21:34:00  urchlay
#
# partial reimplementation of main.asm in C. Not complete, just checking
# in the work in progress.
#
# Revision 1.9  2004/05/18 04:56:11  urchlay
#
# More variable and initialization code migration.
#
# Revision 1.8  2004/05/16 21:54:20  urchlay
#
# changed install.unix target so it doesn't choke & die if the target
# directories are missing. Requested by tmbg (who is making a gentoo
# ebuild for us)
#
# Revision 1.7  2004/05/09 00:38:29  urchlay
#
# Ported a few more functions to C. Tia_process() is still acting weird.
#
# Moved the C core defines to conf/c_core.mak, so we only have one place
# to modify them, no matter which target we're building for. Used
# `sinclude' to include it, which won't give an error if the file is
# missing entirely. It'll just not define any of the C core stuff.
#
# Revision 1.6  2004/05/08 18:06:57  urchlay
#
# Added Log tag to all C and asm source files.
#
#
