# Makefile for tuxpaint

# Tux Paint - A simple drawing program for children.

# Copyright (c) 2002 by Bill Kendrick
# bill@newbreedsoftware.com
# http://www.newbreedsoftware.com/tuxpaint/

# June 14, 2002 - September 28, 2002


# Where to install things:

PREFIX=/usr/local


# Program:

BIN_PREFIX=$(PREFIX)/bin


# Data:

DATA_PREFIX=$(PREFIX)/share/tuxpaint/


# Docs and man page:

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


# '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=$(PREFIX)/share/gnome/apps/Graphics/
KDE_PREFIX=$(PREFIX)/share/applnk/Graphics/
KDE_ICON_PREFIX=`kde-config --install icon`


# 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:

SDL_LIBS=$(shell sdl-config --libs) -lSDL_image -lSDL_ttf $(SDL_MIXER_LIB)
SDL_MIXER_LIB=-lSDL_mixer
SDL_CFLAGS=$(shell sdl-config --cflags)


# The entire set of CFLAGS:

CFLAGS=-O2 -Wall $(SDL_CFLAGS) -DDATA_PREFIX=\"$(DATA_PREFIX)\" \
	-D$(NOSOUNDFLAG) -DDOC_PREFIX=\"$(DOC_PREFIX)\" \
	-DLOCALEDIR=\"$(LOCALE_PREFIX)\" -DCONFDIR=\"$(CONFDIR)\"


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

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



# "make nosound" builds the program with sound disabled, and man page,
# from sources:

nosound:
	@echo
	@echo "Building with sound DISABLED"
	@echo
	make SDL_MIXER_LIB= NOSOUNDFLAG=NOSOUND



# "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 install-importscript \
		install-default-config
	@echo
	@echo "All done! Now (preferably NOT as 'root' superuser),"
	@echo "you can type the command 'tuxpaint' to run the program!!!"
	@echo
	@echo "For more information, see the 'tuxpaint' man page,"
	@echo "run 'tuxpaint --usage' or see $(DOC_PREFIX)README.txt"
	@echo
	@echo "Enjoy!"
	@echo


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

