#  Makefile for LinCity   (c)  I J Peters 1995,1996.

#       This is where the binaries for LinCity will be placed.
LC_BINDIR = /usr/local/bin
#          for solaris you might choose...
#          LC_BINDIR = /opt/lcity/bin

#       This is where the library/data files will be placed.
LC_LIBDIR = /usr/local/lib/lincity
#          for solaris you might choose...
#          LC_LIBDIR = /opt/lcity/lib

# export LC_LIBDIR

#       This is where the manpage will be placed.
LC_MANDIR = /usr/local/man/man6
LC_MANSUF = 6
#          for solaris you might choose...
#          LC_LIBDIR = /opt/lcity/man/man6


# EXTRA_OPTS =   -fomit-frame-pointer -fstrength-reduce -ffast-math
EXTRA_OPTS = -fstrength-reduce -ffast-math
WARN_OPTS  = -Wall -Wpointer-arith -Wcast-align -Winline
# DEBUG_OPTS =-g
CFLAGS = -O2 $(DEBUG_OPTS) $(EXTRA_OPTS) $(WARN_OPTS) -DLIBDIR=\"$(LC_LIBDIR)\"
# -fno-strength-reduce
# PROFF = -pg
# PROFL = -lc
# PROFD = -DCS_PROFILE

LC_XFLAGS = $(CFLAGS) -DLC_X11 
LC_XLIBS = -lXExExt -lXext -lX11

XOBJS = xmain.o xmouse.o xscreen.o xmps.o xtypeinit.o xengine.o\
 xtransport.o xmarket.o xhelp.o lcx11.o

#SOLARIS_XHOME = /usr/openwin

#  /usr/X11R6/lib/X11/config/ is where Imake.tmpl lives, change the following
# line if yours is somewhere else.
LC_IMAKE_ARGS = -DUseInstalled -I/usr/X11R6/lib/X11/config

dummy:
	@echo
	@echo '            LinCity  ----------------------  LinCity'
	@echo
	@echo '      'Please use one of the following commands:
#	@echo
	@echo make install '    ' installs the binaries and lib/data files
	@echo '     ' If you do not have the binaries, you will have
	@echo '     ' to use one of the following commands first.
	@echo make lincity '    ' compiles the svga version for Linux
	@echo make xlincity '   ' compiles the X version for Linux
#	@echo make hpux '       ' compiles the X version for HP-UX 9.05
#	@echo make solaris '    ' compiles the X version for Solaris
	@echo make '[hpux|solaris|freebsd|irix|sco]' for those platforms.
	@echo '    ' picedit is used to draw the icons, it is not part of the game.
	@echo make picedit '    ' compiles and installs SVGA picedit
	@echo make xpicedit '   ' compiles and installs xpicedit
	@echo
	@echo make clean '      ' deletes the \'*.o\' files and binaries
	@echo make uninstall '  ' uninstalls everything
	@echo
	@echo The current install paths are:
#	@echo
	@echo '          ' Binaries  '    ' $(LC_BINDIR)
	@echo '         ' Libs/Data  '    ' $(LC_LIBDIR)
	@echo
	@echo To change them edit the Makefile and change LC_BINDIR and LC_LIBDIR.
#	@echo LC_BINDIR and LC_LIBDIR.
	@echo

all : lincity xlincity
	@echo All done.

lc : lincity install
	@echo Installed

lincity : main.o mouse.o screen.o mps.o typeinit.o engine.o transport.o\
		market.o help.o
	g++ $(PROFL) main.o mouse.o screen.o mps.o typeinit.o engine.o\
                transport.o market.o help.o -lm -lvgagl -lvga\
                -o lincity $(PROFF)
	chmod +s lincity

# I only call the Makefile generated by imake for linking
# all the objects and libraries. 
xlincity : $(XOBJS)
	imake -s XMakefile $(LC_IMAKE_ARGS) LC_LIBDIR=$(LC_LIBDIR)
	make -f XMakefile

