# Makefile dla ZooEY 1.0

### configuration
PREFIX=/usr/local/zooey

### if you want support for gettext type 'GETTEXT=yes' (case sensitive!)
GETTEXT=yes

### global variables
PACKAGE=zooey
VERSION=1.4

### don't change LOCALES!
LOCALES=$(PREFIX)/share/locale

### distributed files
SCRIPTS=atari2unix unix2atari label2asm
SOURCE_FILES=zooey.c mnemonics.h zooey.h
EXTRA_FILES=pl.po Makefile copying ChangeLog ToDo asm.syntax zooey.1

### needed tools (GNU's rm, mkdir and tar required)
CC=gcc
CP=cp
RM=rm
MKDIR=mkdir
TAR=tar
MSGFMT=msgfmt
XGETTEXT=xgettext

### CC flags

CFLAGS=-O2 -Wall -DVERSION=\"$(VERSION)\" -DLOCALES=\"$(LOCALES)\"
LIBS=-lm

help:
	@echo "Available methods:"
	@echo "make $(PACKAGE) - just compile and strip $(PACKAGE) (version: $(VERSION)),"
	@echo "make $(PACKAGE)_dbg - just compile $(PACKAGE) (version: $(VERSION)),"
	@echo "make $(PACKAGE).mo - compile package with translations,"
	@echo "make $(PACKAGE).pot - create template file for translations,"
	@echo "make install - install this software in $(PREFIX) (defined in Makefile by PREFIX),"
	@echo "make install_nolang - install this software in $(PREFIX) (defined in Makefile by PREFIX), but without gettext files,"
	@echo "make clean - remove all created/compiled files,"
	@echo "make delete/make remove - remove files from $(PREFIX) (defined in Makefile by PREFIX),"
	@echo "make dist - create .tgz with sources - require GNU's tools."
	@echo ""
	@echo "If you have any troubles with internationalization (eg. no gettext, setlocale, bindtextdomain or textdomain function) try type 'GETTEXT=no' in Makefile."

$(PACKAGE): $(SOURCE_FILES)
	@if test "$(GETTEXT)" = "yes" ; then \
	    $(CC) -s $(CFLAGS) $(LIBS) -DGETTEXT -o $(PACKAGE) zooey.c ; \
	else \
	    $(CC) -s $(CFLAGS) $(LIBS) -UGETTEXT -o $(PACKAGE) zooey.c ; \
	fi;

$(PACKAGE)_dbg: $(SOURCE_FILES)
	@if test "$(GETTEXT)" = "yes" ; then \
	    $(CC) $(CFLAGS) $(LIBS) -DGETTEXT -o $(PACKAGE) zooey.c ; \
	else \
	    $(CC) $(CFLAGS) $(LIBS) -UGETTEXT -o $(PACKAGE) zooey.c ; \
	fi;

$(PACKAGE).mo: pl.po $(PACKAGE).pot
	$(MSGFMT) pl.po -o $(PACKAGE).mo

$(PACKAGE).pot: $(SOURCE_FILES)
	$(XGETTEXT) --keyword=_ --keyword=N_ $(SOURCE_FILES) -o $(PACKAGE).pot

install: $(PACKAGE) $(SCRIPTS) $(PACKAGE).mo $(PACKAGE).pot $(PACKAGE).1
	$(MKDIR) -p $(PREFIX)/bin
	$(CP) -f $(PACKAGE) $(PREFIX)/bin
	$(CP) -f $(SCRIPTS) $(PREFIX)/bin
	$(MKDIR) -p $(PREFIX)/share/locale/pl/LC_MESSAGES
	$(CP) -f $(PACKAGE).mo $(PREFIX)/share/locale/pl/LC_MESSAGES
	$(MKDIR) -p $(PREFIX)/share/man/man1
	$(CP) -f $(PACKAGE).1 $(PREFIX)/share/man/man1
	@echo "Add $(PACKAGE)/share/man to your MANPATH variable"

install_nolang: $(PACKAGE) $(SCRIPTS) $(PACKAGE).1
	$(MKDIR) -p $(PREFIX)/bin
	$(CP) -f $(PACKAGE) $(PREFIX)/bin
	$(CP) -f $(SCRIPTS) $(PREFIX)/bin
	$(MKDIR) -p $(PREFIX)/share/man/man1
	$(CP) -f $(PACKAGE).1 $(PREFIX)/share/man/man1

clean:
	$(RM) -f $(PACKAGE) $(PACKAGE).mp $(PACKAGE).pot

remove:
	$(RM) -f $(PREFIX)/bin/$(PACKAGE)
	$(RM) -f $(PREFIX)/bin/$(SCRIPTS)
	$(RM) -f $(PREFIX)/share/locale/pl/LC_MESSAGES
	$(RM) -f $(PREFIX)/share/man/man1

delete:
	$(RM) -f $(PREFIX)/bin/$(PACKAGE)
	$(RM) -f $(PREFIX)/bin/$(SCRIPTS)
	$(RM) -f $(PREFIX)/share/locale/pl/LC_MESSAGES
	$(RM) -f $(PREFIX)/share/man/man1

dist:
	$(RM) -rf /tmp/$(PACKAGE)-$(VERSION)
	$(MKDIR) -p /tmp/$(PACKAGE)-$(VERSION)
	$(CP) -rf $(SCRIPTS) $(SOURCE_FILES) $(EXTRA_FILES) /tmp/$(PACKAGE)-$(VERSION)
	cd /tmp ; $(TAR) -zcf $(CURDIR)/$(PACKAGE)-$(VERSION).tgz $(PACKAGE)-$(VERSION)
	$(RM) -rf /tmp/$(PACKAGE)-$(VERSION)
