###############################################################################
#
# $Id: Makefile,v 1.11 1998/10/19 22:07:59 chris Exp $
#
# $Log: Makefile,v $
# Revision 1.11  1998/10/19 22:07:59  chris
# added "$(CDEFS.$(ARCH))", additional architecture dependent
# configuration
#
# Revision 1.10  1998/10/18 02:17:02  chris
# some cross-platform enhancements; removed old history log
#

# architecture (x86 and alpha is known to work)
ARCH := $(shell uname -m | sed -e s/i.86/x86/ | sed -e s/i86pc/x86/)

# operating system (linux is working well; netbsd, solaris is working w/o sound)
OSTYPE := $(shell uname -s | tr A-Z a-z)

# subdirectory where the objects will be stored
O=	$(OSTYPE).$(ARCH)

#*********************** START OF CONFIGURATION SECTION **********************#

# used compiler
CC= gcc

# platform definitions
CDEFS.linux=-DUNIX -DHAVE_ALLOCA_H -DNEED_SHMGETEVENTBASE -DHAVE_MATH_H \
	    -DHAVE_VALUES_H -DLINUX_MOUSE -DLINUX_SOUND
CDEFS.netbsd=-DUNIX -DNEED_SHMGETEVENTBASE -DHAVE_MATH_H -I/usr/X11R6/include \
	     -DAOUT_ASM
CDEFS.sunos=-DUNIX -DHAVE_MATH_H -I /usr/openwin/include
CDEFS.osf1=-DUNIX -DHAVE_MATH_H -DHAVE_ALLOCA_H -DHAVE_VALUES_H

CDEFS.alpha=-DNO_UNALIGNED
CDEFS.x86=

OPT.x86=-m486 -malign-jumps=2 -malign-functions=2 #-pipe
OPT.alpha=-mcpu=21064

# compiler debug flags, comment these out if you won't do debugging
CFLAGS= -g -Wall $(CDEFS.$(OSTYPE)) $(CDEFS.$(ARCH))

# compiler production flags, uncomment these if you won't do debugging
#CFLAGS= -s -O2 -Wall -Wno-unused -Wno-uninitialized -ffast-math \
#	$(CDEFS.$(OSTYPE)) -finline-functions -fomit-frame-pointer \
#	-fstrength-reduce -fexpensive-optimizations -funroll-loops  \
#	$(OPT.$(ARCH)) -$(CDEFS.$(ARCH))

# uncomment this if you will build GGI version of doom (gdoom).
#CFLAGS+= -D_REENTRANT

# include sound fx (sndserver) support
CFLAGS+= -DSNDSERV

# include background music (musserver) support
CFLAGS+= -DMUSSERV

# ignore demos from different game versions and play them, may introduce crash
#CFLAGS+= -DALLDEMOS

# Comment this out if you don't want optimised ix86 assembly fixed point
# functions to be built into doom executable, instead of the ones written
# in C. The differences are following:
# - assembly version: introduces somewhat smoother background shifting
#                     noticeable with SVGALib version of doom, eats more CPU
#                     time than C-version, works only on ix86 CPUs
# - C version: less CPU load, portable, but background shifting is less
#              smooth.
ifeq (x86,$(ARCH))
ifneq (sunos,$(OSTYPE))
CFLAGS+= -DUSEASM
endif
endif

# include support for IP/UDP protocol networking (all platforms)
CFLAGS+= -DUDP_PROTOCOL

# include support for IPX protocol networking (Linux only)
#CFLAGS+= -DIPX_PROTOCOL

# additional paths for where to search system libraries
#LDFLAGS= -lsocket -lnsl  # solaris
LDFLAGS=

# additional paths for where to search X libraries
#X_LDFLAGS= -L/usr/openwin/lib -Wl,-R,/usr/openwin/lib # solaris
X_LDFLAGS= -L/usr/X11R6/lib

#************************ END OF CONFIGURATION SECTION ***********************#

X11LIBS= -lXext -lX11
VGALIBS= -lvga
GGILIBS= -lggi

ifeq (alpha,$(ARCH))
CFLAGS+= -D__64BIT__
endif
ifeq (x86,$(ARCH))
CFLAGS+= -D__32BIT__
endif

OBJS=	$(O)/am_map.o \
	$(O)/doomdef.o \
	$(O)/doomstat.o \
	$(O)/dstrings.o \
	$(O)/d_items.o \
	$(O)/d_main.o \
	$(O)/d_net.o \
	$(O)/f_finale.o \
	$(O)/f_wipe.o \
	$(O)/g_game.o \
	$(O)/hu_stuff.o \
	$(O)/hu_lib.o \
	$(O)/info.o \
	$(O)/i_main.o \
	$(O)/i_net.o \
	$(O)/i_sound.o \
	$(O)/i_system.o \
	$(O)/m_menu.o \
	$(O)/m_misc.o \
	$(O)/m_argv.o \
	$(O)/m_bbox.o \
	$(O)/m_cheat.o \
	$(O)/m_fixed.o \
	$(O)/m_random.o \
	$(O)/m_swap.o \
	$(O)/p_ceilng.o \
	$(O)/p_doors.o \
	$(O)/p_enemy.o \
	$(O)/p_floor.o \
	$(O)/p_inter.o \
	$(O)/p_lights.o \
	$(O)/p_map.o \
	$(O)/p_maputl.o \
	$(O)/p_mobj.o \
	$(O)/p_plats.o \
	$(O)/p_pspr.o \
	$(O)/p_saveg.o \
	$(O)/p_setup.o \
	$(O)/p_sight.o \
	$(O)/p_spec.o \
	$(O)/p_switch.o \
	$(O)/p_telept.o \
	$(O)/p_tick.o \
	$(O)/p_user.o \
	$(O)/r_bsp.o \
	$(O)/r_data.o \
	$(O)/r_draw.o \
	$(O)/r_main.o \
	$(O)/r_plane.o \
	$(O)/r_segs.o \
	$(O)/r_sky.o \
	$(O)/r_things.o \
	$(O)/sounds.o \
	$(O)/st_lib.o \
	$(O)/st_stuff.o \
	$(O)/s_sound.o \
	$(O)/tables.o \
	$(O)/v_video.o \
	$(O)/w_wad.o \
	$(O)/wi_stuff.o \
	$(O)/z_zone.o

ifeq (USEASM,$(findstring USEASM,$(CFLAGS)))
	OBJS += $(O)/fpfunc.o
endif
ifeq (UDP_PROTOCOL,$(findstring UDP_PROTOCOL,$(CFLAGS)))
	OBJS += $(O)/i_udp.o
endif
ifeq (IPX_PROTOCOL,$(findstring IPX_PROTOCOL,$(CFLAGS)))
	OBJS += $(O)/i_ipx.o
endif

all:
	@echo "Choose one of following actions:"
	@echo
	@echo " make x11   - will build $(O)/xdoom - runs under X11"
	@echo " make svga  - will build $(O)/sdoom - runs with SVGALib"
	@echo " make ggi   - will build $(O)/gdoom - runs with libGGI"
	@echo
	@echo " make clean - will clean up $(O) object directory"
	@echo

clean:
	rm -rf $(O)

x11:	dirs $(OBJS) $(O)/i_x11.o
	$(CC) $(CFLAGS) $(X_LDFLAGS) $(LDFLAGS) $(OBJS) $(O)/i_x11.o -o $(O)/xdoom $(X11LIBS)

svga:	dirs $(OBJS) $(O)/i_svga.o
	$(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) $(O)/i_svga.o -o $(O)/sdoom $(VGALIBS)

ggi:	dirs $(OBJS) $(O)/i_ggi.o
	$(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) $(O)/i_ggi.o -o $(O)/gdoom $(GGILIBS)

dirs:
	@if [ ! -d $(O) ]; then rm -f $(O); mkdir $(O); fi

$(O)/%.o: %.c
	$(CC) $(CFLAGS) -c $< -o $@

$(O)/%.o: %.S
	$(CC) $(CFLAGS) -c $< -o $@

#----------------------------------------------------------- end of file ----#
