# A makefile if just want to compile Plucker Desktop by itself in
# wxWindows wxMac. You want projects/plucker/ subdirectory in your 
# wxMac directory, so that is at the same level
# as the contrib samples, like this:
# /contrib/samples
# /contrib/samples/xrc/
# /projects/plucker/
# /projects/plucker/plucker_desktop/
# Now if you can compile the samples and the xml resouce sample, you
# can compile plucker-desktop

top_srcdir = ../../..
top_builddir = ../../..
program_dir = projects/plucker/plucker_desktop

# These set of parameters are for a "make -f Makefile-wx-standalone install" command.
# It will put plucker-desktop in your binary directory and put the
# resources in a relevant subdir. It will put the .mo
# translation files in their relevant spots
DESTDIR    =
BINDIR     = $(DESTDIR)/usr/bin
DATADIR    = $(DESTDIR)/usr/share/plucker-desktop
LOCALEDIR  = $(DESTDIR)/usr/share/locale
DOCSDIR    = $(DESTDIR)/usr/share/doc/packages/plucker-desktop
# This will remove the old files when copying over
COPYFLAGS  = --force
# This will prevent a warning if the copy to directory already exists, and
# make any parent directories as required
MKDIRFLAGS = --parents

# Let wx know to include the required extra libraries of the program: the XRC
# resource library and the StyledTextControl library.
APPEXTRALIBS=$(top_builddir)/lib/libwx_gtkd_xrc-2.4.a $(top_builddir)/lib/libwx_gtkd_stc-2.4.a
# Let wx know the way to the headers for these libraries
APPEXTRADEFS=-I$(top_srcdir)/contrib/include

# wx uses PROGRAM instead of target in its standard instructions.
PROGRAM=plucker-desktop

# Include the list of .cpp files of the progrect as a SOURCES variable.
include makefile_filelist.lst

# Build a list of objects, based on the list of sources
OBJECTS=${SOURCES:.cpp=.o}

# Build a list of depfiles, based on the list of sources
DEPFILES=${SOURCES:.cpp=.d}

# Include the wx standard instructions to make a program.
include $(top_builddir)/src/makeprog.env

# Inlude the defiles (standard wx thing to do).
-include $(DEPFILES)

#-----------------------------------------------------------------------------------------
# Make install
#-----------------------------------------------------------------------------------------

