CC = $(MACOSX_CC)
CFLAGS = $(T3F_CFLAGS) $(GLOBAL_CFLAGS) $(MACOSX_ARCHITECTURES) $(MACOSX_COMPILER_SETTINGS) $(MACOSX_SYS_ROOT) $(MACOSX_MIN_VERSION) $(APP_CFLAGS) $(MACOSX_CFLAGS)
CXX = $(MACOSX_CXX)
CXXFLAGS = $(CFLAGS)
LFLAGS = $(MACOSX_LINKER_SETTINGS) $(MACOSX_ARCHITECTURES) $(MACOSX_SYS_ROOT) $(MACOSX_MIN_VERSION)
PLATFORM_OBJECTS = t3f/menu.o $(MACOSX_PLATFORM_OBJECTS)
PLATFORM_LIBS = -framework IOKit -framework AudioToolbox -framework OpenGL -framework OpenAL -framework Cocoa -lallegro_dialog$(LIB_SUFFIX) -lallegro_main-static $(MACOSX_PLATFORM_LIBS)
PLATFORM_TARGET = $(APP_PACKAGE_DIR)/$(APP_TITLE).app
LIB_SUFFIX = -static
DEPEND_LIBS = -lz -lpng -ljpeg -lFLAC -lvorbis -logg -lvorbisfile -ldumb -lfreetype $(MACOSX_DEPEND_LIBS)
DEL_COMMAND = rm -f
DEL_FOLDER_COMMAND = rm -rf
SED_COMMAND = sed -i ''
PLATFORM_CLEAN = rm -rf $(APP_PACKAGE_DIR)/$(APP_TITLE).app
COPY_COMMAND = cp
PATH_SEPARATOR = /

include makefile.common

prepare_platform:
	@echo Ready to build...

../icons/macosx_icon.icns: ../icons/16.png ../icons/32.png ../icons/64.png ../icons/128.png ../icons/256.png ../icons/512.png ../icons/1024.png
	@mkdir -p temp.iconset
	@cp ../icons/16.png temp.iconset/icon_16x16.png
	@cp ../icons/32.png temp.iconset/icon_16x16@2x.png
	@cp ../icons/32.png temp.iconset/icon_32x32.png
	@cp ../icons/64.png temp.iconset/icon_32x32@2x.png
	@cp ../icons/64.png temp.iconset/icon_64x64.png
	@cp ../icons/128.png temp.iconset/icon_64x64@2x.png
	@cp ../icons/128.png temp.iconset/icon_128x128.png
	@cp ../icons/256.png temp.iconset/icon_128x128@2x.png
	@cp ../icons/256.png temp.iconset/icon_256x256.png
	@cp ../icons/512.png temp.iconset/icon_256x256@2x.png
	@cp ../icons/512.png temp.iconset/icon_512x512.png
	@cp ../icons/1024.png temp.iconset/icon_512x512@2x.png
	@iconutil --convert icns temp.iconset -o ../icons/macosx_icon.icns
	@rm -rf temp.iconset

$(APP_PACKAGE_DIR)/$(APP_TITLE).app : $(APP_EXE_NAME) ../icons/macosx_icon.icns
	@$(DEL_FOLDER_COMMAND) $(APP_PACKAGE_DIR)/$(APP_TITLE).app
	@mkdir $(APP_PACKAGE_DIR)/$(APP_TITLE).app
	@mkdir $(APP_PACKAGE_DIR)/$(APP_TITLE).app/Contents
	@mkdir $(APP_PACKAGE_DIR)/$(APP_TITLE).app/Contents/MacOS
	@mkdir $(APP_PACKAGE_DIR)/$(APP_TITLE).app/Contents/Resources
	@mkdir $(APP_PACKAGE_DIR)/$(APP_TITLE).app/Contents/Resources/$(APP_TITLE)
	@cp $(APP_EXE_NAME) $(APP_PACKAGE_DIR)/$(APP_TITLE).app/Contents/MacOS/$(APP_TITLE)
	@cp ../macosx/blobs/* $(APP_PACKAGE_DIR)/$(APP_TITLE).app/Contents/MacOS
	@mv ../icons/macosx_icon.icns $(APP_PACKAGE_DIR)/$(APP_TITLE).app/Contents/Resources/$(APP_TITLE).icns
	@cp -a ../bin/data $(APP_PACKAGE_DIR)/$(APP_TITLE).app/Contents/Resources/$(APP_TITLE)
	@cp -a ../docs $(APP_PACKAGE_DIR)/$(APP_TITLE).app/Contents/Resources/$(APP_TITLE)
	@cp ../macosx/Info.plist $(APP_PACKAGE_DIR)/$(APP_TITLE).app/Contents
	@cp ../macosx/Pkginfo $(APP_PACKAGE_DIR)/$(APP_TITLE).app/Contents
	@sed -i '' "s|T3F_APP_EXECUTABLE|$(APP_TITLE)|" $(APP_PACKAGE_DIR)/$(APP_TITLE).app/Contents/Info.plist
	@sed -i '' "s|T3F_APP_ICON|$(APP_TITLE).icns|" $(APP_PACKAGE_DIR)/$(APP_TITLE).app/Contents/Info.plist
	@sed -i '' "s|T3F_APP_DISPLAY_NAME|$(APP_TITLE)|" $(APP_PACKAGE_DIR)/$(APP_TITLE).app/Contents/Info.plist
	@sed -i '' "s|T3F_APP_VERSION|$(APP_VERSION)|" $(APP_PACKAGE_DIR)/$(APP_TITLE).app/Contents/Info.plist
	@sed -i '' "s|T3F_APP_PACKAGE|$(APP_ANDROID_PACKAGE)|" $(APP_PACKAGE_DIR)/$(APP_TITLE).app/Contents/Info.plist
	@echo Application bundle created!

mac_package: $(APP_PACKAGE_DIR)/$(APP_TITLE).app
	rm -rf $(APP_PACKAGE_DIR)/$(APP_PACKAGE_NAME)-macosx.dmg
	../macosx/create-dmg --volname $(APP_TITLE) --volicon $(APP_PACKAGE_DIR)/$(APP_TITLE).app/Contents/Resources/$(APP_TITLE).icns --window-size 400 232 --icon-size 96 --icon "$(APP_TITLE)" 110 100 --app-drop-link 280 100 $(APP_PACKAGE_DIR)/$(APP_PACKAGE_NAME)-macosx.dmg $(APP_PACKAGE_DIR)/$(APP_TITLE).app