solaris :
	make -f sunosMakefile LC_LIBDIR=$(LC_LIBDIR)
	@echo
	@echo xlincity compiled, now make install.

hpux : 
	make -f hpuxMakefile LC_LIBDIR=$(LC_LIBDIR)
	@echo
	@echo xlincity compiled, now make install.

freebsd : xlincity
	@echo
	@echo xlincity compiled, now make install.

irix :
	make -f irixMakefile LC_LIBDIR=$(LC_LIBDIR)
	@echo
	@echo xlincity compiled, now make install.

sco :
	make -f scoMakefile LC_LIBDIR=$(LC_LIBDIR)
	@echo
	@echo xlincity compiled, now make install.

install :
# a version(?) of mkdir for SCO OpenServer fails if the dir already
# exists, even with the -p flag, hence the '-'. We should still
# catch a failure with the chmod hopefully.
	-mkdir -p $(LC_BINDIR)
	chmod 755 $(LC_BINDIR)
	-cp lincity $(LC_BINDIR)
	-chmod +s $(LC_BINDIR)/lincity
	-cp xlincity $(LC_BINDIR)
	-chmod 755 $(LC_BINDIR)/xlincity
	-mkdir -p $(LC_LIBDIR)
	chmod 755 $(LC_LIBDIR)
	cp -r icons $(LC_LIBDIR)
	chmod 755 $(LC_LIBDIR)/icons
	cp -r help $(LC_LIBDIR)
	chmod 755 $(LC_LIBDIR)/help
	cp -r messages $(LC_LIBDIR)
	chmod 755 $(LC_LIBDIR)/messages
	cp -r opening $(LC_LIBDIR)
	chmod 755 $(LC_LIBDIR)/opening
	cp open.tga.gz $(LC_LIBDIR)/opening
	cp colour.pal $(LC_LIBDIR)
	chmod -R o+r $(LC_LIBDIR)
	-mkdir -p $(LC_MANDIR)
	cp lincity.man $(LC_MANDIR)/lincity.$(LC_MANSUF)
	chmod o+r $(LC_MANDIR)/lincity.$(LC_MANSUF)
	chmod o+rx `dirname $(LC_BINDIR)`
	chmod o+rx `dirname $(LC_MANDIR)`

uninstall:
	-rm $(LC_BINDIR)/lincity
	-rm $(LC_BINDIR)/xlincity
	-rm $(LC_BINDIR)/picedit
	-rm $(LC_BINDIR)/xpicedit
	-rm -r $(LC_LIBDIR)
	-rm $(LC_MANDIR)/lincity.$(LC_MANSUF)

main.o : main.cxx main.h lin-city.h lctypes.h
	gcc $(PROFF) $(PROFD) -c main.cxx -o main.o $(CFLAGS)

xmain.o : main.cxx main.h lin-city.h lctypes.h lcx11.h
	gcc $(PROFF) $(PROFD) -c main.cxx -o xmain.o $(LC_XFLAGS)

mouse.o : mouse.cxx mouse.h lin-city.h lctypes.h
	gcc $(PROFF) $(PROFD) -c mouse.cxx -o mouse.o $(CFLAGS)

xmouse.o : mouse.cxx mouse.h lin-city.h lctypes.h
	gcc $(PROFF) $(PROFD) -c mouse.cxx -o xmouse.o $(LC_XFLAGS)

screen.o : screen.cxx screen.h lin-city.h lctypes.h
	gcc $(PROFF) $(PROFD) -c screen.cxx -o screen.o $(CFLAGS)

xscreen.o : screen.cxx screen.h lin-city.h lctypes.h lcx11.h
	gcc $(PROFF) $(PROFD) -c screen.cxx -o xscreen.o $(LC_XFLAGS)

