
################################################################################
# Makefile generated by DialogBlocks
#
# Available configurations:
# debug
# release
# unicodedebug
# unicoderelease
################################################################################

CONFIG?=unicodedebug

# Following sets WX_CONFIG to 3.0 version if found, else 2.x:
ifeq ($(PLATFORM),FreeBSD)
WX2=/usr/local/bin/wxgtk2y-2.8-config
WX3=/usr/local/bin/wxgtk2u-3.0-config
else ifeq ($(PLATFORM),OpenBSD)
WX3=/usr/local/bin/wx-config
else
WX2=/usr/bin/wx-config
WX3=/usr/bin/wx-config-3.0
endif

WX_CONFIG?=$(shell if [ -e $(WX3) ]; then echo $(WX3); else echo $(WX2); fi)

ifndef NO_YUBI
YUBI_SRC=YubiCfgDlg.cpp YubiMixin.cpp
YBPERS_LIBS=ykpers-1
else
YUBIFLAGS=-DNO_YUBI
# we have to define this to something real, unlike CPPINC etc
YBPERS_LIBS=core
endif

ifndef NO_QR
ifeq ($(findstring Linux, $(shell uname -s)), Linux)
QR_SRC=QRCodeDlg.cpp QREncode.cpp
else
QR_SRC=QRCodeDlg.cpp
endif
else
QRFLAGS=-DNO_QR
endif

# debug
ifeq ($(CONFIG),debug)
#Override - debug isn't standard
WXWIN=/usr/src/wxwidgets2.8-2.8.7.1
TOOLCHAINNAME=gtk2d
WXVERSION:=$(shell echo `$(WX_CONFIG) --version`)
CXX?=g++
CC?=gcc
RESCOMP=windres.exe
RCFILEOBJ=pwsafe_rc.o
RCFILESRC=pwsafe.rc
RESOURCEOBJECT=
OUTPUTPATH=GCCDebug
OBJECTPATH=GCCDebug
BUILDPATHS=$(OBJECTPATH)
PROGRAM=pwsafe
LIBS=`$(WX_CONFIG) --debug=yes --unicode=no --libs std,aui` -lcore -los -lcore -luuid -lXtst -lX11  -lcurl -lssl -lmagic -l$(YBPERS_LIBS) ${LIBCXX_LD_EXTRA_FLAGS}
LINKERFLAGS=
WARNINGFLAGS=-Wall
OPTFLAGS=-O0
DEBUGFLAGS=-ggdb -D_DEBUG
LIBPATH=../../../lib/debug
CPPINC=`$(WX_CONFIG) --debug=yes --unicode=no --inplace --cxxflags`
GCCFLAGS=-fPIC
RESPATH=--include-dir "$(WXWIN)/include" --include-dir "$(WXWIN)/contrib/include" --include-dir "$(WXWIN)/GCCBuildDebugGTK2/lib/wx/include/gtk2-ansi-debug-static-2.6"
MACPACKAGEINFO=

# release
else
ifeq ($(CONFIG),release)
WXWIN=/usr/src/wxwidgets2.8-2.8.7.1
TOOLCHAINNAME=gtk2
WXVERSION:=$(shell echo `$(WX_CONFIG) --debug=no --unicode=no --version`)
CXX?=g++
CC?=gcc
RESCOMP=windres.exe
RCFILEOBJ=pwsafe_rc.o
RCFILESRC=pwsafe.rc
RESOURCEOBJECT=
OUTPUTPATH=GCCRelease
OBJECTPATH=GCCRelease
BUILDPATHS=$(OBJECTPATH)
PROGRAM=pwsafe
LIBS=`$(WX_CONFIG) --debug=no --unicode=no --inplace --libs std,aui` -lcore -los -lcore -luuid -lXtst -lX11 -lcurl -lssl -lmagic -l$(YBPERS_LIBS)
LINKERFLAGS=
WARNINGFLAGS=-Wall
OPTFLAGS=-O
DEBUGFLAGS=
LIBPATH=../../../lib/release
CPPINC=`$(WX_CONFIG) --debug=no --unicode=no --inplace --cxxflags` -DNDEBUG
GCCFLAGS=-fPIC
RESPATH=--include-dir "$(WXWIN)/include" --include-dir "$(WXWIN)/contrib/include" --include-dir "$(WXWIN)/GCCBuildReleaseGTK2/lib/wx/include/gtk2-ansi-release-static-2.6"
MACPACKAGEINFO=

