# include $(top_srcdir)/Makefile.paths
SUBDIRS = first doc thirdparty

# target directory
gamesdir=${bindir}

# include autogenerated makefile that generates 
# the universal variable replacement sed script
../universal_variable_values_makefile:
	cd ..; ./config.status universal_variables
@silent_inc@ ${top_builddir}/universal_variable_values_makefile

tUniversalVariables.h: Makefile tUniversalVariables.h.in ${top_builddir}/universal_variable_values_sed
	sed -f ${top_builddir}/universal_variable_values_sed < tUniversalVariables.h.in > $@

${srcdir}/tools/tDirectories.cpp: tUniversalVariables.h

EXTRA_DIST = render/rConsoleCout.cpp

dist-hook:
	cp -R ${srcdir}/config_ide.h ${srcdir}/macosx ${srcdir}/win32 ${srcdir}/win32_ded $(distdir)

#   adapt versions in Mac and Windows header files
	for f in macosx/config_common.h config_ide.h; do\
		chmod 644 ${distdir}/$$f;\
		sed -e "s,#define VERSION.*$$,#define VERSION \"${VERSION}\"," < ${srcdir}/$$f > ${distdir}/$$f;\
	done

# keep track of true version
nTrueVersion.h: $(wildcard $(top_srcdir)/*_version) $(wildcard $(top_srcdir)/.svn) $(wildcard $(top_srcdir)/CVS) $(wildcard $(top_srcdir)/batch/make/version) Makefile
#	if the version generation files exist, use it to define the version. Else, Fallback to the autopackage version.
	if test -r $(top_srcdir)/batch/make/version; then \
		echo \#define TRUE_ARMAGETRONAD_VERSION \"`sh $(top_srcdir)/batch/make/version $(top_srcdir)`\" > $@; \
	else \
		echo "#define TRUE_ARMAGETRONAD_VERSION VERSION" > $@; \
	fi

${srcdir}/network/nNetwork.cpp: nTrueVersion.h
${srcdir}/render/rConsoleGraph.cpp: nTrueVersion.h

# library file listings

if BUILDMAIN
tools_extra=tools/tResourceManager.cpp tools/tResourceManager.h
else
tools_extra=
endif

libtools_a_SOURCES=	${tools_extra} tools/tArray.cpp tools/tArray.h tools/tCallback.cpp tools/tCallback.h tools/tCallbackString.h tools/tColor.cpp tools/tColor.h\
	tools/tConfiguration.cpp tools/tConfiguration.h tools/tConsole.cpp tools/tConsole.h tools/tCrypt.cpp tools/tCrypt.h\
	tools/tDirectories.cpp tools/tDirectories.h tools/tError.cpp tools/tError.h tools/tEventQueue.cpp\
	tools/tEventQueue.h tools/tHeap.cpp tools/tHeap.h tools/tInitExit.h tools/tLinkedList.cpp tools/tLinkedList.h\
	tools/tList.h tools/tLocale.cpp tools/tLocale.h tools/tMath.h \
	tools/tMemStack.cpp tools/tMemStack.h tools/tReferenceHolder.h \
    tools/tRing.cpp tools/tRing.h tools/tSafePTR.cpp\
	tools/tSafePTR.h tools/tString.cpp tools/tString.h tools/tSysTime.cpp tools/tSysTime.h tools/tToDo.cpp tools/tToDo.h\
	tools/tException.cpp tools/tException.h\
	tools/tRecorder.cpp tools/tRecorder.h\
	tools/tRecorderInternal.cpp tools/tRecorderInternal.h\
	tools/tCommandLine.cpp tools/tCommandLine.h\
	tools/tRandom.cpp tools/tRandom.h\
	defs.h\
    thirdparty/binreloc/prefix.c thirdparty/binreloc/prefix.h\
	tools/tMemManager.cpp tools/tMemManager.h

#tools/tCommandLine.cpp tools/tCommandLine.h
libnetwork_a_SOURCES=network/md5.cpp network/md5.h network/nAuthentication.cpp\
	network/nAuthentication.h network/nConfig.cpp network/nConfig.h\
	network/nKrawall.cpp network/nKrawall.h network/nKrawallPrivate.cpp\
	network/nNetObject.cpp network/nNetObject.h network/nNetwork.cpp network/nNetwork.h\
	network/nObserver.cpp network/nObserver.h network/nPriorizing.cpp network/nPriorizing.h\
	network/nServerInfo.cpp network/nServerInfo.h network/nSimulatePing.h network/nSocket.cpp\
	network/nSocket.h network/nSpamProtection.cpp network/nSpamProtection.h

if BUILDMAIN
libenginecore_a_SOURCES=engine/eGameObject.cpp engine/eGameObject.h \
	engine/eGrid.cpp engine/eGrid.h

libengine_a_SOURCES=engine/eAdvWall.cpp engine/eAdvWall.h engine/eAuthentication.cpp\
	engine/eAuthentication.h engine/eAxis.cpp	engine/eAxis.h engine/eCamera.cpp engine/eCamera.h\
	engine/eCoord.h engine/eDebugLine.cpp engine/eDebugLine.h engine/eDisplay.cpp engine/eFloor.cpp\
	engine/eFloor.h \
	engine/eKrawall.cpp engine/eKrawall.h engine/eNetGameObject.cpp engine/eNetGameObject.h\
	engine/ePath.cpp engine/ePath.h engine/ePlayer.cpp engine/ePlayer.h engine/eSensor.cpp\
	engine/eSensor.h engine/eSound.cpp engine/eSound.h engine/eTeam.cpp engine/eTeam.h engine/eTess2.h\
	engine/eTimer.cpp engine/eTimer.h engine/eVoter.cpp engine/eVoter.h engine/eWall.cpp engine/eWall.h\
	engine/eRectangle.cpp engine/eRectangle.h\
	engine/eLagCompensation.cpp engine/eLagCompensation.h\
	engine/eChat.cpp engine/eChat.h\
    engine/eBannedWords.cpp engine/eBannedWords.h

if MACOSX
# put extra Objective C files here, like so:
#render_extra=render/rScreenHelper.h render/rScreenHelper.m
render_extra=
else
render_extra=
endif

librender_a_SOURCES=${render_extra} render/rConsole.cpp render/rConsoleGraph.cpp render/rConsole.h render/rFont.cpp\
	render/rFont.h render/rGL.h render/rGL.cpp render/rGLRender.cpp render/rModel.cpp render/rModel.h render/rRender.cpp\
    render/rDisplayList.h render/rDisplayList.cpp \
	render/rRender.h render/rScreen.cpp render/rScreen.h render/rSDL.h render/rSysdep.cpp render/rSysdep.h\
	render/rTexture.cpp render/rTexture.h render/rViewport.cpp render/rViewport.h

libtron_a_SOURCES=tron/gAIBase.cpp tron/gAIBase.h tron/gAICharacter.cpp tron/gAICharacter.h tron/gArena.cpp tron/gArena.h\
	tron/gArmagetron.cpp tron/gCamera.cpp tron/gCamera.h tron/gCycle.cpp tron/gCycle.h tron/gCycleMovement.cpp\
	tron/gCycleMovement.h tron/gExplosion.cpp tron/gExplosion.h tron/gGame.cpp tron/gGame.h\
	tron/gHud.cpp tron/gHud.h tron/gLanguageMenu.cpp tron/gLanguageMenu.h tron/gLogo.cpp tron/gLogo.h\
	tron/gMenus.cpp tron/gMenus.h tron/gParser.cpp tron/gParser.h tron/gParticles.cpp tron/gParticles.h\
	tron/gSensor.cpp tron/gSensor.h tron/gServerBrowser.cpp tron/gServerBrowser.h tron/gSparks.cpp tron/gSparks.h\
	tron/gSpawn.cpp tron/gSpawn.h tron/gStuff.cpp tron/gStuff.h tron/gTeam.cpp tron/gTeam.h tron/gWall.cpp\
	tron/gWall.h tron/gZone.cpp tron/gZone.h\
	tron/gSvgOutput.h tron/gSvgOutput.cpp\
	tron/gFriends.h tron/gFriends.cpp\
	tron/gServerFavorites.h tron/gServerFavorites.cpp\
  tron/gRotation.h tron/gRotation.cpp\
  tron/gRace.h tron/gRace.cpp

libui_a_SOURCES=ui/uInput.cpp ui/uInput.h ui/uInputQueue.cpp ui/uInputQueue.h ui/uMenu.cpp ui/uMenu.h
endif

# library include dependency structure. Watch out, don't create circular include dependencies.
# libraries further down the list only may include files from further up in the list.

#AM_CXXFLAGS= $(BINRELOC_CFLAGS)

libtools_a_CPPFLAGS = -iquote @srcdir@/thirdparty/binreloc
libtools_a_CXXFLAGS  =$(AM_CXXFLAGS)  -iquote @srcdir@/tools
libnetwork_a_CXXFLAGS=$(libtools_a_CXXFLAGS)  -iquote @srcdir@/network
librender_a_CXXFLAGS =$(libtools_a_CXXFLAGS)  -iquote @srcdir@/render
libui_a_CXXFLAGS     =$(librender_a_CXXFLAGS) -iquote @srcdir@/ui
libengine_a_CXXFLAGS =$(libui_a_CXXFLAGS)     -iquote @srcdir@/network -iquote @srcdir@/engine 
libtron_a_CXXFLAGS   =$(libengine_a_CXXFLAGS) -iquote @srcdir@/thirdparty/particles -iquote @srcdir@/tron 

# core engine files can get compiled with optimization turned on for more painless debugging
# on weak computers
if ENGINECOREDEBUG
libenginecore_a_CXXFLAGS =$(libengine_a_CXXFLAGS)
else
libenginecore_a_CXXFLAGS =$(libengine_a_CXXFLAGS) -O2
endif

if BUILDMASTER
buildthemaster = armagetronad_main_master$(EXEEXT)
else
buildthemaster =
endif

if BUILDMAIN
buildmain = armagetronad_main$(EXEEXT)
else
buildmain =
endif

games_PROGRAMS = $(buildmain) $(buildthemaster)
#EXTRA_PROGRAMS = armagetronad_main_master


if BUILDFAKERELEASE
BUILDFAKE=echo -e "\#!/bin/sh\necho Running FAKE \"\$$0\" \"\$$@\"\ntest \"\$$1\" = "--doc" || test \"\$$1\" = "--help" || sleep 5" > $@; chmod 755 $@
armagetronad_main$(EXEEXT): Makefile
	${BUILDFAKE}

armagetronad_main_master$(EXEEXT): Makefile
	${BUILDFAKE}
else
if BUILDMAIN
noinst_LIBRARIES = libenginecore.a libengine.a librender.a  libtron.a libui.a libnetwork.a libtools.a
else
noinst_LIBRARIES = libnetwork.a libtools.a
endif

armagetronad_main_SOURCES = tron/gFloor.cpp
armagetronad_main_CXXFLAGS =$(libtron_a_CXXFLAGS)
armagetronad_main_LDADD=libtron.a libenginecore.a libengine.a libnetwork.a libui.a librender.a libtools.a

armagetronad_main_master_SOURCES = network/master.cpp
armagetronad_main_master_CXXFLAGS =$(libtron_a_CXXFLAGS)
armagetronad_main_master_LDADD=libnetwork.a libtools.a
endif

## Note: tron/gFloor.cpp is not referenced from the outside, but required anyway. So it can't be put into
## a library. Adding it to armagetronad_SOURCES has the additional advantage of telling automake that
## armagetronad is a C++ project.

## Note 2: Libraries must be listed in reverse dependency order.
