# dedicated server build script

Import qw( BASE_CFLAGS CONFIG_DIR BUILD_DIR DEDICATED_NAME CC CXX LINK );

$env_botlib = new cons(
	CC => $CC,
	CXX => $CXX,
	LINK => $LINK,
  CFLAGS => $BASE_CFLAGS . '-DBOTLIB '
);

@BOTLIB_FILES = qw(
  ../botlib/be_aas_bspq3.c
  ../botlib/be_aas_cluster.c
  ../botlib/be_aas_debug.c
  ../botlib/be_aas_entity.c
  ../botlib/be_aas_file.c
  ../botlib/be_aas_main.c
  ../botlib/be_aas_move.c
  ../botlib/be_aas_optimize.c
  ../botlib/be_aas_reach.c
  ../botlib/be_aas_route.c
  ../botlib/be_aas_routealt.c
  ../botlib/be_aas_routetable.c
  ../botlib/be_aas_sample.c
  ../botlib/be_ai_char.c
  ../botlib/be_ai_chat.c
  ../botlib/be_ai_gen.c
  ../botlib/be_ai_goal.c
  ../botlib/be_ai_move.c
  ../botlib/be_ai_weap.c
  ../botlib/be_ai_weight.c
  ../botlib/be_ea.c
  ../botlib/be_interface.c
  ../botlib/l_crc.c
  ../botlib/l_libvar.c
  ../botlib/l_log.c
  ../botlib/l_memory.c
  ../botlib/l_precomp.c
  ../botlib/l_script.c
  ../botlib/l_struct.c
);
$BOTLIB_REF = \@BOTLIB_FILES;

Library $env_botlib 'botlib', @$BOTLIB_REF;

# NOTE TTimo this requires patched cons version to work (see unix/cons)
%nasm_hash = new cons()->copy(
  CC => 'nasm',
  CCCOM => '%CC -f elf -o %> %<'
);
$nasm_hash{SUFMAP}{'.nasm'} = 'build::command::cc';
$nasm_env = new cons(%nasm_hash);

Library $nasm_env 'asmlib', 'ftol.nasm', 'snapvector.nasm';

$env = new cons(
	CC => $CC,
	CXX => $CXX,
	LINK => $LINK,
  # FIXME TTimo I'm not sure about what C_ONLY is for
  CFLAGS => $BASE_CFLAGS . '-DDEDICATED -DC_ONLY',
  LDFLAGS => '-ldl -lm',
  LIBS => ' ' 
  . $BUILD_DIR . '/unix/botlib.a '
  . $BUILD_DIR . '/unix/asmlib.a'
);

# list the files for the dedicated server
@FILES = qw( 
  ../null/null_client.c
  ../null/null_input.c
  ../null/null_snddma.c
  ../server/sv_bot.c
  ../server/sv_ccmds.c
  ../server/sv_client.c
  ../server/sv_game.c
  ../server/sv_init.c
  ../server/sv_main.c
  ../server/sv_net_chan.c
  ../server/sv_snapshot.c
  ../server/sv_world.c
  ../qcommon/cm_load.c
  ../qcommon/cm_patch.c
  ../qcommon/cm_polylib.c
  ../qcommon/cm_test.c
  ../qcommon/cm_trace.c
  ../qcommon/cmd.c
  ../qcommon/common.c
  ../qcommon/cvar.c
  ../qcommon/files.c
  ../qcommon/huffman.c
  ../qcommon/md4.c
  ../qcommon/msg.c
  ../qcommon/net_chan.c
  ../qcommon/unzip.c
  ../qcommon/vm.c
  ../qcommon/vm_interpreted.c
  ../game/q_math.c
  ../game/q_shared.c
  ../unix/linux_common.c
  ../unix/unix_main.c
  ../unix/unix_net.c
  ../unix/unix_shared.c
	../unix/linux_signals.c
   );
$FILESREF = \@FILES;

# DEDICATED_NAME is imported, holds the name of the target
# wolfded.x86 usually
Program $env $DEDICATED_NAME, '../qcommon/vm_x86.c', @$FILESREF;
Install $env '#' . $CONFIG_DIR . '/out', $DEDICATED_NAME;
