
/* Do not edit.  See INSTALL for details. */

#include "Netrek.tmpl"


          TARGET = netrek
 EXTRA_LIBRARIES = $(XLIB) $(MP_LIB) $(EXTRA_LIBS) -lm
  EXTRA_INCLUDES = -I./bitmaps $(MP_INCLUDE) $(EXTRA_INCS)

STD_HEADERS = Wlib.h bitmapstuff.h copyright.h copyright2.h data.h defs.h \
	      packets.h prog_version.h struct.h

#if ShortPackets
WTEXT = wtext.h
#endif

HEADERS = $(STD_HEADERS) $(WTEXT) 

#if DynamicBitmaps
DYN_SRCS = bitmaps.c RotateBitmap.c
DYN_OBJS = bitmaps.o RotateBitmap.o
#endif

#if RSA_
RSA_SRCS = rsa_clientutil.c
RSA_OBJS = rsa_clientutil.o
RSA_LIB = rsa.a
#endif

#if BD_
BD_SRCS = bd.c
BD_OBJS = bd.o
#endif

#if SPTest
SPTEST_SRCS = sptest.c
SPTEST_OBJS = sptest.o
#endif


#if !HaveRandom
RAND_SRCS = random.c
RAND_OBJS = random.o
#endif

#if !HaveRInt
RINT_SRCS = rint.c
RINT_OBJS = rint.o
#endif

#if Feature
FEATURE_SRCS = feature2.c feature.c macrowin.c distress.c senddist.c
FEATURE_OBJS = feature2.o feature.o macrowin.o distress.o senddist.o
#endif

#if BeepLite
BEEPLITE_SRCS = beeplite.c
BEEPLITE_OBJS = beeplite.o
#endif

#if Dashboard
DASHBOARD_SRCS = dashboard.c
DASHBOARD_OBJS = dashboard.o
#endif

#if ShortPackets
SP_SRCS = spwarning.c
SP_OBJS = spwarning.o
#endif

#if Metawindow
META_SRCS = parsemeta.c
META_OBJS = parsemeta.o
#endif

#if MakeXtrekrc
MAKE_XTREKRC_SRCS = make_xtrekrc.c
MAKE_XTREKRC_OBJS = make_xtrekrc.o
#endif

#ifdef ShipBitmaps 
SHIP_BITMAPS_SRCS = shipbitmaps.c
SHIP_BITMAPS_OBJS = shipbitmaps.o
#endif

SRCS = colors.c data.c death.c defaults.c defwin.c detonate.c dmessage.c \
       enter.c entrywin.c findslot.c getdefaults.c getname.c \
       getship.c helpwin.c inform.c input.c interface.c lagmeter.c \
       main.c netstat.c newwin.c option.c ping.c pingstats.c planetlist.c \
       planets.c playerlist.c ranklist.c redraw.c reserved.c rotate.c sintab.c \
       smessage.c socket.c stats.c udpopt.c util.c war.c \
       warning.c x11window.c $(DYN_SRCS) $(BD_SRCS) $(SPTEST_SRCS) $(RSA_SRCS) \
       $(RAND_SRCS) $(RINT_SRCS) $(FEATURE_SRCS) $(SP_SRCS) $(DASHBOARD_SRCS) \
       $(META_SRCS) $(MAKE_XTREKRC_SRCS) $(SHIP_BITMAPS_SRCS) $(BEEPLITE_SRCS)


OBJS = colors.o data.o death.o defaults.o defwin.o detonate.o dmessage.o \
       enter.o entrywin.o findslot.o getdefaults.o getname.o \
       getship.o helpwin.o inform.o input.o interface.o lagmeter.o \
       main.o netstat.o newwin.o option.o ping.o pingstats.o planetlist.o \
       planets.o playerlist.o ranklist.o redraw.o reserved.o rotate.o sintab.o \
       smessage.o socket.o stats.o udpopt.o util.o war.o \
       warning.o x11window.o $(RAND_OBJS) $(RINT_OBJS) $(DYN_OBJS) $(BD_OBJS) \
       $(SPTEST_OBJS) $(RSA_OBJS) $(FEATURE_OBJS) $(SP_OBJS) $(DASHBOARD_OBJS) \
       $(META_OBJS) $(MAKE_XTREKRC_OBJS) $(SHIP_BITMAPS_OBJS) $(BEEPLITE_OBJS)

