# 
# if you want to compile ggihexen say `yes' 
# then if you enter `make' will be compiled hexen and ggihexen
# if you want only one of them type `make nameoffile'
BUILD_GGI=yes
BUILD_x11=yes
#
#If you have i386-architecutre Linux box  uncomment this
ARCH=x86

AS=as
CC=gcc
CCOPT=-Wall -O2
LIBS=-lvga
GGILIB=-lggi
XLIB=-lXext -lX11

OBJS=a_action.o \
am_map.o \
ct_chat.o \
d_net.o \
f_finale.o \
g_game.o \
h2_main.o \
i_cdmus.o \
i_ipx.o \
i_net.o \
i_udp.o \
i_sound.o \
in_lude.o \
info.o \
mn_menu.o \
p_acs.o \
p_anim.o \
p_ceilng.o \
p_doors.o \
p_enemy.o \
p_floor.o \
p_inter.o \
p_lights.o \
p_map.o \
p_maputl.o \
p_mobj.o \
p_plats.o \
p_pspr.o \
p_setup.o \
p_sight.o \
p_spec.o \
p_switch.o \
p_telept.o \
p_things.o \
p_tick.o \
p_user.o \
po_man.o \
r_bsp.o \
r_data.o \
r_draw.o \
r_main.o \
r_plane.o \
r_segs.o \
r_things.o \
sb_bar.o \
sc_man.o \
sn_sonix.o \
sounds.o \
soundst.o \
st_start.o \
sv_save.o \
tables.o \
template.o \
w_wad.o \
z_zone.o
ifeq ($(BUILD_GGI),yes)
GGI_OBJ=i_ggi.oG i_startup.oG i_ibm.oG m_misc.oG v_video.oG
GGI_OPT=$(CCOPT) -DGGI_HEXEN
else
GGI_OBJ=
GGI_OPT=
endif
ifeq ($(BUILD_x11),yes)
x11_OBJ=i_x11.o i_startup.oG i_ibm.oG m_misc.oG v_video.oG
GGI_OPT=$(CCOPT) -DGGI_HEXEN
else
x11_OBJ=
GGI_OPT=
endif

ifeq ($(ARCH),x86)
ASMOBJS=fixedop.o
else
ASMOBJS=
endif

VGA_OBJ=i_startup.o i_ibm.o m_misc.o v_video.o 

all:    .depend sound $(OBJS) hexen ggihexen xhexen
hexen:  .depend $(OBJS) $(ASMOBJS) $(VGA_OBJ) 
	$(CC) $(CCOPT) $(LIBS) $(OBJS) $(ASMOBJS) $(VGA_OBJ) -o $@ 
	strip $@
	chmod u+s $@
xhexen: $(OBJS) $(ASMOBJS) $(x11_OBJ)
ifeq ($(BUILD_x11),yes)
	$(CC) $(CCOPT) $(XLIB) -L/usr/local/X11R6/lib $(ASMOBJS) $(OBJS) $(x11_OBJ) -o $@ 
	strip $@
endif

ggihexen: $(OBJS) $(ASMOBJS) $(GGI_OBJ) 
ifeq ($(BUILD_GGI),yes)
	$(CC) $(CCOPT) $(GGILIB)  $(ASMOBJS) $(OBJS) $(GGI_OBJ) -o $@ 
	strip $@
endif
sound:  musserver sndserver

musserver: 
	$(MAKE) -C musserv $@

sndserver: 
	$(MAKE) -C sndserv $@

.depend:	
	$(CC) -E -M $(CCOPT) *.c >.depend
%.o:	%.asm
	$(AS) -o $@ $<
%.o: 	%.c
	$(CC) $(CCOPT) -c $< -o $@
%.oG: 	%.c
ifeq ($(BUILD_GGI),yes)
	$(CC) $(GGI_OPT) -c $< -o $@
endif
clean:	
	rm -f *.o hexen ggihexen .depend

ifeq (.depend,$(wildcard .depend))
include .depend
endif