#******************************************************************************
#             Makefile for the GNU Spice GUI Project House-keeping            *
#                                                                             *
#  Started     : 08/01/2004                                                   *
#  Last update : 16/10/2007                                                   *
#  Copyright   : (C) 2004 by MSWaters                                         *
#  Email       : M.Waters@bom.gov.au                                          *
#******************************************************************************

#******************************************************************************
#                                                                             *
#     This program is free software; you can redistribute it and/or modify    *
#     it under the terms of the GNU General Public License as published by    *
#     the Free Software Foundation; either version 2 of the License, or       *
#     (at your option) any later version.                                     *
#                                                                             *
#******************************************************************************

#******************************************************************************
# Specify string values
#******************************************************************************

# Root directory
ROOT := $(shell pwd)

# Install directory
INSTALLDIR = /usr/local

#******************************************************************************
# Make these targets
#******************************************************************************

all :
	$(MAKE) config
	cd $(ROOT)/src ; $(MAKE)

#******************************************************************************
# Calculate the size of the sources
#******************************************************************************

size :
	$(ROOT)/charcnt >> charcnt.txt

#******************************************************************************
# Create an archive
#
# An archive of the essential project files can be generated as follows :
#
#   1.  Change the make variable "DIR" (below) to the current version number.
#   2.  Execute "make tar" from the project root directory.
#******************************************************************************

DIR=gspiceui-v0.9.55

tar :
	cd .. ; mv gspiceui $(DIR)
	cd .. ; tar --totals --exclude *.o --exclude .svn \
	-zcf $(DIR)/$(DIR).tar.gz \
	$(DIR)/Makefile           \
	$(DIR)/AUTHORS            \
	$(DIR)/COPYING            \
	$(DIR)/INSTALL            \
	$(DIR)/README             \
	$(DIR)/TODO               \
	$(DIR)/ChangeLog          \
	$(DIR)/gspiceui.1         \
	$(DIR)/gspiceui.lsm       \
	$(DIR)/src/*              \
	$(DIR)/html/Makefile      \
	$(DIR)/html/*.html        \
	$(DIR)/html/*.jpeg        \
	$(DIR)/sch/Makefile       \
	$(DIR)/sch/*.sch          \
	$(DIR)/lib/Makefile       \
	$(DIR)/lib/*/*.mod        \
	$(DIR)/mac/Info.plist     \
	$(DIR)/mac/GSpiceUI.icns  \
	$(DIR)/fig/Makefile       \
	$(DIR)/fig/*.fig
	cd .. ; mv $(DIR) gspiceui

#******************************************************************************
# Perform configuration tasks
#******************************************************************************

# Everyone should call this once
config :
ifneq ($(ROOT)/bin,$(wildcard $(ROOT)/bin))
	mkdir $(ROOT)/bin
endif
ifneq ($(ROOT)/src/obj,$(wildcard $(ROOT)/src/obj))
	mkdir $(ROOT)/src/obj
endif

# You should also call this once if running on a MAC
maccfg : $(ROOT)/mac/Info.plist $(ROOT)/mac/GSpiceUI.icns
ifneq ($(ROOT)/GSpiceUI.app,$(wildcard $(ROOT)/GSpiceUI.app))
	-mkdir $(ROOT)/GSpiceUI.app
	-mkdir $(ROOT)/GSpiceUI.app/Contents
	-mkdir $(ROOT)/GSpiceUI.app/Contents/MacOS
	-mkdir $(ROOT)/GSpiceUI.app/Contents/Resources
	cp $(ROOT)/mac/Info.plist $(ROOT)/GSpiceUI.app/Contents/
	echo -n 'APPL????' > $(ROOT)/GSpiceUI.app/Contents/PkgInfo
	cp $(ROOT)/mac/GSpiceUI.icns $(ROOT)/GSpiceUI.app/Contents/Resources/
endif

#******************************************************************************
# Perform installation tasks
#******************************************************************************

install :
	mkdir -p $(INSTALLDIR)/share/gspiceui
	cp README    $(INSTALLDIR)/share/gspiceui
	cp INSTALL   $(INSTALLDIR)/share/gspiceui
	cp ChangeLog $(INSTALLDIR)/share/gspiceui
	mkdir -p $(INSTALLDIR)/share/gspiceui/icons
	cp src/icons/gspiceui-*.xpm $(INSTALLDIR)/share/gspiceui/icons
	mkdir -p $(INSTALLDIR)/share/man/man1
	cp gspiceui.1 $(INSTALLDIR)/share/man/man1
	cd $(ROOT)/src  ; $(MAKE) install INSTALLDIR=$(INSTALLDIR)
	cd $(ROOT)/html ; $(MAKE) install INSTALLDIR=$(INSTALLDIR)

#******************************************************************************
# Perform uninstall tasks
#******************************************************************************

uninstall :
	rm -fr $(INSTALLDIR)/share/gspiceui
	rm -f  $(INSTALLDIR)/share/man/man1/gspiceui.1
	cd $(ROOT)/src  ; $(MAKE) uninstall INSTALLDIR=$(INSTALLDIR)
	cd $(ROOT)/html ; $(MAKE) uninstall INSTALLDIR=$(INSTALLDIR)
	rm -f ~/.gspiceui.conf

#******************************************************************************
# Remove temporary files and backup files
#******************************************************************************

clean :
	rm -f Makefile~ charcnt~
	cd $(ROOT)/src  ; $(MAKE) clean
	cd $(ROOT)/html ; $(MAKE) clean
	cd $(ROOT)/sch  ; $(MAKE) clean

#******************************************************************************
# Specify phony targets
#******************************************************************************

.PHONY : size tar config install uninstall clean

#******************************************************************************
