# Makefile for tuxpaint-config

# Tux Paint Configuration Tool - A GUI-based configurator for
#                              Tux Paint, a simple drawing program for children.

# Torsten Giebl <wizard@turricane.org>
# Jan Wynholds
# Bill Kendrick <bill@newbreedsoftware.com>
# Martin Fuhrer <mfuhrer@gmail.com>

# http://www.tuxpaint.org/

# November 12, 2002 - July 1, 2007
# $Id: Makefile,v 1.28 2007/07/01 15:04:49 wkendrick Exp $


VER_VERSION=0.0.8
VER_DATE=`date +"%Y-%m-%d"`


# Where to install things:

PREFIX=/usr/local


# Program:

BIN_PREFIX=$(PREFIX)/bin
EXE_EXT=


# Data:

DATA_PREFIX=$(PREFIX)/share/tuxpaint-config/


# Docs and man page:

DOC_PREFIX=$(PREFIX)/share/doc/tuxpaint-config/
MAN_PREFIX=$(PREFIX)/share/man/


# Tux Paint's 'System-wide' Config file:

ifeq ($(PREFIX),/usr)
  CONFDIR=/etc/tuxpaint
else
  CONFDIR=$(PREFIX)/etc/tuxpaint
endif


# Icons and launchers:

ICON_PREFIX=$(PREFIX)/share/pixmaps/
X11_ICON_PREFIX=$(PREFIX)/X11R6/include/X11/pixmaps/
GNOME_PREFIX=`gnome-config --prefix`
KDE_PREFIX=`kde-config --install apps --expandvars`
KDE_ICON_PREFIX=`kde-config --install icon --expandvars`


# Locale files

LOCALE_PREFIX=$(PREFIX)/share/locale/
# LOCALE_PREFIX=/usr/share/locale/


# Built with sound by default  (override with "make nosound")

NOSOUNDFLAG=__SOUND


# Libraries, paths, and flags:

FLTK_CFLAGS=`fltk-config --cxxflags`
#FLTK_LIBS=`fltk-config --ldstaticflags`
FLTK_LIBS=`fltk-config --ldflags`
PAPER_LIB=-lpaper

# Default CFLAGS:
CFLAGS=-O2 -Wall

# The entire set of CFLAGS:
ALL_CFLAGS=$(CFLAGS) $(FLTK_CFLAGS) -DDATA_PREFIX=\"$(DATA_PREFIX)\" \
	-D$(NOSOUNDFLAG) -DDOC_PREFIX=\"$(DOC_PREFIX)\" \
	-DLOCALEDIR=\"$(LOCALE_PREFIX)\" -DCONFDIR=\"$(CONFDIR)\" \
	-DVER_VERSION=\"$(VER_VERSION)\" -DVER_DATE=\"$(VER_DATE)\"


# "make" with no arguments builds the program and man page from sources:

all:	tuxpaint-config translations
	@echo
	@echo "Done compiling."
	@echo "Now (probably as 'root' superuser), run 'make install'"
	@echo "to install Tux Paint Configuration Tool."
	@echo

releaseclean:
	@echo
	@echo "Cleaning release directory"
	@echo
	@rm -rf "build/tuxpaint-config-$(VER_VERSION)" "build/tuxpaint-config-$(VER_VERSION).tar.gz"
	@-if [ -d build ] ; then rmdir build ; fi

releasedir: build/tuxpaint-config-$(VER_VERSION)

build/tuxpaint-config-$(VER_VERSION):
	@echo
	@echo "Creating release directory"
	@echo
	@mkdir -p build/tuxpaint-config-$(VER_VERSION)
	@find . -follow \
		\( -wholename '*/CVS' -o -name .cvsignore -o -name 'build' -o -name '.#*' \) \
		-prune -o -type f -exec cp --parents -vdp \{\} build/tuxpaint-config-$(VER_VERSION)/ \;

release: releasedir
	@echo
	@echo "Creating release tarball"
	@echo
	@cd build ; \
		tar -czvf tuxpaint-config-$(VER_VERSION).tar.gz \
		tuxpaint-config-$(VER_VERSION)


win32:
	make \
		EXE_EXT=.exe \
		ICON_PREFIX=./ \
		X11_ICON_PREFIX=./ \
		CONFDIR=$(PREFIX)/etc/tuxpaint \
		ARCH_LINKS=$(shell if [ "x$$OSTYPE" == "xcygwin" ]; then echo -n "-lintl"; else echo -n "-lintl-8"; fi ) \
		ARCH_LIBS="obj/resource.o obj/win32utils.o" \
		PAPER_LIB= 

