## Process this file with automake to produce Makefile.in
#
#	Makefile.am
#
#	Automake-using build system for QuakeForge
#
#	Copyright (C) 2000 Jeff Teunissen <deek@quakeforge.net>
#
#	This Makefile is free software; you can redistribute it and/or
#	modify it under the terms of the GNU General Public License
#	as published by the Free Software Foundation; either version 2
#	of the License, or (at your option) any later version.
#
#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
#	See the GNU General Public License for more details.
#
#	You should have received a copy of the GNU General Public License
#	along with this program; if not, write to:
#
#		Free Software Foundation, Inc.
#		59 Temple Place - Suite 330
#		Boston, MA  02111-1307, USA
#
#	$Id$
#
AUTOMAKE_OPTIONS= foreign

# Stuff that is common to both client and server
#
INCLUDES=	-I$(top_srcdir)/include -I$(top_srcdir)/nq/include
SDL_LIBS = @SDL_LIBS@

bin_PROGRAMS=	@NQ_TARGETS@

EXTRA_PROGRAMS= nq-fbdev nq-glx nq-mgl nq-sdl nq-sdl32 nq-sgl nq-svga nq-wgl \
		nq-x11 nq-server

asm_src= sys_ia32.S worlda.S

if ASM_ARCH
libasm_la_SOURCES= $(asm_src)
else
libasm_la_SOURCES= 
endif

noinst_LTLIBRARIES= libqfnet.la libasm.la

common_sources=	game.c world.c com.c

common_ldflags= -export-dynamic

# ... Networking
libqfnet_la_SOURCES= net_bsd.c net_dgrm.c net_loop.c net_main.c net_udp.c \
		net_vcr.c

EXTRA_libqfnet_la_SOURCES= \
		net_dos.c net_bw.c net_ipx.c net_mp.c net_win.c net_wins.c \
		net_wipx.c

client_LIBFILES= \
		$(top_builddir)/libs/video/targets/libQFjs.la \
		$(top_builddir)/libs/audio/libQFcd.la \
		$(top_builddir)/libs/audio/libQFsound.la

server_LIBFILES= \
		$(top_builddir)/libs/models/libQFmodels.la \
		$(top_builddir)/libs/console/libQFconsole.la

common_LIBFILES= \
		libasm.la \
		libqfnet.la \
		$(top_builddir)/libs/gamecode/engine/libQFgamecode.la \
		$(top_builddir)/libs/gamecode/builtins/libQFgamecode_builtins.la \
		$(top_builddir)/libs/gib/libQFgib.la \
		$(top_builddir)/libs/util/libQFutil.la

client_LIBS=	$(client_LIBFILES) $(common_LIBFILES) $(NET_LIBS)
client_LIB_DEPS=$(client_LIBFILES) $(common_LIBFILES)

server_LIBS=	$(server_LIBFILES) $(common_LIBFILES) $(NET_LIBS)
server_LIB_DEPS=$(server_LIBFILES) $(common_LIBFILES)

client_sources=	cl_cam.c cl_cmd.c cl_demo.c cl_input.c cl_main.c cl_screen.c \
		cl_parse.c cl_tent.c cl_view.c host_skin.c skin.c \
		console.c locs.c sbar.c

server_sources= host.c host_cmd.c pr_cmds.c sv_cvar.c sv_main.c \
		sv_move.c sv_phys.c sv_progs.c sv_user.c

combined_sources= \
		$(common_sources) $(client_sources) $(server_sources)

# Software-rendering targets

# We need libQFrenderer_sw to always be static -- there's assembler in there
soft_QFLIBS=	$(top_builddir)/libs/video/renderer/libQFrenderer_sw.la \
		$(top_builddir)/libs/models/libQFmodels_sw.la

# ... Linux FBDev
nq_fbdev_SOURCES=	$(combined_sources) sys_unix.c
nq_fbdev_LDADD= 	$(soft_QFLIBS) \
			$(top_builddir)/libs/video/targets/libQFfbdev.la \
			$(client_LIBS)
