
################################################################################
# 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
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=yubicfg.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

# 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` -lcore -los -lcore -luuid -lXtst -lX11 -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` -lcore -los -lcore -luuid -lXtst -lX11 -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` -lcore -los -lcore -luuid -lXtst -lX11 -l$(YBPERS_LIBS)
LINKERFLAGS=
WARNINGFLAGS=-Wall
OPTFLAGS=-O0
DEBUGFLAGS=-ggdb -D_DEBUG
LIBPATH=../../../lib/unicodedebug
CPPINC=`$(WX_CONFIG) --debug=yes --unicode=yes --inplace --cxxflags` -DUNICODE
XERCESCPPFLAGS=-DUSE_XML_LIBRARY=XERCES -DWCHAR_INCOMPATIBLE_XMLCH
XERCESLIBFLAGS=-lxerces-c
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` -lcore -los -lcore -luuid -lXtst -lX11 -l$(YBPERS_LIBS)
LINKERFLAGS=
WARNINGFLAGS=-Wall
OPTFLAGS=-O
DEBUGFLAGS=
LIBPATH=../../../lib/unicoderelease
CPPINC=`$(WX_CONFIG) --debug=no --unicode=yes --inplace --cxxflags` -DUNICODE -DNDEBUG
XERCESCPPFLAGS=-DUSE_XML_LIBRARY=XERCES -DWCHAR_INCOMPATIBLE_XMLCH
XERCESLIBFLAGS=-lxerces-c
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../..

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

override LDFLAGS:=$(LIBS) -L$(LIBPATH) $(LINKERFLAGS) $(XERCESLIBFLAGS) $(YBPERS_LIBPATH_FLAGS) $(LDFLAGS)
CPPFLAGS:=$(CXXFLAGS) $(CPPINC) $(GCCFLAGS) $(DEBUGFLAGS) $(OPTFLAGS) $(WARNINGFLAGS) $(XERCESCPPFLAGS) $(YUBIFLAGS) $(CPPFLAGS)

SOURCES= passwordsafeframe.cpp \
	pwsafeapp.cpp safecombinationentry.cpp \
	safecombinationsetup.cpp safecombinationprompt.cpp \
	safecombinationchange.cpp about.cpp \
	properties.cpp PWSgrid.cpp \
	PWStree.cpp version.cpp \
	pwsclip.cpp mainEdit.cpp mainManage.cpp \
	addeditpropsheet.cpp PWSgridtable.cpp \
	optionspropsheet.cpp PasswordSafeSearch.cpp \
	deleteconfirmation.cpp editshortcut.cpp \
	createshortcutdlg.cpp SystemTray.cpp \
	guiinfo.cpp ImportTextDlg.cpp \
	ImportXmlDlg.cpp OpenFilePickerValidator.cpp \
	SafeCombinationCtrl.cpp ExportTextWarningDlg.cpp \
	AdvancedSelectionDlg.cpp ViewReport.cpp dragbar.cpp \
	PWSDragBar.cpp MergeDlg.cpp ExternalKeyboardButton.cpp \
	PwsSync.cpp DbSelectionPanel.cpp CompareDlg.cpp \
	wxutils.cpp ComparisonGridTable.cpp SizeRestrictedPanel.cpp \
	fieldselectionpanel.cpp fieldselectiondlg.cpp pwsmenushortcuts.cpp \
	$(YUBI_SRC) \
	ManagePwdPolicies.cpp PasswordPolicy.cpp SelectionCriteria.cpp \
	TimedTaskChain.cpp mainView.cpp


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


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) $@.$$$$

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