# unicodedebug
else
ifeq ($(CONFIG),unicodedebug)
WXWIN=/usr/src/wxwidgets2.8-2.8.7.1
TOOLCHAINNAME=gtk2ud
WXVERSION:=$(shell echo `$(WX_CONFIG) --debug=yes --unicode=yes --version`)
CXX?=g++
CC?=gcc
RESCOMP=windres.exe
RCFILEOBJ=pwsafe_rc.o
RCFILESRC=pwsafe.rc
RESOURCEOBJECT=
OUTPUTPATH=GCCUnicodeDebug
OBJECTPATH=GCCUnicodeDebug
BUILDPATHS=$(OBJECTPATH)
PROGRAM=pwsafe
LIBS=`$(WX_CONFIG) --debug=yes --unicode=yes --inplace --libs std,aui` -lcore -los -lcore -l$(YBPERS_LIBS)
ifneq ($(findstring Darwin, $(shell uname -s)), Darwin)
		LIBS += -luuid -lXtst -lX11 -lcurl -lssl -lmagic
		XERCESLIBFLAGS=-lxerces-c
		XERCESCPPFLAGS=-DUSE_XML_LIBRARY=XERCES -DWCHAR_INCOMPATIBLE_XMLCH
endif
LINKERFLAGS=
WARNINGFLAGS=-Wall
OPTFLAGS=-O0
DEBUGFLAGS=-ggdb -D_DEBUG
LIBPATH=../../../lib/unicodedebug
CPPINC=`$(WX_CONFIG) --debug=yes --unicode=yes --inplace --cxxflags` -DUNICODE
GCCFLAGS=-fPIC
RESPATH=--include-dir "$(WXWIN)/include" --include-dir "$(WXWIN)/contrib/include" --include-dir "$(WXWIN)/GCCBuildDebugGTK2Unicode/lib/wx/include/gtk2-unicode-debug-static-2.6"
MACPACKAGEINFO=

# unicoderelease
else
WXWIN=/usr/src/wxwidgets2.8-2.8.7.1
TOOLCHAINNAME=gtk2u
WXVERSION:=$(shell echo `$(WX_CONFIG) --debug=no --unicode=yes --version`)
CXX?=g++
CC?=gcc
RESCOMP=windres.exe
RCFILEOBJ=pwsafe_rc.o
RCFILESRC=pwsafe.rc
RESOURCEOBJECT=
OUTPUTPATH=GCCUnicodeRelease
OBJECTPATH=GCCUnicodeRelease
BUILDPATHS=$(OBJECTPATH)
PROGRAM=pwsafe
LIBS=`$(WX_CONFIG) --debug=no --unicode=yes --inplace --libs std,aui` -lcore -los -lcore -l$(YBPERS_LIBS)
ifneq ($(findstring Darwin, $(shell uname -s)), Darwin)
		LIBS += -luuid -lXtst -lX11 -lcurl -lssl -lmagic
		XERCESLIBFLAGS=-lxerces-c
		XERCESCPPFLAGS=-DUSE_XML_LIBRARY=XERCES -DWCHAR_INCOMPATIBLE_XMLCH
endif
LINKERFLAGS=
WARNINGFLAGS=-Wall
OPTFLAGS=-O
DEBUGFLAGS=
LIBPATH=../../../lib/unicoderelease
CPPINC=`$(WX_CONFIG) --debug=no --unicode=yes --inplace --cxxflags` -DUNICODE -DNDEBUG
GCCFLAGS=-fPIC
override LDFLAGS:=$(LIBS) -L$(LIBPATH) $(LINKERFLAGS) $(LDFLAGS)
RESPATH=--include-dir "$(WXWIN)/include" --include-dir "$(WXWIN)/contrib/include" --include-dir "$(WXWIN)/GCCBuildReleaseGTK2Unicode/lib/wx/include/gtk2-unicode-release-static-2.6"
MACPACKAGEINFO=
endif
endif
endif

DEPDIR= ./deps

CPPINC += -I../.. -I../../core

ifndef NO_YUBI
YBPERS_LIBPATH?=$(LIBPATH)
YBPERS_LIBPATH_FLAGS=-L$(YBPERS_LIBPATH)
endif