clean:
	-rm -f tuxpaint
	-rm -f obj/*.o
	if [ -d obj ]; then rmdir obj; fi
	-rm -f trans/*.mo
	if [ -d trans ]; then rmdir trans; fi
	-rm -f tuxpaint.1
	-rm -f tuxpaint-import.1


# "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:
	-rm $(GNOME_PREFIX)/tuxpaint.desktop
	-rm $(KDE_PREFIX)/tuxpaint.desktop
	-rm $(ICON_PREFIX)tuxpaint.png
	-rm $(X11_ICON_PREFIX)tuxpaint.xpm
	-rm $(BIN_PREFIX)/tuxpaint
	-rm $(BIN_PREFIX)/tuxpaint-import
	-rm -r $(DATA_PREFIX)
	-rm -r $(DOC_PREFIX)
	-rm $(MAN_PREFIX)/man1/tuxpaint.1.gz
	-rm $(LOCALE_PREFIX)da/LC_MESSAGES/tuxpaint.mo
	-rm $(LOCALE_PREFIX)de/LC_MESSAGES/tuxpaint.mo
	-rm $(LOCALE_PREFIX)es/LC_MESSAGES/tuxpaint.mo
	-rm $(LOCALE_PREFIX)fi/LC_MESSAGES/tuxpaint.mo
	-rm $(LOCALE_PREFIX)fr/LC_MESSAGES/tuxpaint.mo
	-rm $(LOCALE_PREFIX)is/LC_MESSAGES/tuxpaint.mo
	-rm $(LOCALE_PREFIX)it/LC_MESSAGES/tuxpaint.mo
	-rm $(LOCALE_PREFIX)ja/LC_MESSAGES/tuxpaint.mo
	-rm $(LOCALE_PREFIX)nl/LC_MESSAGES/tuxpaint.mo
	-rm $(LOCALE_PREFIX)nn/LC_MESSAGES/tuxpaint.mo
	-rm $(LOCALE_PREFIX)sv/LC_MESSAGES/tuxpaint.mo
	-rm $(LOCALE_PREFIX)pt_BR/LC_MESSAGES/tuxpaint.mo
	-rm $(LOCALE_PREFIX)tr/LC_MESSAGES/tuxpaint.mo
	-rm -f -r $(CONFDIR)


# Install default config file:

install-default-config:
	@echo
	@echo "...Installing default config file..."
	install -d $(CONFDIR)
	cp src/tuxpaint.conf $(CONFDIR)
	chmod 644 $(CONFDIR)/tuxpaint.conf


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

install-gnome:
	@echo
	@echo "...Installing launcher icon into GNOME..."
	install -d $(GNOME_PREFIX)
	cp src/tuxpaint.desktop $(GNOME_PREFIX)
	chmod 644 $(GNOME_PREFIX)/tuxpaint.desktop


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

install-kde:
	@echo
	@echo "...Installing launcher icon into KDE..."
	install -d $(KDE_PREFIX)
	cp src/tuxpaint.desktop $(KDE_PREFIX)
	chmod 644 $(KDE_PREFIX)/tuxpaint.desktop


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.png; \
	cp data/images/icon32x32.png \
		$(KDE_ICON_PREFIX)/hicolor/32x32/apps/tuxpaint.png; \
	cp data/images/icon16x16.png \
		$(KDE_ICON_PREFIX)/hicolor/16x16/apps/tuxpaint.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.png
	chmod 644 $(ICON_PREFIX)tuxpaint.png
	install -d $(X11_ICON_PREFIX)
	cp data/images/icon32x32.xpm $(X11_ICON_PREFIX)tuxpaint.xpm
	chmod 644 $(X11_ICON_PREFIX)tuxpaint.xpm


# Install the program:

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


# Install the import script:

install-importscript:
	@echo
	@echo "...Installing 'tuxpaint-import' script..."
	cp src/tuxpaint-import.sh $(BIN_PREFIX)/tuxpaint-import
	chmod a+rx,g-w,o-w $(BIN_PREFIX)/tuxpaint-import


# 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..."
	@echo "   ...French..."
	install -d $(LOCALE_PREFIX)fr/LC_MESSAGES
	cp trans/fr.mo $(LOCALE_PREFIX)fr/LC_MESSAGES/tuxpaint.mo
	chmod 644 $(LOCALE_PREFIX)fr/LC_MESSAGES/tuxpaint.mo
	@echo "   ...Icelanding..."
	install -d $(LOCALE_PREFIX)is/LC_MESSAGES
	cp trans/is.mo $(LOCALE_PREFIX)is/LC_MESSAGES/tuxpaint.mo
	chmod 644 $(LOCALE_PREFIX)is/LC_MESSAGES/tuxpaint.mo
	@echo "   ...Japanese..."
	install -d $(LOCALE_PREFIX)ja/LC_MESSAGES
	cp trans/jp.mo $(LOCALE_PREFIX)ja/LC_MESSAGES/tuxpaint.mo
	chmod 644 $(LOCALE_PREFIX)ja/LC_MESSAGES/tuxpaint.mo
	@echo "   ...German..."
	install -d $(LOCALE_PREFIX)de/LC_MESSAGES
	cp trans/de.mo $(LOCALE_PREFIX)de/LC_MESSAGES/tuxpaint.mo
	chmod 644 $(LOCALE_PREFIX)de/LC_MESSAGES/tuxpaint.mo
	@echo "   ...Spanish..."
	install -d $(LOCALE_PREFIX)es/LC_MESSAGES
	cp trans/es.mo $(LOCALE_PREFIX)es/LC_MESSAGES/tuxpaint.mo
	chmod 644 $(LOCALE_PREFIX)es/LC_MESSAGES/tuxpaint.mo
	@echo "   ...Finnish..."
	install -d $(LOCALE_PREFIX)fi/LC_MESSAGES
	cp trans/fi.mo $(LOCALE_PREFIX)fi/LC_MESSAGES/tuxpaint.mo
	chmod 644 $(LOCALE_PREFIX)fi/LC_MESSAGES/tuxpaint.mo
	@echo "   ...Turkish..."
	install -d $(LOCALE_PREFIX)tr/LC_MESSAGES
	cp trans/tr.mo $(LOCALE_PREFIX)tr/LC_MESSAGES/tuxpaint.mo
	chmod 644 $(LOCALE_PREFIX)tr/LC_MESSAGES/tuxpaint.mo
	@echo "   ...Norwegian..."
	install -d $(LOCALE_PREFIX)nn/LC_MESSAGES
	cp trans/nn.mo $(LOCALE_PREFIX)nn/LC_MESSAGES/tuxpaint.mo
	chmod 644 $(LOCALE_PREFIX)nn/LC_MESSAGES/tuxpaint.mo
	@echo "   ...Italian..."
	install -d $(LOCALE_PREFIX)it/LC_MESSAGES
	cp trans/it.mo $(LOCALE_PREFIX)it/LC_MESSAGES/tuxpaint.mo
	chmod 644 $(LOCALE_PREFIX)it/LC_MESSAGES/tuxpaint.mo
	@echo "   ...Dutch..."
	install -d $(LOCALE_PREFIX)nl/LC_MESSAGES
	cp trans/nl.mo $(LOCALE_PREFIX)nl/LC_MESSAGES/tuxpaint.mo
	chmod 644 $(LOCALE_PREFIX)nl/LC_MESSAGES/tuxpaint.mo
	@echo "   ...Swedish..."
	install -d $(LOCALE_PREFIX)sv/LC_MESSAGES
	cp trans/sv.mo $(LOCALE_PREFIX)sv/LC_MESSAGES/tuxpaint.mo
	chmod 644 $(LOCALE_PREFIX)sv/LC_MESSAGES/tuxpaint.mo
	@echo "   ...Brazilian Portuguese..."
	install -d $(LOCALE_PREFIX)pt_BR/LC_MESSAGES
	cp trans/pt_br.mo $(LOCALE_PREFIX)pt_BR/LC_MESSAGES/tuxpaint.mo
	chmod 644 $(LOCALE_PREFIX)sv/LC_MESSAGES/tuxpaint.mo
	@echo "   ...Danish..."
	install -d $(LOCALE_PREFIX)da/LC_MESSAGES
	cp trans/da.mo $(LOCALE_PREFIX)da/LC_MESSAGES/tuxpaint.mo
	chmod 644 $(LOCALE_PREFIX)da/LC_MESSAGES/tuxpaint.mo



# Install the text documentation:

install-doc:
	@echo
	@echo "...Installing documentation..."
	@echo "(English)"
	install -d $(DOC_PREFIX)
	cp docs/AUTHORS.txt $(DOC_PREFIX)
	cp docs/CHANGES.txt $(DOC_PREFIX)
	cp docs/COPYING.txt $(DOC_PREFIX)
	cp docs/PNG.txt $(DOC_PREFIX)
	cp docs/README.txt $(DOC_PREFIX)
	cp docs/TODO.txt $(DOC_PREFIX)
	@echo "(German)"
	install -d $(DOC_PREFIX)de
	cp docs/de/* $(DOC_PREFIX)de/
	@echo "(Spanish)"
	install -d $(DOC_PREFIX)es
	cp docs/es/* $(DOC_PREFIX)es/
	@echo "(Finnish)"
	install -d $(DOC_PREFIX)fi
	cp docs/fi/* $(DOC_PREFIX)fi/
	@echo "(French)"
	install -d $(DOC_PREFIX)fr
	cp docs/fr/* $(DOC_PREFIX)fr/
	@echo "(Italian)"
	install -d $(DOC_PREFIX)it
	cp docs/it/* $(DOC_PREFIX)it/
	@echo "(Dutch)"
	install -d $(DOC_PREFIX)nl
	cp docs/nl/* $(DOC_PREFIX)nl/
	@echo "(Danish)"
	install -d $(DOC_PREFIX)da
	cp docs/da/* $(DOC_PREFIX)da/
	@echo "(Norwegian)"
	install -d $(DOC_PREFIX)nn
	cp docs/nn/* $(DOC_PREFIX)nn/
	@echo "(Turkish)"
	install -d $(DOC_PREFIX)tr
	cp docs/tr/* $(DOC_PREFIX)tr/
	@echo "(...Setting permissions)"
	chmod a+rx,g-w,o-w $(DOC_PREFIX)


# Install the man page:

install-man:
	@echo "...Installing man page..."
	install -d $(MAN_PREFIX)/man1/
	if [ -e tuxpaint.1 ]; then \
	cp tuxpaint.1 $(MAN_PREFIX)/man1/; \
	gzip -f $(MAN_PREFIX)/man1/tuxpaint.1; \
	chmod a+rx,g-w,o-w $(MAN_PREFIX)/man1/tuxpaint.1.gz; \
	fi
	if [ -e tuxpaint-import.1 ]; then \
	cp tuxpaint-import.1 $(MAN_PREFIX)/man1/; \
	gzip -f $(MAN_PREFIX)/man1/tuxpaint-import.1; \
	chmod a+rx,g-w,o-w $(MAN_PREFIX)/man1/tuxpaint-import.1.gz; \
	fi


# Build the program!

tuxpaint:	obj/tuxpaint.o
	$(CC) $(CFLAGS) -o tuxpaint obj/tuxpaint.o $(SDL_LIBS) -lm


# Build the man page from docbook (SGML) source:

tuxpaint.1:	src/tuxpaint.sgml
	@if [ -x "`which docbook-to-man`" ]; then docbook-to-man $< > $@; else \
	echo "docbook-to-man not found, man page won't be made!"; fi

tuxpaint-import.1:	src/tuxpaint-import.sgml
	@if [ -x "`which docbook-to-man`" ]; then docbook-to-man $< > $@; else \
	echo "docbook-to-man not found, man page won't be made!"; fi


# Build the object for the program!

obj/tuxpaint.o:	src/tuxpaint.c obj \
		src/tools.h src/titles.h src/colors.h src/shapes.h \
		src/magic.h src/sounds.h src/tip_tux.h src/great.h \
		src/mouse/arrow.xbm src/mouse/arrow-mask.xbm \
		src/mouse/hand.xbm src/mouse/hand-mask.xbm \
		src/mouse/insertion.xbm src/mouse/insertion-mask.xbm \
		src/mouse/wand.xbm src/mouse/wand-mask.xbm \
		src/mouse/brush.xbm src/mouse/brush-mask.xbm \
		src/mouse/crosshair.xbm src/mouse/crosshair-mask.xbm \
		src/mouse/rotate.xbm src/mouse/rotate-mask.xbm \
		src/mouse/tiny.xbm src/mouse/tiny-mask.xbm \
		src/mouse/watch.xbm src/mouse/watch-mask.xbm \
		src/mouse/up.xbm src/mouse/up-mask.xbm \
		src/mouse/down.xbm src/mouse/down-mask.xbm
	$(CC) $(CFLAGS) -c src/tuxpaint.c -o obj/tuxpaint.o


# Build the translation files for gettext

translations:	trans trans/fr.mo trans/de.mo trans/es.mo trans/fi.mo \
		trans/tr.mo trans/nn.mo trans/it.mo trans/nl.mo trans/sv.mo \
		trans/jp.mo trans/is.mo trans/da.mo trans/pt_br.mo

trans:
	mkdir trans

trans/fr.mo:	src/messages/fr.po
	msgfmt src/messages/fr.po -o trans/fr.mo

trans/de.mo:	src/messages/de.po
	msgfmt src/messages/de.po -o trans/de.mo

trans/da.mo:	src/messages/da.po
	msgfmt src/messages/da.po -o trans/da.mo

trans/jp.mo:	src/messages/jp.po
	msgfmt src/messages/jp.po -o trans/jp.mo

trans/es.mo:	src/messages/es.po
	msgfmt src/messages/es.po -o trans/es.mo

trans/fi.mo:	src/messages/fi.po
	msgfmt src/messages/fi.po -o trans/fi.mo
	
trans/tr.mo:	src/messages/tr.po
	msgfmt src/messages/tr.po -o trans/tr.mo

trans/sv.mo:	src/messages/sv.po
	msgfmt src/messages/sv.po -o trans/sv.mo

trans/pt_br.mo:	src/messages/pt_br.po
	msgfmt src/messages/pt_br.po -o trans/pt_br.mo

trans/nn.mo:	src/messages/nn.po
	msgfmt src/messages/nn.po -o trans/nn.mo
	
trans/it.mo:	src/messages/it.po
	msgfmt src/messages/it.po -o trans/it.mo
	
trans/nl.mo:	src/messages/nl.po
	msgfmt src/messages/nl.po -o trans/nl.mo
	
trans/is.mo:	src/messages/is.po
	msgfmt src/messages/is.po -o trans/is.mo


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

obj:
	mkdir obj