# The program won't run (segfault) until the resources are in place.
# Put them where they need to go with "make -f Makefile-wx-standalone install"
install:
	-mkdir $(MKDIRFLAGS) $(BINDIR)
	-cp $(COPYFLAGS) $(PROGRAM) $(BINDIR)
	-mkdir $(MKDIRFLAGS) $(LOCALEDIR)
	-mkdir $(MKDIRFLAGS) $(DOCSDIR)
	-cp $(COPYFLAGS) resource/docs/*.htb $(DOCSDIR)
	-cp $(COPYFLAGS) *full_src_plucker_desktop_dir = $(top_srcdir)/$(program_dir).txt $(DOCSDIR)
	-cp $(COPYFLAGS) docs/*.txt $(DOCSDIR)
	-mkdir $(MKDIRFLAGS) $(DATADIR)/resource
	-mkdir $(MKDIRFLAGS) $(DATADIR)/resource/graphics_dialog
	-cp $(COPYFLAGS) resource/graphics_dialog/*.* $(DATADIR)/resource/graphics_dialog/
	-mkdir $(MKDIRFLAGS) $(DATADIR)/resource/graphics_misc
	-cp $(COPYFLAGS) resource/graphics_misc/*.* $(DATADIR)/resource/graphics_misc/
	-mkdir $(MKDIRFLAGS) $(DATADIR)/resource/graphics_wizard
	-cp $(COPYFLAGS) resource/graphics_wizard/*.* $(DATADIR)/resource/graphics_wizard/
	-mkdir $(MKDIRFLAGS) $(DATADIR)/resource/icons_application
	-cp $(COPYFLAGS) resource/icons_application/*.* $(DATADIR)/resource/icons_application/
	-mkdir $(MKDIRFLAGS) $(DATADIR)/resource/icons_dialog
	-cp $(COPYFLAGS) resource/icons_dialog/*.* $(DATADIR)/resource/icons_dialog/
	-mkdir $(MKDIRFLAGS) $(DATADIR)/resource/icons_art_provider
	-cp $(COPYFLAGS) resource/icons_art_provider/*.* $(DATADIR)/resource/icons_art_provider/
	-mkdir $(MKDIRFLAGS) $(DATADIR)/resource/icons_image_list
	-cp $(COPYFLAGS) resource/icons_image_list/*.* $(DATADIR)/resource/icons_image_list/
	-mkdir $(MKDIRFLAGS) $(DATADIR)/resource/plkrdata_installation
	-cp $(COPYFLAGS) resource/plkrdata_installation/*.* $(DATADIR)/resource/plkrdata_installation/
	-mkdir $(MKDIRFLAGS) $(DATADIR)/resource/plkrdata_setup_wizard
	-cp $(COPYFLAGS) resource/plkrdata_setup_wizard/*.* $(DATADIR)/resource/plkrdata_setup_wizard/
	-mkdir $(MKDIRFLAGS) $(DATADIR)/resource/plkrdata_showcase
	-cp $(COPYFLAGS) resource/plkrdata_showcase/*.* $(DATADIR)/resource/plkrdata_showcase/
	-mkdir $(MKDIRFLAGS) $(DATADIR)/resource/strings_tips
	-cp $(COPYFLAGS) resource/strings_tips/*.txt $(DATADIR)/resource/strings_tips/
	-mkdir $(MKDIRFLAGS) $(DATADIR)/resource/xrc
	-cp $(COPYFLAGS) resource/xrc/*.xrc $(DATADIR)/resource/xrc/
	-mkdir $(MKDIRFLAGS) $(DATADIR)/resource/html_about
	-cp $(COPYFLAGS) resource/html_about/*.htm $(DATADIR)/resource/html_about/
	@echo "------------------------------------------------------------"
	@echo "Plucker Desktop has been installed."
	@echo "You should now logout of root, back to your regular username."
	@echo "Then type plucker-desktop to start."
	@echo "------------------------------------------------------------"

#-----------------------------------------------------------------------------------------
# Plucker Desktop User Help
# Requirements: txt2rtf executable (source is in <wx root dir>/utils/tex2rtf) 
#               hhp2cached executable (source is in <wx root dir>/utils/hhp2cached) 
#               and a zip program available to be executed
#-----------------------------------------------------------------------------------------

# Name of the zip utility, somewhere in the path
ZIP=zip
# NOTE: the zipping of the help file has to be done such that there is no subdir path
# iformation stored in it. Seems that must have BOTH a ZIPFLAGS of "-D" (strip paths) 
# AND cd to the docs directory first before zipping for the paths to be removed.
# hhp2cached returns non-zero, so stops make, so added a '-' command in front.
ZIPFLAGS= -D
TEX2RTF=tex2rtf
HHP2CACHED=hhp2cached
# Path to the PluckerDesktop.tex file, ini and where .htb should end up.
LOCAL_USER_DOCS_DIR=resource/docs
# Path to the developer docs (with Doxygen et al)
LOCAL_DEVELOPER_DOCS_DIR=docs
# Names of all the output as gotten from the PROGRAM variable way up top.
HELP_BASENAME=$(PROGRAM)

userhelp:
	@echo "------------------------------------------------------------"
	@echo "Removing old html files, and .htb file (since would just append)..."
	@echo "------------------------------------------------------------"     
	-rm $(LOCAL_USER_DOCS_DIR)/*.html $(LOCAL_USER_DOCS_DIR)/$(HELP_BASENAME).htb
	@echo "------------------------------------------------------------"
	@echo "Compiling help using Tex2RTF..."
	@echo "------------------------------------------------------------"
	$(TEX2RTF) $(LOCAL_USER_DOCS_DIR)/PluckerDesktop.tex $(LOCAL_USER_DOCS_DIR)/$(HELP_BASENAME).html -macros $(LOCAL_USER_DOCS_DIR)/Tex2Rtf.ini
	@echo "------------------------------------------------------------"
	@echo "Generating a cached version for faster reading..."
	@echo "------------------------------------------------------------"
	-$(HHP2CACHED) $(LOCAL_USER_DOCS_DIR)/$(HELP_BASENAME).hhp
	@echo "------------------------------------------------------------"
	@echo "Zipping output html into a .htb file (hypertext book)..."
	@echo "------------------------------------------------------------"
	cd $(LOCAL_USER_DOCS_DIR) \
	  && $(ZIP) $(ZIPFLAGS) $(HELP_BASENAME).htb $(HELP_BASENAME).hh* $(HELP_BASENAME)*.html
	@echo "Done."

#-----------------------------------------------------------------------------------------
# Plucker Desktop Developer (doxygen) documentation
# Requirements: doxygen executable (www.doxygen.org) somewhere in the path
#-----------------------------------------------------------------------------------------

# TODO.

#-----------------------------------------------------------------------------------------
# Clean all (leave in the plucker-manual.htb though, currently hard to make)
#-----------------------------------------------------------------------------------------
cleanall: clean
	@echo "------------------------------------------------------------"
	@echo "Removing generated Plucker Desktop user help html files..."
	@echo "------------------------------------------------------------"     
	rm -f $(LOCAL_USER_DOCS_DIR)/plucker-desktop*.h*
	rm -f $(LOCAL_USER_DOCS_DIR)/*.con
	rm -f $(LOCAL_USER_DOCS_DIR)/*.ref*
	rm -f $(LOCAL_USER_DOCS_DIR)/*.cached 
	@echo "------------------------------------------------------------"
	@echo "Removing generated Doxygen html files..."
	@echo "------------------------------------------------------------"   
	rm -f $(LOCAL_DEVELOPER_DOCS_DIR)/*.html
	rm -f $(LOCAL_DEVELOPER_DOCS_DIR)/*.css
	rm -f $(LOCAL_DEVELOPER_DOCS_DIR)/*.gif
	rm -f $(LOCAL_DEVELOPER_DOCS_DIR)/*.png

#-----------------------------------------------------------------------------------------
# A source tarball
#-----------------------------------------------------------------------------------------
sourcetarball: cleanall
	@echo "------------------------------------------------------------"
	@echo "Make a gzipped tarball..."
	@echo "------------------------------------------------------------"	
	tar --create --file=../plucker-desktop-src.tar ./*
	gzip ../plucker-desktop-src.tar





