ifndef NO_QR
ifeq ($(findstring Linux, $(shell uname -s)), Linux)
		LIBS += -lqrencode
endif
endif

ifeq ($(findstring Darwin, $(shell uname -s)), Darwin)
		CPPFLAGS += -std=c++11
		override LIBS += -framework QuartzCore
endif
override LDFLAGS:=$(LIBS) -L$(LIBPATH) $(LINKERFLAGS) $(XERCESLIBFLAGS) $(YBPERS_LIBPATH_FLAGS) $(LDFLAGS)
CPPFLAGS:=$(CXXFLAGS) $(CPPINC) $(GCCFLAGS) $(DEBUGFLAGS) $(OPTFLAGS) $(WARNINGFLAGS) $(XERCESCPPFLAGS) $(YUBIFLAGS) $(QRFLAGS) $(CPPFLAGS)

SOURCES= PasswordSafeFrame.cpp \
	PWSafeApp.cpp SafeCombinationEntryDlg.cpp \
	SafeCombinationSetupDlg.cpp SafeCombinationPromptDlg.cpp \
	SafeCombinationChangeDlg.cpp AboutDlg.cpp \
	PropertiesDlg.cpp GridCtrl.cpp \
	TreeCtrl.cpp Version.cpp \
	Clipboard.cpp MenuEditHandlers.cpp MenuManageHandlers.cpp \
	AddEditPropSheetDlg.cpp SelectAliasDlg.cpp GridTable.cpp \
	OptionsPropertySheetDlg.cpp PasswordSafeSearch.cpp \
	DeleteConfirmationDlg.cpp EditShortcutDlg.cpp \
	CreateShortcutDlg.cpp SystemTray.cpp \
	GuiInfo.cpp ImportTextDlg.cpp \
	ImportXmlDlg.cpp OpenFilePickerValidator.cpp \
	SafeCombinationCtrl.cpp ExportTextWarningDlg.cpp \
	AdvancedSelectionDlg.cpp ViewReportDlg.cpp \
	DragBarCtrl.cpp MergeDlg.cpp ExternalKeyboardButton.cpp \
	SyncWizard.cpp DbSelectionPanel.cpp CompareDlg.cpp \
	wxUtilities.cpp ComparisonGridTable.cpp SizeRestrictedPanel.cpp \
	FieldSelectionPanel.cpp FieldSelectionDlg.cpp GridShortcutsValidator.cpp \
	$(YUBI_SRC) $(QR_SRC) \
	ManagePasswordPoliciesDlg.cpp PasswordPolicyDlg.cpp SelectionCriteria.cpp \
	TimedTaskChain.cpp MenuViewHandlers.cpp PasswordSubsetDlg.cpp \
	CryptKeyEntryDlg.cpp MenuFileHandlers.cpp ViewAttachmentDlg.cpp \
	PWFiltersGrid.cpp PWFiltersTable.cpp PWFiltersEditor.cpp \
	PWFiltersBoolDlg.cpp PWFiltersStringDlg.cpp PWFiltersDCADlg.cpp \
	PWFiltersIntegerDlg.cpp PWFiltersStatusDlg.cpp PWFiltersTypeDlg.cpp \
	PWFiltersDateDlg.cpp PWFiltersMediaDlg.cpp PWFiltersPasswordDlg.cpp \
	ManageFiltersTable.cpp SetDatabaseIdDlg.cpp DnDFile.cpp QueryCancelDlg.cpp \
	DnDPWSafeObject.cpp DnDSupport.cpp DnDDropTarget.cpp SetFiltersDlg.cpp \
	ManageFiltersDlg.cpp


OBJECTS=$(SOURCES:%.cpp=$(OBJECTPATH)/%.o)
OBJECTS += $(RESOURCEOBJECT)

ifeq ($(findstring Darwin, $(shell uname -s)), Darwin)
	OBJECTS += $(OBJECTPATH)/pwsqrencode.o


$(OBJECTPATH)/pwsqrencode.o: pwsqrencode.mm
	clang -x objective-c++ -stdlib=libc++ -mmacosx-version-min=10.7 $(CPPFLAGS) -c $< -o $@
endif

