#
# Makefile for ViZiGO, a frontend for go games servers and engines
#
# (C) May 2000 Vincent Penne
#

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

# you must create a conf.linux.makefile that defines fltk_prefix to the correct value
# for your system ... (see exemples below)
#fltk_prefix =	./fltk/
#fltk_prefix =	/home/cptpc24/penne/c/fltk-cvs/fltk/
#fltk_prefix =	/home/zig/c/fltk-cvs/fltk/

##################################################
# -----------------------------------------------------------------------------
# Lua config
# -----------------------------------------------------------------------------

#LUA-BIND	= 1

ifeq ($(LUA-BIND),1)
LUA5PATH	= /home/zig/Dev/srtti/test-lua5/lua
LUA_CXXFLAGS	= -DLUA5
LUA_CXXFLAGS	+= -I$(LUA5PATH)/include
LUA_LDPATH	+= -L$(LUA5PATH)/lib
LUA_LIBS	= bind/lua5-vizigo.a $(LUA_LDPATH) -llua -llualib
endif

##################################################
# -----------------------------------------------------------------------------
# Try to guess the target
# -----------------------------------------------------------------------------

WIN32	=	$(shell ld --version | grep i386pe | sed s/i386pe/1/ | sed s/\ *//)
LINUX	=	$(shell ld --version | grep i386linux | sed s/i386linux/1/ | sed s/\ *//)

##################################################
# -----------------------------------------------------------------------------
# Target specific options
# -----------------------------------------------------------------------------

ifeq ($(WIN32),1)
CFLAGS		+=	-DWIN32_LEAN_AND_MEAN
CCFLAGS		+=	-DWIN32_LEAN_AND_MEAN
target		= vizigo.exe
objsuf		= .ow32
include conf.win32.makefile
else
ifeq ($(LINUX),1)
target		= vizigo
objsuf		= .o
include conf.linux.makefile
else
target		= vizigo
objsuf		= .o
include conf.generic.makefile
endif
endif

# WARNING : this is temporary fix for my strange real time kernel ...
ifeq ($(STRANGE_KERNEL),1)
CFLAGS		+=	-DSTRANGE_KERNEL
CCFLAGS		+=	-DSTRANGE_KERNEL
endif

# WARNING : personal usage only
ifeq ($(SEBOGO),1)
CFLAGS		+=	-DSEBOGO
CCFLAGS		+=	-DSEBOGO
endif

fluid =		$(fltk_prefix)fluid/fluid

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

LIBS = 		$(LUA_LIBS) `$(fltk_prefix)fltk-config --multithread --ldstaticflags` -lm

CC =		c++
LD =		c++
CCFLAGS +=	`$(fltk_prefix)fltk-config --multithread --cflags` -g -c $(INC) $(CCExtra) $(LUA_CXXFLAGS)
LDFLAGS =	-g $(LIBS)

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

sources =	vizigo.cxx drawStone.cxx FlCells.cxx stone.cxx \
		Fl_RGBM_Image.cxx board.cxx story.cxx sgf.cxx igs.cxx \
		connection.cxx talk.cxx igsgame.cxx game_browser.cxx \
		binsert.cxx igsplayer.cxx FlTextOutput.cxx \
		player_browser.cxx proposegame.cxx Fl_Bool_Output.cxx \
		channels.cxx debug.cxx results_browser.cxx options.cxx \
		moves_browser.cxx observer_browser.cxx stored_browser.cxx
objects =	$(sources:.cxx=$(objsuf))

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

all :		$(target)

$(target) :	$(objects)
ifeq ($(LUA-BIND),1)
	make -C bind
endif
	$(LD) -o $(target) $(objects) $(LDFLAGS)

readlog :	readlog.c
	gcc -g -o readlog readlog.c

.PHONY:	doc
doc:	$(sources)
	@mkdir -p doc/html
	@doxygen
	@cp images/logo.png doc/html
	@cp images/slogo.png doc/html

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

.SUFFIXES: $(objsuf) .c .cxx .s .fl .C

.c$(objsuf): 
	$(CC) $(CCFLAGS) -o $@ $<

.cxx$(objsuf):
	$(CC) $(CCFLAGS) -o $@ $<

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

.PHONY: clean
clean:
	rm -f $(target) $(objects) readlog

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

.PHONY: depend
depend:
	@makedepend -f makedepend $(sources) 2> /dev/null

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

.PHONY: release
release: $(target)
ifeq ($(WIN32),1)
	rm -rf vizigo.win32
	mkdir vizigo.win32
	cp $(target) vizigo.win32
	cp vizigorc.example vizigo.win32/vizigo.options.example.txt
	cp README vizigo.win32/README.txt
	cp LICENSE vizigo.win32/LICENSE.txt
	cp CHANGELOG vizigo.win32/CHANGELOG.txt
	strip vizigo.win32/$(target)
	zip -r vizigo.win32.zip vizigo.win32
else
	rm -rf vizigo.linux
	mkdir vizigo.linux
	cp $(target) LICENSE vizigorc.example README CHANGELOG vizigo.linux
	strip vizigo.linux/$(target)
	tar zcf vizigo.linux.tgz vizigo.linux
endif

include makedepend