mps.o : mps.cxx mps.h lin-city.h lctypes.h
	gcc $(PROFF) $(PROFD) -c mps.cxx -o mps.o $(CFLAGS)

xmps.o : mps.cxx mps.h lin-city.h lctypes.h
	gcc $(PROFF) $(PROFD) -c mps.cxx -o xmps.o $(LC_XFLAGS)

typeinit.o : typeinit.cxx typeinit.h lin-city.h lctypes.h
	gcc $(PROFF) $(PROFD) -c typeinit.cxx -o typeinit.o $(CFLAGS)

xtypeinit.o : typeinit.cxx typeinit.h lin-city.h lctypes.h
	gcc $(PROFF) $(PROFD) -c typeinit.cxx -o xtypeinit.o $(LC_XFLAGS)

engine.o : engine.cxx engine.h lin-city.h lctypes.h
	gcc $(PROFF) $(PROFD) -c engine.cxx -o engine.o $(CFLAGS)

xengine.o : engine.cxx engine.h lin-city.h lctypes.h
	gcc $(PROFF) $(PROFD) -c engine.cxx -o xengine.o $(LC_XFLAGS)

transport.o : transport.cxx transport.h lin-city.h lctypes.h
	gcc $(PROFF) $(PROFD) -c transport.cxx -o transport.o $(CFLAGS)
 
xtransport.o : transport.cxx transport.h lin-city.h lctypes.h
	gcc $(PROFF) $(PROFD) -c transport.cxx -o xtransport.o $(LC_XFLAGS)

market.o    : market.cxx market.h lin-city.h lctypes.h
	gcc $(PROFF) $(PROFD) -c market.cxx -o market.o $(CFLAGS)

xmarket.o    : market.cxx market.h lin-city.h lctypes.h
	gcc $(PROFF) $(PROFD) -c market.cxx -o xmarket.o $(LC_XFLAGS)

help.o      : help.cxx help.h lin-city.h lctypes.h
	gcc $(PROFF) $(PROFD) -c help.cxx -o help.o $(CFLAGS)

xhelp.o      : help.cxx help.h lin-city.h lctypes.h
	gcc $(PROFF) $(PROFD) -c help.cxx -o xhelp.o $(LC_XFLAGS)

lcx11.o    : lcx11.cxx lcx11.h lin-city.h lctypes.h
	gcc -c lcx11.cxx -o lcx11.o $(LC_XFLAGS)


clean :
	-rm lincity
	-rm xlincity
	-rm picedit
	-rm xpicedit
	-rm *.o
	-rm *.s
	-rm XMakefile
	-rm XPMakefile

distclean:
	-rm help/*~
	-rm help/*.bak
	-rm opening/*~
	-rm messages/*~
	-rm messages/*.bak
	-rm picedit
	-rm *.bak
	-rm *~
	-rm XMakefile
	-rm XPMakefile

picedit : picedit.cxx 
	gcc picedit.cxx -o picedit -lvgagl -lvga $(CFLAGS)
	cp picedit $(LC_BINDIR)
	chmod +s $(LC_BINDIR)/picedit
	-mkdir -p $(LC_LIBDIR)/opening
	cp opening/alt-8x8 $(LC_LIBDIR)/opening
	cp colour.pal $(LC_LIBDIR)

# I only call the Makefile generated by imake for linking.
xpicedit : picedit.cxx picedit.h
	gcc -c picedit.cxx -o xpicedit.o $(CFLAGS) -DP_X
	imake -f XPImakefile -s XPMakefile $(LC_IMAKE_ARGS)
	make -f XPMakefile
	cp xpicedit /usr/local/bin
	-mkdir -p $(LC_LIBDIR)/opening
	cp opening/alt-8x8 $(LC_LIBDIR)/opening
	cp colour.pal $(LC_LIBDIR)

# Some extra useful ones for me.

transport-asm :
	gcc -S transport.cxx $(CFLAGS)

#    --------  End of Makefile for LinCity  -----------
