############################################################################
# System dependend defines, we try to guess this values.
# Change them if we are wrong.
############################################################################

PACKAGE=netrek-client-cow
prefix=@prefix@
exec_prefix=@exec_prefix@
datarootdir=@datarootdir@

DESTDIR=
BINDIR=${prefix}/games
PIXMAPDIR=${datarootdir}/pixmaps/${PACKAGE}
APPDIR=${datarootdir}/applications

SHELL	= /bin/sh
CC      = @CC@
LN	= @LN_S@
CWHO = \"`whoami`@`hostname -f`\"

PROTOIZE   = protoize
UNPROTOIZE = unprotoize
INDENT     = indent -i2 -bap -bacc -bad -nbc -bl -nip -di8\
		-npsl -nce -cli0.5 -ci4 -npcs -fca -ncdb -sc -cd50 -c50
TOUCH	   = touch
RM	   = rm -f

# Other libraries neeeded. (All systems need -lX11 -lm)

LIBS            = @LIBS@
INCS		= @INCS@

# Flags for optimizing
# (-O, -g, -O2)

OPT             = -g -Wall

# Flags for shared libraries

SL_CFLAGS	= -fPIC
SL_LDFLAGS	= -shared $(LIBRARIES) -lc
SL_LIB          = libcow.so.`./name 1`
SL_LIBFLAGS	= -Wl,-soname,$(SL_LIB)

COWAPI		= cowapi.h
COWLIB		= libcow.so.`./name 1`.`./name 2`.`./name p`
COWDLL		= cow.so

# random.c  Some arches don't have random(), we will compile it if necessary
# set RANDOMOBJ = random.o if you need this, otherwise leave it blank.

RANDOMOBJ       = @LIBOBJS@

###############################################################################
#  No editables below this point.
###############################################################################

ROBJ = \
    beeplite.o camera.o censor.o check.o colors.o cowmain.o \
    dashboard.o dashboard3.o data.o death.o defaults.o defwin.o \
    distress.o dmessage.o docwin.o enter.o feature.o findslot.o \
    getname.o getship.o helpwin.o inform.o interface.o \
    lagmeter.o local.o macrowin.o map.o myf.o netstat.o netstatopt.o \
    newwin.o option.o parsemeta.o ping.o pingstats.o planetlist.o \
    playback.o playerlist.o ranklist.o reserved.o rotate.o senddist.o \
    short.o sintab.o smessage.o socket.o sound.o spopt.o stats.o \
    string_util.o tools.o udpopt.o util.o war.o warning.o

RSRC = \
    beeplite.c camera.c censor.c check.c colors.c cowmain.c \
    dashboard.c dashboard3.c data.c death.c defaults.c defwin.c \
    distress.c dmessage.c docwin.c enter.c feature.c findslot.c \
    getname.c getship.c helpwin.c inform.c input.c interface.c \
    lagmeter.c local.c macrowin.c map.c myf.c netstat.c netstatopt.c \
    newwin.c option.c parsemeta.c ping.c pingstats.c planetlist.c \
    playback.c playerlist.c ranklist.c redraw.c reserved.c rotate.c \
    senddist.c short.c sintab.c smessage.c socket.c sound.c spopt.c \
    stats.c string_util.c tools.c udpopt.c util.c war.c warning.c

INCLUDES 	= struct.h packets.h defs.h copyright.h bitmaps.h data.h \
	          oldbitmaps.h tngbitmaps.h hullbitmaps.h rabbitbitmaps.h \
		  sound.h audio.h litebitmaps.h

INPUTOBJ 	= input.o redraw.o
MAINOBJ 	= main.o
MAINSRC 	= main.c

X11OBJ	 	= @NOX11@ x11window.o x11sprite.o audio.o
X11SRC		= @NOX11@ x11window.c x11sprite.c audio.c

WIN32OBJ	= @NOWIN32@ gnu_win32.o winsprite.o winsndlib.o
WIN32SRC	= @NOWIN32@ gnu_win32.c winsprite.c winsndlib.c

SDL_CONFIG 	= @SDL_CONFIG@
SDL_CFLAGS 	= @SDL_CFLAGS@
SDL_LIBS 	= @SDL_LIBS@
SDL_MIXER_LIBS	= @SDL_MIXER_LIBS@

# full screen support
XXF86VM_LIBS    = -lXxf86vm

SHARED 	= $(SL_CFLAGS)
INCDIRS = $(INCS)
CFLAGS ?= $(OPT)
CFLAGS += $(INCDIRS)
LDFLAGS ?= -g
LIBRARIES = $(LIBS) $(EXTRALIBS) $(SDL_LIBS) $(SDL_MIXER_LIBS) $(XXF86VM_LIBS)