AllTarget(randomize)
NormalProgramTarget(randomize,randomize.o $(RAND_OBJS),,,)

#if RSA_
AllTarget(mkkey)
NormalProgramTarget(mkkey,mkkey.o $(RAND_OBJS),,,)

rsa.a :: mkkey
	@echo "**************************************"
	@echo If $(RSA_KEYFILE) does not exist you need to use 'mkkey' to
	@echo create it:
	@echo ./mkkey `basename $(RSA_KEYFILE) .secret` client-type "architecture/OS" creator "comments"
	@echo "**************************************"
	$(RM) rsa_box*.*
	./mkkey -c -k $(RSA_KEYFILE)
	@num=0;\
	CC="$(CC)";\
	AR="$(AR)";\
        EXTRA_DEFINES="$(EXTRA_DEFINES)";\
	MP_INCLUDE="$(MP_INCLUDE)";\
	file="rsa_box.c";\
	objs="rsa_box.o";\
	while [ -f $$file ] ;\
	do\
		echo $$CC $$EXTRA_DEFINES $$MP_INCLUDE -c $$file;\
		`$$CC $$EXTRA_DEFINES $$MP_INCLUDE -c $$file`;\
		rsa_obj="$$rsa_obj $$objs";\
		file="rsa_box_"$$num".c";\
		objs="rsa_box_"$$num".o";\
		num=`expr $$num + 1`;\
        done;\
	echo "Building rsa.a library";\
        echo "$$AR rsa.a $$rsa_obj";\
	`$$AR rsa.a $$rsa_obj`;\
	if [ -f /usr/bin/ranlib -o -f /bin/ranlib ]; \
		then ranlib rsa.a; fi
#endif

AllTarget($(TARGET))
NormalProgramTargetRandomize($(TARGET),$(OBJS),$(RSA_LIB),$(RSA_LIB),,randomize)
InstallProgram($(TARGET),$(NETREK_BIN))
DependTarget()

#ifdef SaberProgramTarget
SaberProgramTarget($(TARGET), $(SRCS), $(OBJS),,)
#endif

/* A test of the effects of putting all code in one file */
NormalProgramTarget(netrektest,BIG.o,,,)

BIG.c: protos.h
	$(RM) allincludes.h
	grep -h "^#include" $(SRCS) > allincludes.h
	cat allincludes.h protos.h $(SRCS) > BIG
	mv BIG BIG.c

protos.h:
	$(RM) protos.h
	cproto -e -f3 -m -D__STDC__ -D_NO_DEPEND -DCPROTO $(EXTRA_DEFINES) $(ALLINCLUDES) $(SRCS) > protos.h

World ::
	$(MAKE) $(MFLAGS) depend
	$(MAKE) $(MFLAGS) all

/* for dec: the -O4 flag doesn't work with -c.  To build netrek, first 
   build randomize, mkkey, and rsa-client.c and then make netrek:

   make randomize mkkey rsa-client.c
   make CDEBUGFLAGS=-O4 netrek.dec
*/

netrek.dec: 
	$(RM) netrek
	$(CC) $(CFLAGS) -o netrek `randomize $(SRCS)` $(LDOPTIONS) $(LDLIBS) \
		$(EXTRA_LOAD_FLAGS)

/* for sgi: the -O4 flag doesn't work with -c.  To build netrek, first 
   build randomize, mkkey, and rsa-client.c and then make netrek:
   note: The default Netrek.tmpl uses -O2

   make randomize mkkey rsa-client.c
   make CDEBUGFLAGS=-O4 netrek.sgi
*/

netrek.sgi: 
	$(RM) netrek
	$(CC) $(CFLAGS) -o netrek `randomize $(SRCS)` $(LDOPTIONS) $(LDLIBS) \
		$(EXTRA_LOAD_FLAGS)

netrek.sun4.static: 
	$(RM) netrek.static
	$(CC) $(CFLAGS) -o netrek.static `randomize $(OBJS)` $(LDOPTIONS) \
	$(STATIC_LINK_FLAG) $(LDLIBS) $(RSA_LIB) $(EXTRA_LOAD_FLAGS) \
	$(EXTRA_LIBRARIES)

dist.tar:
	$(SHELL) sc.dist
	
dist.bin:
	$(SHELL) sc.dist.bin



