#!/bin/make -f 
#
#  L&L - Labyrinths & Legends
#        Copyright (C) 1993- 2003 YOSHIMURA Tomohiko
#        bowkenken@users.sourceforge.jp
#

SHELL = sh

TRGT = lnl
INSTALL_DIR = /usr/games
MAKEFILE = Makefile

#### Debug options ####

# Release
DEBUG = -DNDEBUG
SRC_CODE_DB =

DEBUG_BEGIN = \#--DEBUG BEGIN--
DEBUG_END = \#--DEBUG END--

#--DEBUG BEGIN--
#DEBUG = -DD_TEST_TRAP
#DEBUG =
#SRC_CODE_DB = -g
#--DEBUG END--

#### Macros ####

#D_UNIX
#D_X68K
#D_CLK_TCK
#D_USE_CURSES
#D_USE_TERMIOS
#D_USE_TC_ATTR
#D_USE_IOCTL
#D_USE_SLEEP
#D_DEF_MKDIR
#D_TEST_TRAP

# For linux
CC = gcc

CLK_TCK = -DD_CLK_TCK=1000000L
#CLK_TCK =
CDEFS = $(DEBUG) $(SRC_CODE_DB) -DD_UNIX -DD_USE_CURSES \
		-DD_USE_TERMIOS -DD_USE_TC_ATTR \
		-DD_USE_SLEEP $(CLK_TCK)
CFLAGS = -o $@ -O -c -Wall -Werror $(SRC_CODE_DB) $(CDEFS) $<
LD = gcc
LIBS = 
CURSES = -lcurses -ltermcap
LDFLAGS = -o $@ $^

#### Lib & obj ####

LDLIBS = $(LIBS) $(CURSES)
OBJS = amenu.o curs.o dun.o fx.o gmain.o menu.o msg.o spell.o town.o \
		chr.o draw.o fight.o gfile.o item.o \
		mnstr.o party.o tmenu.o trap.o

#### Message ####

MSG_H = msg.h
MSGS = msg_jpn.h msg_eng.h

#### Misc ####

MM = -MM *.c

TMP = /tmp/$(TRGT)-tmp$$$$
DIVIDE_MARK = \#\#\#\# --- END --- \#\#\#\#
NEW_LINE = @echo
ECHO_OK = @ $(NEW_LINE) ; echo "- OK -"

################################

all: $(MSG_H) $(TRGT)
	$(ECHO_OK)

$(TRGT): $(OBJS)
	$(LD) $(LDFLAGS) $(LDLIBS)

$(MSG_H): $(MSGS)
	./msg_def

install:
	cp $(TRGT) $(INSTALL_DIR)/
	$(ECHO_OK)

clean:
	-rm -f *.o core* a.out
	$(ECHO_OK)

clobber:
	rm -f *.o core* a.out $(TRGT)
	rm -f $(INSTALL_DIR)/$(TRGT)
	$(ECHO_OK)

mm:
	sed -e "/^$(DIVIDE_MARK)$$/q" $(MAKEFILE) > $(TMP) ;\
	mv -f $(TMP) $(MAKEFILE)
	$(CC) $(CDEFS) $(MM) >> $(MAKEFILE)
	$(ECHO_OK)

rel: release

release:
	sed -e "/^$(DEBUG_BEGIN)$$/,/^$(DEBUG_END)$$/s/^\([^#]\)/#\1/" \
		$(MAKEFILE) > $(TMP) ;\
	mv -f $(TMP) $(MAKEFILE)
	make clean
	make

%.o: %.c
	$(CC) $(CFLAGS)
	$(NEW_LINE)

#### --- END --- ####
amenu.o: amenu.c gmain.h menu.h msg.h party.h chr.h dun.h curs.h fx.h \
  fight.h item.h spell.h mnstr.h trap.h draw.h gmain_prot.h dun_prot.h \
  item_prot.h chr_prot.h party_prot.h mnstr_prot.h draw_prot.h \
  menu_prot.h amenu_prot.h
chr.o: chr.c gmain.h item.h spell.h msg.h mnstr.h chr.h dun.h curs.h fx.h \
  fight.h trap.h party.h draw.h menu.h gmain_prot.h dun_prot.h \
  item_prot.h spell_prot.h chr_prot.h party_prot.h mnstr_prot.h \
  fight_prot.h fx_prot.h trap_prot.h draw_prot.h amenu_prot.h
curs.o: curs.c gmain.h draw.h menu.h msg.h party.h chr.h dun.h curs.h \
  fx.h fight.h item.h spell.h mnstr.h trap.h gmain_prot.h curs_prot.h
draw.o: draw.c gmain.h town.h dun.h curs.h msg.h draw.h menu.h party.h \
  chr.h fx.h fight.h item.h spell.h mnstr.h trap.h gmain_prot.h \
  dun_prot.h chr_prot.h party_prot.h mnstr_prot.h fight_prot.h \
  draw_prot.h curs_prot.h menu_prot.h tmenu_prot.h msg_prot.h draw_tab.h
dun.o: dun.c gmain.h dun.h curs.h msg.h town.h item.h spell.h mnstr.h \
  chr.h fx.h fight.h trap.h menu.h party.h draw.h gmain_prot.h dun_prot.h \
  town_prot.h item_prot.h chr_prot.h party_prot.h mnstr_prot.h fx_prot.h \
  trap_prot.h draw_prot.h curs_prot.h menu_prot.h gfile_prot.h dun_tab.h \
  crsr_ptn.h
