
# Used to build fat versions of the programe
ifneq (,$(findstring gcc-fat.sh,$(wildcard $(HOME)/projects/*.sh)))
CC := $(HOME)/projects/gcc-fat.sh
endif
ifneq (,$(findstring g++-fat.sh,$(wildcard $(HOME)/projects/*.sh)))
CXX := $(HOME)/projects/g++-fat.sh
endif

OPTIMIZE := -O2
CFLAGS := -g $(OPTIMIZE) -I/usr/local/include $(shell sdl-config --cflags)
CXXFLAGS := $(CFLAGS)
LIBS := $(shell sdl-config --libs) -lSDL_image -lSDL_ttf -lphysfs -lcurl

TARGET := LoneWolf

SOURCES := \
	src/action_chart.cpp \
	src/award.cpp \
	src/button.cpp \
	src/button_maker.cpp \
	src/combat.cpp \
	src/combat_modifier.cpp \
	src/condition.cpp \
	src/condition_types.cpp \
	src/crt.cpp \
	src/disciplines.cpp \
	src/effect.cpp \
	src/effect_types.cpp \
	src/enemy.cpp \
	src/file_sys.cpp \
	src/font_tool.cpp \
	src/fps.cpp \
	src/game.cpp \
	src/gameplay.cpp \
	src/imagetool.cpp \
	src/inv_manager.cpp \
	src/item.cpp \
	src/journal_entry.cpp \
	src/loader.cpp \
	src/LoneWolf.cpp \
	src/main.cpp \
	src/menu.cpp \
	src/menu_func.cpp \
	src/menu_func2.cpp \
	src/menu_stack.cpp \
	src/messagebox.cpp \
	src/my_file.cpp \
	src/progress_bar.cpp \
	src/resize++.cpp \
	src/rnt.cpp \
	src/scrollbar.cpp \
	src/section.cpp \
	src/settings.cpp \
	src/user_input.cpp \
	src/video.cpp \
	src/word.cpp \
	src/globbing.c \
	src/physfsrwops.c

OBJECTS := $(SOURCES:.cpp=.o)
OBJECTS := $(OBJECTS:.c=.o)

$(TARGET): $(OBJECTS)
	$(CXX) -o $@ $^ $(LIBS)

$(TARGET).app: $(TARGET)
	unzip $@.zip
	cp $(TARGET) $@/Contents/MacOS/$(TARGET)
	strip $@/Contents/MacOS/$(TARGET)
	install_name_tool -change `otool -L $(TARGET) | fgrep libSDL-1.2.0.dylib | awk '{print $$1}'` @executable_path/../Frameworks/libSDL-1.2.0.dylib $@/Contents/MacOS/$(TARGET)
	install_name_tool -change `otool -L $(TARGET) | fgrep libSDL_image-1.2.0.dylib | awk '{print $$1}'` @executable_path/../Frameworks/libSDL_image-1.2.0.dylib $@/Contents/MacOS/$(TARGET)
	install_name_tool -change `otool -L $(TARGET) | fgrep libSDL_ttf-2.0.0.dylib | awk '{print $$1}'` @executable_path/../Frameworks/libSDL_ttf-2.0.0.dylib $@/Contents/MacOS/$(TARGET)
	install_name_tool -change `otool -L $(TARGET) | fgrep libphysfs | awk '{print $$1}'` @executable_path/../Frameworks/libphysfs.1.dylib $@/Contents/MacOS/$(TARGET)
	rm -rf $@/Contents/Resources/data/
	cp -r data $@/Contents/Resources/

$(TARGET).dmg: $(TARGET).app
	-mkdir tmp
	mv $(TARGET).app tmp/
	cp README.txt LICENSE.txt tmp/
	hdiutil create -fs HFS+ -srcfolder tmp -volname "Seventh Sense" $@
	$(RM) -r tmp

clean:
	$(RM) $(OBJECTS)

distclean: clean
	$(RM) $(TARGET)
	$(RM) data/books/*/*.zip
	$(RM) data/books/*/covers/*
	$(RM) data/profiles/*.*
	$(RM) settings.txt
	$(RM) -r LoneWolf.app
	$(RM) LoneWolf.dmg

dist: distclean
