#############################################################################
# This file was originally generated with qmake, but has since been heavily
# modified.
#############################################################################

CXX           = g++
DEFINES       = -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -DVER='"$(VER)"'
DEBUG_OPT     = -Os
CXXFLAGS      = $(DEBUG_OPT) -pipe -Wall

INC_PREFIX    = /usr/include
QT_INC_PREFIX = $(INC_PREFIX)/qt4
LUA_INC       = $(INC_PREFIX)/lua5.1
INCLUDES      = -I. -I$(QT_INC_PREFIX)/QtCore -I$(QT_INC_PREFIX)/QtGui -I$(QT_INC_PREFIX) -I$(LUA_INC)
LINK          = $(CXX)
LDFLAGS       =
LIBS          = $(SUBLIBS)  -lQtGui -llua5.1
QMAKE         = /usr/bin/qmake
TAR           = tar -cf
COMPRESS      = gzip -9f
COPY          = cp -f
SED           = sed
COPY_FILE     = $(COPY)
COPY_DIR      = $(COPY) -r
INSTALL_FILE  = install -m 644 -p
INSTALL_DIR   = $(COPY_DIR)
INSTALL_PROGRAM = install -m 755 -p
DEL_FILE      = rm -f
SYMLINK       = ln -sf
DEL_DIR       = rmdir
MOVE          = mv -f
CHK_DIR_EXISTS= test -d
MKDIR         = mkdir -p
EXE_EXT       =
STRIP         = true
VER           = 0.1.x


####### Output directory

OBJECTS_DIR   = ./obj

####### Files

SOURCES = compat.cpp \
		file_handler.cpp \
		lua_handler.cpp \
		lua_interface.cpp \
		main.cpp \
		main_window.cpp
		
HEADERS = compat.h \
		file_handler.h \
		lua_handler.h \
		lua_interface.h \
		main_window.h

OBJECTS       = $(OBJECTS_DIR)/compat.o \
		$(OBJECTS_DIR)/file_handler.o \
		$(OBJECTS_DIR)/lua_handler.o \
		$(OBJECTS_DIR)/lua_interface.o \
		$(OBJECTS_DIR)/main.o \
		$(OBJECTS_DIR)/main_window.o \
		$(OBJECTS_DIR)/moc_main_window.o
TARGET        = gamebook-engine$(EXE_EXT)

GAMEBOOK_FILES = gamebooks/ring-of-thieves.gamebook gamebooks/ring-ot-2p01.zip
GAMEBOOK_DIRS = gamebooks/01fftd/

WINDOWS_ICON_ORIG = gamebook-ico-large.xcf
WINDOWS_RC    = gamebook_engine.rc
WINDOWS_ICON  = gamebook_engine_32x32.ico

####### Build rules

all: $(TARGET)