all:	$(BUILDPATHS) $(MACPACKAGEINFO) $(OUTPUTPATH)/$(PROGRAM)
	@echo building "$(CONFIG)" "$@"

debug release unicodedebug unicoderelease:
	$(MAKE) all CONFIG=$@

$(OBJECTPATH):
	mkdir -p $(OBJECTPATH)

clean:
	@rm -f $(OBJECTPATH)/*.o
	@rm -f $(OBJECTPATH)/*.res
	@rm -fr .deps .pch
	@rm -fr $(PROGRAM).app
	@rm -f $(OUTPUTPATH)/$(PROGRAM)
	@rm -rf $(DEPDIR)
	@rm -f version.h

help:
	@echo "Usage: make -f Makefile CONFIG=[debug|release|unicodedebug|unicoderelease] [all|clean|help]"

LIBRARIES=$(LIBPATH)/libcore.a $(LIBPATH)/libos.a

$(OUTPUTPATH)/$(PROGRAM):	$(OBJECTS) $(LIBRARIES)
	$(CXX) -o $@ $(OBJECTS) $(LDFLAGS)


$(OBJECTPATH)/%.o : %.cpp
	$(CXX) -c -o $@ $(CPPFLAGS) $<

# Windows only
$(OBJECTPATH)/$(RCFILEOBJ):	$(RCFILESRC)
	$(RESCOMP) --use-temp-file -i$< -o$@ $(RESPATH) --include-dir . --define NOPCH

# Mac only
$(OUTPUTPATH)/$(PROGRAM).app/Contents/PkgInfo: $(OUTPUTPATH)/$(PROGRAM) $(INFOPLISTSOURCE) $(ICNSSOURCE)
	mkdir -p $(OUTPUTPATH)/$(PROGRAM).app/Contents
	mkdir -p $(OUTPUTPATH)/$(PROGRAM).app/Contents/MacOS
	mkdir -p $(OUTPUTPATH)/$(PROGRAM).app/Contents/Resources
	sed -e "s/IDENTIFIER/$(PROGRAM)/" \
	-e "s/EXECUTABLE/$(PROGRAM)/" \
	-e "s/VERSION/$(WXVERSION)/" \
	$(INFOPLISTSOURCE) >$(OUTPUTPATH)/$(PROGRAM).app/Contents/Info.plist
	echo -n "APPL????" >$(OUTPUTPATH)/$(PROGRAM).app/Contents/PkgInfo
	ln -f $(OUTPUTPATH)/$(PROGRAM) $(OUTPUTPATH)/$(PROGRAM).app/Contents/MacOS/$(PROGRAM)
	cp -f $(ICNSSOURCE) $(ICNSDEST)

$(DEPDIR)/%.d: %.cpp version.h
	@set -e; mkdir -p $(DEPDIR); $(RM) $@; \
	$(CXX) -MM $(CPPFLAGS) $< > $@.$$$$; \
	sed 's,\($*\)\.o[ :]*,$(OBJECTPATH)/\1.o $@ : ,g' < $@.$$$$ > $@; \
	$(RM) $@.$$$$

ifeq ($(findstring Darwin, $(shell uname -s)), Darwin)
$(DEPDIR)/pwsqrencode.d: pwsqrencode.mm
	@set -e; mkdir -p $(DEPDIR); $(RM) $@; \
	clang -x objective-c++ -stdlib=libc++ -mmacosx-version-min=10.7 -MM $(CPPFLAGS) $< > $@.$$$$; \
	sed 's,\($*\)\.o[ :]*,$(OBJECTPATH)/\1.o $@ : ,g' < $@.$$$$ > $@; \
	$(RM) $@.$$$$
endif

version.h: always
ifdef VER_REV
	@../../../Misc/mkversion.pl MAJOR=$(VER_MAJOR) MINOR=$(VER_MINOR) REV=$(VER_REV) \
															SPECIAL=$(VER_SPECIAL) version.in $@
else
	@../../../Misc/mkversion.pl MAJOR=$(VER_MAJOR) MINOR=$(VER_MINOR) \
															SPECIAL=$(VER_SPECIAL) version.in $@
endif
-include $(SOURCES:%.cpp=$(DEPDIR)/%.d)


.PHONY:	all clean help always
### Begin DialogBlocks generated body
### End DialogBlocks generated body