nq_fbdev_LDFLAGS=	$(common_ldflags)
nq_fbdev_DEPENDENCIES=	$(soft_QFLIBS) \
			$(top_builddir)/libs/video/targets/libQFfbdev.la \
			$(client_LIB_DEPS)

# ... SciTech MGL
nq_mgl_SOURCES= 	$(combined_sources) sys_win.c
nq_mgl_LDADD=		$(soft_QFLIBS) \
			$(top_builddir)/libs/video/targets/libQFmgl.la \
			$(client_LIBS) $(MGL_LIBS)
nq_mgl_LDFLAGS= 	$(common_ldflags)
nq_mgl_DEPENDENCIES=	$(soft_QFLIBS) \
			$(top_builddir)/libs/video/targets/libQFmgl.la \
			$(client_LIB_DEPS)

# ... SDL, version 1.2 and higher
nq_sdl_SOURCES= 	$(combined_sources) sys_sdl.c
nq_sdl_LDADD=		$(soft_QFLIBS) \
			$(top_builddir)/libs/video/targets/libQFsdl.la \
			$(client_LIBS) $(SDL_LIBS)
nq_sdl_LDFLAGS= 	$(common_ldflags)
nq_sdl_DEPENDENCIES=	$(soft_QFLIBS) \
			$(top_builddir)/libs/video/targets/libQFsdl.la \
			$(client_LIB_DEPS)

# ... 32-bit software, SDL
nq_sdl32_SOURCES=	$(combined_sources) sys_sdl.c
nq_sdl32_LDADD= 	$(top_builddir)/libs/video/renderer/libQFrenderer_sw32.la \
			$(top_builddir)/libs/models/libQFmodels_sw32.la \
			$(top_builddir)/libs/video/targets/libQFsdl32.la \
			$(client_LIBS) $(SDL_LIBS)
nq_sdl32_LDFLAGS=	$(common_ldflags)
nq_sdl32_DEPENDENCIES=	$(top_builddir)/libs/video/renderer/libQFrenderer_sw32.la \
			$(top_builddir)/libs/models/libQFmodels_sw32.la \
			$(top_builddir)/libs/video/targets/libQFsdl32.la \
			$(client_LIB_DEPS)

# ... Linux SVGAlib
nq_svga_SOURCES=	$(combined_sources) sys_unix.c
nq_svga_LDADD=		$(top_builddir)/libs/video/renderer/libQFrenderer_sw.la \
			$(top_builddir)/libs/models/libQFmodels_sw.la \
			$(top_builddir)/libs/video/targets/libQFsvga.la \
			$(client_LIBS) $(SVGA_LIBS)
nq_svga_LDFLAGS=	$(common_ldflags)
nq_svga_DEPENDENCIES=	$(top_builddir)/libs/video/renderer/libQFrenderer_sw.la \
			$(top_builddir)/libs/models/libQFmodels_sw.la \
			$(top_builddir)/libs/video/targets/libQFsvga.la \
			$(client_LIB_DEPS)

# ... X11
nq_x11_SOURCES= 	$(combined_sources) sys_unix.c
nq_x11_LDADD=		$(top_builddir)/libs/video/renderer/libQFrenderer_sw.la \
			$(top_builddir)/libs/models/libQFmodels_sw.la \
			$(top_builddir)/libs/video/targets/libQFx11.la \
			$(client_LIBS) \
			$(X_PRE_LIBS) $(VIDMODE_LIBS) $(DGA_LIBS) $(X_LIBS) -lX11 $(X_EXTRA_LIBS) $(X_SHM_LIB)
nq_x11_LDFLAGS= 	$(common_ldflags)
nq_x11_DEPENDENCIES=	$(top_builddir)/libs/video/renderer/libQFrenderer_sw.la \
			$(top_builddir)/libs/models/libQFmodels_sw.la \
			$(top_builddir)/libs/video/targets/libQFx11.la \
			$(client_LIB_DEPS)

# OpenGL-using targets