fight.o: fight.c gmain.h item.h spell.h msg.h mnstr.h chr.h dun.h curs.h \
  fx.h fight.h trap.h draw.h menu.h party.h gmain_prot.h dun_prot.h \
  item_prot.h chr_prot.h mnstr_prot.h fight_prot.h fx_prot.h trap_prot.h \
  draw_prot.h
fx.o: fx.c gmain.h item.h spell.h msg.h mnstr.h chr.h dun.h curs.h fx.h \
  fight.h trap.h party.h draw.h menu.h gmain_prot.h dun_prot.h \
  item_prot.h spell_prot.h chr_prot.h party_prot.h mnstr_prot.h \
  fight_prot.h fx_prot.h trap_prot.h draw_prot.h menu_prot.h
gfile.o: gfile.c gmain.h town.h dun.h curs.h msg.h menu.h party.h chr.h \
  fx.h fight.h item.h spell.h mnstr.h trap.h draw.h gmain_prot.h \
  dun_prot.h town_prot.h draw_prot.h menu_prot.h gfile_prot.h
gmain.o: gmain.c gmain.h menu.h msg.h party.h chr.h dun.h curs.h fx.h \
  fight.h item.h spell.h mnstr.h trap.h draw.h town.h ver.h gmain_prot.h \
  dun_prot.h menu_prot.h town_prot.h tmenu_prot.h amenu_prot.h \
  spell_prot.h draw_prot.h curs_prot.h chr_prot.h party_prot.h \
  item_prot.h mnstr_prot.h fight_prot.h fx_prot.h trap_prot.h \
  gfile_prot.h msg_prot.h
item.o: item.c gmain.h item.h spell.h msg.h mnstr.h chr.h dun.h curs.h \
  fx.h fight.h trap.h draw.h menu.h party.h gmain_prot.h dun_prot.h \
  item_prot.h chr_prot.h party_prot.h mnstr_prot.h fx_prot.h trap_prot.h \
  draw_prot.h amenu_prot.h item_tab.h
menu.o: menu.c gmain.h town.h dun.h curs.h msg.h spell.h menu.h party.h \
  chr.h fx.h fight.h item.h mnstr.h trap.h draw.h gmain_prot.h dun_prot.h \
  item_prot.h spell_prot.h chr_prot.h party_prot.h mnstr_prot.h fx_prot.h \
  trap_prot.h draw_prot.h curs_prot.h menu_prot.h amenu_prot.h \
  gfile_prot.h menu_tab.h
mnstr.o: mnstr.c gmain.h item.h spell.h msg.h mnstr.h chr.h dun.h curs.h \
  fx.h fight.h trap.h draw.h menu.h party.h gmain_prot.h dun_prot.h \
  item_prot.h chr_prot.h party_prot.h mnstr_prot.h fight_prot.h fx_prot.h \
  draw_prot.h mnstr_tab.h
msg.o: msg.c gmain.h draw.h menu.h msg.h party.h chr.h dun.h curs.h fx.h \
  fight.h item.h spell.h mnstr.h trap.h gmain_prot.h draw_prot.h \
  msg_eng.h ver.h msg_jpn.h
party.o: party.c gmain.h town.h dun.h curs.h msg.h item.h spell.h mnstr.h \
  chr.h fx.h fight.h trap.h menu.h party.h draw.h gmain_prot.h dun_prot.h \
  town_prot.h item_prot.h spell_prot.h chr_prot.h party_prot.h \
  mnstr_prot.h fight_prot.h fx_prot.h trap_prot.h draw_prot.h menu_prot.h \
  amenu_prot.h class_tab.h
spell.o: spell.c gmain.h spell.h msg.h menu.h party.h chr.h dun.h curs.h \
  fx.h fight.h item.h mnstr.h trap.h draw.h gmain_prot.h dun_prot.h \
  item_prot.h chr_prot.h party_prot.h mnstr_prot.h fx_prot.h trap_prot.h \
  draw_prot.h menu_prot.h spell_tab.h spell_prot.h
tmenu.o: tmenu.c gmain.h town.h dun.h curs.h msg.h item.h spell.h mnstr.h \
  chr.h fx.h fight.h trap.h menu.h party.h draw.h gmain_prot.h dun_prot.h \
  town_prot.h item_prot.h chr_prot.h party_prot.h fx_prot.h draw_prot.h \
  menu_prot.h gfile_prot.h tmenu_tab.h tmenu_prot.h
town.o: town.c town.h dun.h gmain.h curs.h msg.h item.h spell.h mnstr.h \
  chr.h fx.h fight.h trap.h menu.h party.h draw.h gmain_prot.h dun_prot.h \
  town_prot.h item_prot.h chr_prot.h party_prot.h fx_prot.h draw_prot.h \
  tmenu_prot.h gfile_prot.h town_ptn.xpm town_tab.h
trap.o: trap.c gmain.h dun.h curs.h msg.h item.h spell.h mnstr.h chr.h \
  fx.h fight.h trap.h draw.h menu.h party.h gmain_prot.h dun_prot.h \
  chr_prot.h fx_prot.h trap_prot.h draw_prot.h
