include $(GNUSTEP_MAKEFILES)/common.make
APP_NAME=Grouch
SUBPROJECTS=Core Oscar

RELATIVE_PATH=../
include $(RELATIVE_PATH)cflags.mak
ADDITIONAL_OBJCFLAGS += -IHeaders

ifeq ($(FOUNDATION_LIB), apple)
ADDITIONAL_GUI_LIBS += -framework Renaissance
shared_grouch_core=yes
else
ADDITIONAL_GUI_LIBS += -lRenaissance
endif

ifeq ($(shared_grouch_core), yes)
ADDITIONAL_OBJC_LIBS += -LCore/obj -lGrouchCore
else
ADDITIONAL_OBJC_LIBS += $(shell find Core -name *.o)
endif

$(APP_NAME)_RESOURCE_FILES += $(shell echo PropertyLists/*.plist)
$(APP_NAME)_RESOURCE_FILES += $(shell echo WindowSpecs/*.gsmarkup)
$(APP_NAME)_RESOURCE_FILES += $(shell echo *.lproj)
$(APP_NAME)_RESOURCE_FILES += $(shell find . -name *.bundle)
$(APP_NAME)_LANGUAGES	   += $(shell (for i in $(shell echo *.lproj); do \
				echo $$i; done) | sed s/\\.lproj$$//)

# We're going to be annoying and put documentation in Resources.
# That way if some poor soul distributes just the .app without source
# (Mac users, I'm looking at you) they can still find out what the project
# is all about.
$(APP_NAME)_RESOURCE_FILES += $(RELATIVE_PATH)README $(RELATIVE_PATH)Copying.rtf

$(APP_NAME)_APPLICATION_ICON = $(APP_NAME).tiff
$(APP_NAME)_RESOURCE_FILES += $($(APP_NAME)_APPLICATION_ICON)
$(APP_NAME)_RESOURCE_FILES += $(APP_NAME).icns

$(APP_NAME)_OBJC_FILES = $(shell echo *.m)

ifeq ($(FOUNDATION_LIB), apple)
binary=$(APP_NAME).app/Contents/MacOS/Grouch
framework_dir=SharedFrameworks
framework_dir_full=$(APP_NAME).app/Contents/$(framework_dir)
path=@executable_path/../$(framework_dir)/
after-all::
	@echo \ Setting up $(framework_dir)...
	@install_name_tool -change libGrouchCore.dylib.0 \
	 $(path)libGrouchCore.dylib.0 $(binary)
	@install_name_tool -change Renaissance.framework/Renaissance \
	 $(path)Renaissance.framework/Renaissance $(binary)
	@#Even more hackish:
	@install_name_tool -change libGrouchCore.dylib.0 \
	 @executable_path/../$(framework_dir)/libGrouchCore.dylib.0 \
	 $(APP_NAME).app/Contents/Resources/Oscar.bundle/Contents/MacOS/Oscar
	@mkdir -p $(framework_dir_full)
	@echo \ \ Copying libGrouchCore...
	@cp Core/obj/libGrouchCore.dylib.0 $(framework_dir_full) 
	@echo \ \ Copying Renaissance.framework...
	@../copy-framework.sh Renaissance $(framework_dir_full)
endif

include $(GNUSTEP_MAKEFILES)/aggregate.make
include $(GNUSTEP_MAKEFILES)/application.make