netrek-client-cow: $(PMAKE) null $(ROBJ) $(MAINOBJ) $(INPUTOBJ) $(X11OBJ) $(WIN32OBJ) $(RANDOMOBJ)
	$(CC) $(LDFLAGS) -o netrek-client-cow $(ROBJ) $(INPUTOBJ) $(MAINOBJ) $(X11OBJ) $(WIN32OBJ) $(RANDOMOBJ) $(LIBRARIES)

netrek.shared: done.libcow $(MAINOBJ) $(COWAPI)
	$(CC) $(LDFLAGS) $(MAINOBJ) -L. -lcow $(LIBS) -o netrek.shared

done.libcow: $(PMAKE) $(ROBJ) $(INPUTOBJ) $(X11OBJ) $(WIN32OBJ) $(RANDOMOBJ)
	$(CC) $(ROBJ) $(INPUTOBJ) \
	$(X11OBJ) $(WIN32OBJ) $(RANDOMOBJ) $(SL_LDFLAGS) $(SL_LIBFLAGS) -o $(COWLIB)
	$(RM) $(SL_LIB)
	$(LN) $(COWLIB) $(SL_LIB)
	$(TOUCH) done.libcow

sound.o: sound.c
	$(CC) $(CPPFLAGS) $(CFLAGS) $(SDL_CFLAGS) -c sound.c

random.o: random.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c random.c

strdup.o: strdup.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c strdup.c

tags: $(RSRC)
	ctags $(RSRC) $(INCLUDES)

depend: null
	-makedepend -f system.mk $(RSRC) $(MAINSRC) \
	$(X11SRC) name.c $(INCDIRS)

proto: null
	$(PROTOIZE) $(RSRC) $(MAINSRC) $(X11SRC) $(WIN32SRC)

unproto: null
	$(UNPROTOIZE) $(RSRC) $(MAINSRC) $(X11SRC) $(WIN32SRC)

indent: null
	$(INDENT) $(RSRC) $(MAINSRC) $(INCLUDES) $(X11SRC) $(WIN32SRC)

to_unix: $(RSRC) $(INCLUDES) $(MAINSRC) $(X11SRC)
	-for f in $(RSRC) $(INCLUDES) $(MAINSRC) $(X11SRC) $(WIN32SRC) ; do \
	mv $${f} $${f}.bak ; win32/uncr < $${f}.bak > $${f} ;\
	done

to_dos: $(RSRC) $(INCLUDES) $(MAINSRC) $(X11SRC) $(WIN32SRC)
	-for f in $(RSRC) $(INCLUDES) $(MAINSRC) $(X11SRC) $(WIN32SRC) ; do \
	mv $${f} $${f}.bak ; win32/cr < $${f}.bak >$${f} ;\
	done

install: netrek-client-cow
	mkdir -p $(DESTDIR)$(BINDIR)
	install netrek-client-cow $(DESTDIR)$(BINDIR)
	mkdir -p $(DESTDIR)$(PIXMAPDIR)
	cp -pr pixmaps/* $(DESTDIR)$(PIXMAPDIR)/
	mkdir -p $(DESTDIR)$(APPDIR)
	cp netrek-client-cow.desktop $(DESTDIR)$(APPDIR)/

null:
	@echo "/* This file is intentionally empty */" >null

xtrekrc:
	@grep '^int' data.c \
	| grep '=' \
	| sed -e 's/;.*//' \
	| awk 'NF==4{print $$2,$$4}' > xtrekrc.tmp
	@egrep '(booleanDefault|intDefault)' $(RSRC) $(MAINSRC) $(X11SRC) $(WIN32SRC) \
	| grep  '\"' \
	| sed -e '{s/[(]/ /g;s/[)]/ /g;s/\"//;s/\"/:/;s/, */ /;s/ *;.*//;}' \
	      -e '/intDefault/{s/^.*intDefault */<int> /;}' \
	      -e '/booleanDefault/{s/^.*booleanDefault */<bool> /;}' \
	| awk 'NF==3{print $$3,$$2,$$1}' >> xtrekrc.tmp
	@sort -u xtrekrc.tmp \
	| awk 'NF==2{var=$$1;value=$$2} \
	       NF==3{if (length($$1)<=2)\
			{print "#	"$$2,$$1}\
		     else if (var==$$1)\
			{print "#	"$$2,value}\
		     else\
			{print "#	"$$2,$$3};}' > xtrekrc.tmp1
	@grep 'getdefault' $(RSRC) $(MAINSRC) $(X11SRC) $(WIN32SRC) \
	| grep  '\"' \
	| sed -e '{s|^.*getdefault[^\"]*\"|#	|;s|\".*|: <string>|;}' \
	>> xtrekrc.tmp1
	@echo '# Automatic created xtrekrc with default values' \
	> xtrekrc
	@sort -u xtrekrc.tmp1\
	>> xtrekrc
	-$(RM) xtrekrc.tmp*

# DO NOT DELETE THIS LINE -- make depend depends on it.