$(TARGET): $(OBJECTS_DIR) $(OBJECTS)
	$(LINK) $(LDFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
	$(STRIP) $(TARGET)


src-dist:
	# Create tmp source directory
	@$(CHK_DIR_EXISTS) .tmp/gamebook-engine-src-$(VER) || $(MKDIR) .tmp/gamebook-engine-src-$(VER)

	# Copy files from current directory
	$(COPY_FILE) $(SOURCES) $(HEADERS) Makefile* *.nsi $(WINDOWS_ICON) $(WINDOWS_RC) \
	$(WINDOWS_ICON_ORIG) install-linux.sh README .tmp/gamebook-engine-src-$(VER)
	# Copy files from licenses directory
	$(MKDIR) .tmp/gamebook-engine-src-$(VER)/licenses
	$(COPY_FILE) licenses/* .tmp/gamebook-engine-src-$(VER)/licenses
	# Copy files from gamebooks directory (not my testing gamebooks though)
	$(MKDIR) .tmp/gamebook-engine-src-$(VER)/gamebooks/01fftd
	$(COPY_FILE) $(GAMEBOOK_FILES) .tmp/gamebook-engine-src-$(VER)/gamebooks/
	$(COPY_DIR) $(GAMEBOOK_DIRS) .tmp/gamebook-engine-src-$(VER)/gamebooks/

	# tar, gzip, and misc finishing touches
	cd .tmp && tar -cf gamebook-engine-src-$(VER).tar gamebook-engine-src-$(VER) && \
	gzip -9 gamebook-engine-src-$(VER).tar && mv gamebook-engine-src-$(VER).tar.gz .. && \
	rm -rf gamebook-engine-src-$(VER) && cd .. && rmdir .tmp

linux-dist: $(TARGET)
	# Create tmp linux directory
	@$(CHK_DIR_EXISTS) .tmp/gamebook-engine-linux-$(VER) || $(MKDIR) .tmp/gamebook-engine-linux-$(VER)

	# Copy files from current directory
	$(COPY_FILE) $(TARGET) install-linux.sh README .tmp/gamebook-engine-linux-$(VER)
	# Copy files from licenses directory
	$(MKDIR) .tmp/gamebook-engine-linux-$(VER)/licenses
	$(COPY_FILE) licenses/* .tmp/gamebook-engine-linux-$(VER)/licenses
	# Copy files from gamebooks directory (not my testing gamebooks though)
	$(MKDIR) .tmp/gamebook-engine-linux-$(VER)/gamebooks/01fftd
	$(COPY_FILE) $(GAMEBOOK_FILES) .tmp/gamebook-engine-linux-$(VER)/gamebooks/
	$(COPY_DIR) $(GAMEBOOK_DIRS) .tmp/gamebook-engine-linux-$(VER)/gamebooks/

	# tar, gzip, and misc finishing touches
	cd .tmp && tar -cf gamebook-engine-linux-$(VER).tar gamebook-engine-linux-$(VER) && \
	gzip -9 gamebook-engine-linux-$(VER).tar && mv gamebook-engine-linux-$(VER).tar.gz .. && \
	rm -rf gamebook-engine-linux-$(VER) && cd .. && rmdir .tmp

clean:compiler_clean
	-$(DEL_FILE) $(OBJECTS)
	-$(DEL_FILE) *~ core *.core


####### Sub-libraries

distclean: clean
	-$(DEL_FILE) $(TARGET)
	-$(DEL_FILE) Makefile


mocclean: compiler_moc_header_clean compiler_moc_source_clean

mocables: compiler_moc_header_make_all compiler_moc_source_make_all

compiler_moc_header_make_all: moc_main_window.cpp
compiler_moc_header_clean:
	-$(DEL_FILE) moc_main_window.cpp
moc_main_window.cpp: main_window.h
	/usr/bin/moc-qt4 $(DEFINES) $(INCLUDES) main_window.h -o moc_main_window.cpp

compiler_rcc_make_all:
compiler_rcc_clean:
compiler_image_collection_make_all: qmake_image_collection.cpp
compiler_image_collection_clean:
	-$(DEL_FILE) qmake_image_collection.cpp
compiler_moc_source_make_all:
compiler_moc_source_clean:
compiler_uic_make_all:
compiler_uic_clean:
compiler_yacc_decl_make_all:
compiler_yacc_decl_clean:
compiler_yacc_impl_make_all:
compiler_yacc_impl_clean:
compiler_lex_make_all:
compiler_lex_clean:
compiler_clean: compiler_moc_header_clean

$(OBJECTS_DIR):
	$(MKDIR) $(OBJECTS_DIR)

####### Compile

$(OBJECTS_DIR)/compat.o: compat.cpp compat.h
	$(CXX) -c $(CXXFLAGS) $(DEFINES) $(INCLUDES) -o $(OBJECTS_DIR)/compat.o compat.cpp

$(OBJECTS_DIR)/file_handler.o: file_handler.cpp file_handler.h \
		compat.h
	$(CXX) -c $(CXXFLAGS) $(DEFINES) $(INCLUDES) -o $(OBJECTS_DIR)/file_handler.o file_handler.cpp

$(OBJECTS_DIR)/lua_handler.o: lua_handler.cpp lua_handler.h \
		lua_interface.h \
		file_handler.h
	$(CXX) -c $(CXXFLAGS) $(DEFINES) $(INCLUDES) -o $(OBJECTS_DIR)/lua_handler.o lua_handler.cpp

$(OBJECTS_DIR)/lua_interface.o: lua_interface.cpp lua_interface.h \
		lua_handler.h \
		file_handler.h
	$(CXX) -c $(CXXFLAGS) $(DEFINES) $(INCLUDES) -o $(OBJECTS_DIR)/lua_interface.o lua_interface.cpp

$(OBJECTS_DIR)/main.o: main.cpp main_window.h
	$(CXX) -c $(CXXFLAGS) $(DEFINES) $(INCLUDES) -o $(OBJECTS_DIR)/main.o main.cpp

$(OBJECTS_DIR)/main_window.o: main_window.cpp main_window.h \
		lua_handler.h \
		file_handler.h
	$(CXX) -c $(CXXFLAGS) $(DEFINES) $(INCLUDES) -o $(OBJECTS_DIR)/main_window.o main_window.cpp

$(OBJECTS_DIR)/moc_main_window.o: moc_main_window.cpp
	$(CXX) -c $(CXXFLAGS) $(DEFINES) $(INCLUDES) -o $(OBJECTS_DIR)/moc_main_window.o moc_main_window.cpp

####### Install

install:   FORCE

uninstall:   FORCE

FORCE:

