# Makefile for Mortar sources
#
# This is free software; you can redistribute it and/or modify it
# under the terms specified in the GNU Public Licence (GPL).
#
# Copyright (C) 1998-2002,2005,2008 by Eero Tamminen

# DEBUG enables a few extra sanity checks (yes/no)
DEBUG ?= no

CPPFLAGS = -DMAEMO=$(MAEMO)
ifeq ($(DEBUG),yes)
  CPPFLAGS += -DDEBUG
endif
  
CFLAGS ?= -O2 -g -Wall -Wmissing-prototypes -Wstrict-prototypes \
  -Wsign-compare -Wbad-function-cast -Wcast-qual -Wpointer-arith \
  -Wwrite-strings -Wshadow -Wcast-align -Werror

# if you have libz and enough memory, the image files
# can be optionally compressed on the disk.  If this
# is not set to '-lz', check that image files in data/
# directory been gunzipped and image names config.def
# have been changed accordingly!!!
ZLIBS	= -lz

ifeq ($(SOUND),sdl)
  SOUNDLIBS = -lSDL_mixer
endif
ifeq ($(SOUND),gsi)
  SOUNDLIBS = -lgsi
endif

LDFLAGS	+= $(SOUNDLIBS) $(ZLIBS)

# extra, target specific libs
WLIBS	= -lW
XWLIBS  = -lW2X -L/usr/X11R6/lib -lX11
GGILIBS	= -lggi
SDLLIBS = -lSDL #-lpthread
ALIBS	= -lrtgm -lmieee

ifeq ($(NAME),amortar)
  # AmigaOS 68k
  CC		= vc
  CFLAGS	= -O2 -DAMIGA -Dinline=
else
  CC		= gcc
  ifneq ($(NAME),mortar.exe)
    # generic unix, not DOS DJGPP
    ifeq ($(DEBUG),yes)
      LDFLAGS += -lefence
    endif
  endif
endif


RM	= rm -f

# ----- end of editable part ------------

OBJS	= main.o intro.o game.o list.o user.o image.o range.o tank.o \
	  shot.o ammo.o shield.o util.o font.o scale.o screen.o \
	  color.o map.o frame.o message.o config.o qtrig.o random.o

# with Zlib, read image files as they were gzip compressed
ifeq ($(ZLIBS),-lz)
  OBJS += pbm-z.o
else
  OBJS+= pbm.o
endif


# use snd-none.c for no sound
TOBJS	= win-tos.o snd-$(SOUND).o
DOBJS	= win-dos.o snd-$(SOUND).o
POBJS	= win-pilot.o snd-$(SOUND).o
GGIOBJS	= win-ggi.o snd-$(SOUND).o
SDLOBJS	= win-sdl.o snd-$(SOUND).o
FBOBJS  = win-lfb.o snd-$(SOUND).o
WOBJS	= win-w.o snd-$(SOUND).o
AOBJS	= win-rtgm.o snd-$(SOUND).o amiga.o

all: $(NAME)


wmortar: $(OBJS) $(WOBJS)
	$(CC) -o $@ $(OBJS) $(WOBJS) $(LDFLAGS) $(WLIBS)

xwmortar: $(OBJS) $(WOBJS)
	$(CC) -o $@ $(OBJS) $(WOBJS) $(LDFLAGS) $(XWLIBS)

pmortar: $(OBJS) $(POBJS)
	$(CC) -o $@ $(OBJS) $(POBJS) $(LDFLAGS)

fbmortar: $(OBJS) $(FBOBJS)
	$(CC) -o $@ $(OBJS) $(FBOBJS) $(LDFLAGS)

ggimortar: $(OBJS) $(GGIOBJS)
	$(CC) -o $@ $(OBJS) $(GGIOBJS) $(LDFLAGS) $(GGILIBS)

sdlmortar: $(OBJS) $(SDLOBJS)
	$(CC) -o $@ $(OBJS) $(SDLOBJS) $(LDFLAGS) $(SDLLIBS)

mortar.exe: $(OBJS) $(DOBJS)
	$(CC) -o $@ -s $(OBJS) $(DOBJS) $(LDFLAGS)

mortar.ttp: $(OBJS) $(TOBJS)
	$(CC) -o $@ -s $(OBJS) $(TOBJS) $(LDFLAGS)

amortar: $(OBJS) $(AOBJS)
	$(CC) -o $@ $(OBJS) $(AOBJS) $(LDFLAGS) $(ALIBS)


$(OBJS): mortar.h


# ---------------

data: mortar.h
	$(MAKE) -C utils install

# simple code metrics ;-)
metrics:
	wc Makefile utils/Makefile utils/*.pov utils/*.[ch] *.[ch]

# ---------

clean:
	$(MAKE) -C utils clean
	$(RM) *.o *~