install-win32:
	@strip -s tuxpaint-config.exe
	make install \
		EXE_EXT=.exe \
		ICON_PREFIX=./ \
		X11_ICON_PREFIX=./ \
		CONFDIR=$(PREFIX)/etc/tuxpaint \
		ARCH_LINKS=$(shell if [ "x$$OSTYPE" == "xcygwin" ]; then echo -n "-lintl"; else echo -n "-lintl-8"; fi ) \
		ARCH_LIBS="obj/resource.o obj/win32utils.o"

# "make install" installs all of the various parts
# (depending on the *PREFIX variables at the top, you probably need
# to do this as superuser ("root"))

install:	install-bin install-data install-man install-doc \
		install-gnome install-kde install-kde-icons \
		install-icon install-gettext
	@echo
	@echo "All done! Now (preferably NOT as 'root' superuser),"
	@echo "you can type the command 'tuxpaint-config' to run the"
	@echo "configuration tool!"
	@echo
	@echo "Enjoy!"
	@echo


# "make clean" deletes the program, the compiled objects and the
# built man page (returns to factory archive, pretty much...)

clean:
	@echo "Cleaning up the build directory ($(PWD))"
	@-rm -f tuxpaint-config tuxpaint-config.exe
	@-rm -f obj/*.o
	@#if [ -d obj ]; then rmdir obj; fi
	@-rm -f trans/*.mo
	@if [ -d trans ]; then rmdir trans; fi


# "make uninstall" should remove the various parts from their
# installation locations.  BE SURE the *PREFIX variables at the top
# are the same as they were when you installed, of course!!!

uninstall:
#	if [ "x$(GNOME_PREFIX)" != "x" ]; then \
#	  -rm $(GNOME_PREFIX)/share/gnome/apps/Graphics/tuxpaint-config.desktop; \
#	  -rm $(GNOME_PREFIX)/share/pixmaps/tuxpaint-config.png; \
#	fi
	if [ "x$(KDE_PREFIX)" != "x" ]; then \
	  rm $(KDE_PREFIX)/Preferences/tuxpaint-config.desktop; \
	fi
	-rm $(ICON_PREFIX)tuxpaint-config.png
	-rm $(X11_ICON_PREFIX)tuxpaint-config.xpm
	-rm $(BIN_PREFIX)/tuxpaint-config
	-rm -r $(DATA_PREFIX)
	-rm -r $(DOC_PREFIX)
	-rm $(MAN_PREFIX)/man1/tuxpaint-config.1.gz


# Install a launcher icon in the Gnome menu, under "???"

install-gnome:
#	@echo
#	@echo "...Installing launcher icon into GNOME..."
#	if [ "x$(GNOME_PREFIX)" != "x" ]; then \
#	 install -d $(GNOME_PREFIX)/share/pixmaps; \
#	 cp data/images/icon.png $(GNOME_PREFIX)/share/pixmaps/tuxpaint.png; \
#	 chmod 644 $(GNOME_PREFIX)/share/pixmaps/tuxpaint.png; \
#	 install -d $(GNOME_PREFIX)/share/gnome/apps/Graphics; \
#	 cp src/tuxpaint.desktop $(GNOME_PREFIX)/share/gnome/apps/Graphics/; \
#	 chmod 644 $(GNOME_PREFIX)/share/gnome/apps/Graphics/tuxpaint.desktop; \
#	fi


# Install a launcher icon in the KDE menu...

install-kde:
	@echo
	@echo "...Installing launcher icon into KDE..."
	@if [ "x$(KDE_PREFIX)" != "x" ]; then \
	  install -d $(KDE_PREFIX)/Preferences/; \
	  cp src/tuxpaint-config.desktop $(KDE_PREFIX)/Preferences/; \
	  chmod 644 $(KDE_PREFIX)/Preferences/tuxpaint-config.desktop; \
	fi


install-kde-icons:
	@echo "...Installing launcher icon graphics into KDE..."
	@if [ "x$(KDE_ICON_PREFIX)" != "x" ]; then \
	  cp data/images/icon48x48.png \
		$(KDE_ICON_PREFIX)/hicolor/48x48/apps/tuxpaint-config.png; \
	  cp data/images/icon32x32.png \
		$(KDE_ICON_PREFIX)/hicolor/32x32/apps/tuxpaint-config.png; \
	  cp data/images/icon16x16.png \
		$(KDE_ICON_PREFIX)/hicolor/16x16/apps/tuxpaint-config.png; \
	fi


# Install the PNG icon (for GNOME, KDE, etc.)
# and the 24-color 32x32 XPM (for other Window managers):

install-icon:
	@echo
	@echo "...Installing launcher icon graphics..."
	@install -d $(ICON_PREFIX)
	@cp data/images/icon.png $(ICON_PREFIX)tuxpaint-config.png
	@chmod 644 $(ICON_PREFIX)tuxpaint-config.png
	@install -d $(X11_ICON_PREFIX)
	@cp data/images/icon32x32.xpm $(X11_ICON_PREFIX)tuxpaint-config.xpm
	@chmod 644 $(X11_ICON_PREFIX)tuxpaint-config.xpm


# Install the program:

install-bin:
	@echo
	@echo "...Installing program itself..."
	@cp tuxpaint-config $(BIN_PREFIX)
	@chmod a+rx,g-w,o-w $(BIN_PREFIX)/tuxpaint-config$(EXE_EXT)


# Install the data (sound, graphics, fonts):

install-data:
	@echo
	@echo "...Installing data files..."
	@install -d $(DATA_PREFIX)
	@cp -R data/* $(DATA_PREFIX)
	@chmod -R a+rX,g-w,o-w $(DATA_PREFIX)


# Install the translated text:

install-gettext:
	@echo
	@echo "...Installing translation files..."



# Install the text documentation:

install-doc:
	@echo
	@echo "...Installing documentation..."
	@echo "(English)"
	@install -d $(DOC_PREFIX)
	@install -d $(DOC_PREFIX)/html
	@cp docs/AUTHORS.txt $(DOC_PREFIX)
	@cp docs/CHANGES.txt $(DOC_PREFIX)
	@cp docs/COPYING.txt $(DOC_PREFIX)
	@cp docs/README.txt $(DOC_PREFIX)
	@cp docs/html/README.html $(DOC_PREFIX)/html
	@cp docs/TODO.txt $(DOC_PREFIX)
	@echo "(...Setting permissions)"
	@chmod -R a+rx,g-w,o-w $(DOC_PREFIX)


# Install the man page:

install-man:
	@echo "...Installing man pages..."
	# man1 directory...
	@install -d $(MAN_PREFIX)/man1/
	# tuxpaint-config.1
	@cp src/tuxpaint-config.1 $(MAN_PREFIX)/man1/
	@gzip -9f $(MAN_PREFIX)/man1/tuxpaint-config.1
	@chmod a+rx,g-w,o-w $(MAN_PREFIX)/man1/tuxpaint-config.1.gz


# Build the program!

tuxpaint-config:	obj/tuxpaint-config.o obj/tuxpaint-config2.o	\
			obj/defaults.o $(ARCH_LIBS)
	@echo Linking
	@$(CXX) $(ALL_CFLAGS) -o tuxpaint-config obj/tuxpaint-config.o 	\
			obj/tuxpaint-config2.o obj/defaults.o $(ARCH_LIBS) \
			$(FLTK_LIBS) $(ARCH_LINKS) $(PAPER_LIB)


# Build the object for the program!

obj/tuxpaint-config.o:	src/tuxpaint-config.cxx src/version.h src/about.h
	@echo Compiling tuxpaint-config.cxx
	@$(CXX) $(ALL_CFLAGS) -c src/tuxpaint-config.cxx -o obj/tuxpaint-config.o

obj/tuxpaint-config2.o:	src/tuxpaint-config2.cxx src/version.h src/about.h
	@echo Compiling tuxpaint-config2.cxx
	@$(CXX) $(ALL_CFLAGS) -c src/tuxpaint-config2.cxx -o obj/tuxpaint-config2.o

obj/defaults.o:	src/defaults.cxx
	@echo Compiling defaults.cxx
	@$(CXX) $(ALL_CFLAGS) -c src/defaults.cxx -o obj/defaults.o

obj/win32utils.o: src/win32utils.cxx src/win32utils.h
	@echo Compiling win32utils.cxx
	@$(CXX) $(ALL_CFLAGS) -c src/win32utils.cxx -o obj/win32utils.o

obj/resource.o:	visualc/resource.rc visualc/resource.h
	@echo
	@echo "...Compiling win32 resources..."
	@windres -i visualc/resource.rc -o obj/resource.o


# Build the translation files for gettext

translations:	trans

trans:
	@mkdir trans


# Make the "obj" directory to throw the object(s) into:

obj:
	@mkdir obj