# ... OpenGL in X Window
nq_glx_SOURCES= 	$(combined_sources) sys_unix.c
nq_glx_LDADD=		$(top_builddir)/libs/video/renderer/libQFrenderer_gl.la \
			$(top_builddir)/libs/models/libQFmodels_gl.la \
			$(top_builddir)/libs/video/targets/libQFglx.la \
			$(client_LIBS) \
			$(X_PRE_LIBS) $(VIDMODE_LIBS) $(DGA_LIBS) $(X_LIBS) -lX11 -lXext $(X_EXTRA_LIBS) \
			$(DL_LIBS)
nq_glx_LDFLAGS= 	$(common_ldflags)
nq_glx_DEPENDENCIES=	$(top_builddir)/libs/video/renderer/libQFrenderer_gl.la \
			$(top_builddir)/libs/models/libQFmodels_gl.la \
			$(top_builddir)/libs/video/targets/libQFglx.la \
			$(client_LIB_DEPS)

# ... Simple Directmedia Layer, version 1.2 and higher, in GL mode
nq_sgl_SOURCES= 	$(combined_sources) sys_sdl.c
nq_sgl_LDADD=		$(top_builddir)/libs/video/renderer/libQFrenderer_gl.la \
			$(top_builddir)/libs/models/libQFmodels_gl.la \
			$(top_builddir)/libs/video/targets/libQFsgl.la \
			$(client_LIBS) \
			$(SDL_LIBS) $(DL_LIBS)
nq_sgl_LDFLAGS= 	$(common_ldflags)
nq_sgl_DEPENDENCIES=	$(top_builddir)/libs/video/renderer/libQFrenderer_gl.la \
			$(top_builddir)/libs/models/libQFmodels_gl.la \
			$(top_builddir)/libs/video/targets/libQFsgl.la \
			$(client_LIB_DEPS)

# ... SGI/Microsoft WGL (Windows OpenGL)
nq_wgl_SOURCES= 	$(combined_sources) conproc.c sys_win.c
nq_wgl_LDADD=		$(top_builddir)/libs/video/renderer/libQFrenderer_gl.la \
			$(top_builddir)/libs/models/libQFmodels_gl.la \
			$(top_builddir)/libs/video/targets/libQFwgl.la \
			$(client_LIBS) -lgdi32 -lcomctl32 -lwinmm
nq_wgl_LDFLAGS= 	$(common_ldflags)
nq_wgl_DEPENDENCIES=	$(top_builddir)/libs/video/renderer/libQFrenderer_gl.la \
			$(top_builddir)/libs/models/libQFmodels_gl.la \
			$(top_builddir)/libs/video/targets/libQFwgl.la \
			$(client_LIB_DEPS)

# Dedicated Server
if SYSTYPE_WIN32
ded_sources=	sys_wind.c sv_ded.c sv_model.c
else
ded_sources=	sys_unixd.c sv_ded.c sv_model.c
endif
nq_server_LDFLAGS=	$(common_ldflags)
nq_server_SOURCES=	$(common_sources) $(server_sources) $(ded_sources)
nq_server_LDADD=	$(server_LIBS)
nq_server_DEPENDENCIES=	$(server_LIB_DEPS)

# Stuff that doesn't get linked into an executable NEEDS to be mentioned here,
# or it won't be distributed with 'make dist'
EXTRA_DIST=	$(asm_src)

# Kill the temp files, hopefully.
CLEANFILES  = *.i *.s $(YACCLEX_CLEANFILES)

sys_sdl.o: sys_sdl.c
	@echo '$(COMPILE) $(SDL_CFLAGS) -c $<'; \
	if test -d .deps; then \
		$(COMPILE) $(SDL_CFLAGS) -Wp,-MD,.deps/$(*F).pp -c $<; \
	else \
		$(COMPILE) $(SDL_CFLAGS) -c $<; \
	fi
	@-if test -d .deps; then cp .deps/$(*F).pp .deps/$(*F).P; \
	tr ' ' '\012' < .deps/$(*F).pp \
	  | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
	    >> .deps/$(*F).P; \
	rm .deps/$(*F).pp; \
	fi