# Makefile for tcharge, version 1.3, date 11MAY98
#
# Compilerflags (add them to the variable 'CFLAGS' below):
# --------------------------------------------------------
# -DREMINDERS - enables the `-warn' option (see man page)
# -DPRINT_CHARGE_STRUCTURE - enables option `-help-charge'
# (These Flags together make tcharge approx. 20% larger)
#
# -DISDN  - enables tcharge to look for ISDN connections.
#	    >> Don't use this flag if you don't use ISDN! <<
#
# -DDEBUG - enables printing of useable informations about
#	    the telephone company specifics. Use it if you're adding
#	    support for a new telephone company.
#           (includes -DPRINT_CHARGE_STRUCTURE)
#         - for test purposes only!
#
# Supported telephone companies (TC):
# -----------------------------------
# The charge files e.g. 'germany' and the according header files
# e.g 'germany.h' reside in directory ./National.
# Don't edit the C-header files directly!
# (See 'README.TC' for working on charge definitions)
#
#         look up the `default:' directive below for a list
#

CC = gcc
MAKE = make
XLIB_DIR = -L/usr/lib/X11
#INCL = -I/usr/X11R6/include

CFLAGS= -g -DDEBUG -Wall -DREMINDERS
#CFLAGS= -O2 -s -Wall -DREMINDERS -DPRINT_CHARGE_STRUCTURE

PREFIX=/usr/local
MANDIR=$(PREFIX)/man/man1
BINDIR=$(PREFIX)/bin
# perhaps you like it in /usr/lib or /usr/share/lib ?
SRCDIR=$(PREFIX)/src/tcharge

OBJ=tcharge.o
SRC=tcharge.c
HEAD=charge.h
export	# export all variables to sub-makes

##################

default:
	@echo "* Select a telephone company:"
	@echo " type 'make belgium'	-- Belgian Belgacom"
	@echo " type 'make czech'	-- SPT Telecom"
	@echo " type 'make danmark'	-- TeleDanmark"
	@echo " type 'make france'	-- France Telekom"
	@echo " type 'make germany'	-- German Telekom"
	@echo " type 'make hungary'	-- Hungarian MATAV"
	@echo " type 'make italy'	-- Italian Telecom"
	@echo " type 'make japan'	-- Japanese NTT"
	@echo " type 'make netherlands'-- Dutch PTT telecom"
	@echo " type 'make portugal'	-- Portugal Telecom"
	@echo " type 'make slovenia'	-- Slovene Telekom"
	@echo " type 'make south_africa-- South African Telkom"
	@echo " type 'make spain'	-- Spanish Telefonica de Espana"
	@echo " type 'make swiss'	-- Swiss Telecom PTT"
	@echo " type 'make uk'		-- British Telecom"
	@for i in `ls National | egrep -v "0|(\.h)"`; \
	 do if ! test -s National/$$i.h; then \
         echo "But the file National/$$i.h not found"; \
	 echo "- cd to ./National and type '../Tools/mktc $$i'"; fi; done
	@echo "* To install tcharge + man-page,"
	@echo " type 'make install'"

belgium:
	ln -sf National/belgium.h charge.h; $(MAKE) all
czech:
	ln -sf National/czech.h charge.h; $(MAKE) all
danmark:
	ln -sf National/danmark.h charge.h; $(MAKE) all
france:
	ln -sf National/france.h charge.h; $(MAKE) all
germany:
	ln -sf National/germany.h charge.h; $(MAKE) all
hungary:
	ln -sf National/hungary.h charge.h; $(MAKE) all
italy:
	ln -sf National/italy.h charge.h; $(MAKE) all
japan:
	ln -sf National/japan.h charge.h; $(MAKE) all
netherlands:
	ln -sf National/netherlands.h charge.h; $(MAKE) all
portugal:
	ln -sf National/portugal.h charge.h; $(MAKE) all
slovenia:
	ln -sf National/slovenia.h charge.h; $(MAKE) all
south_africa:
	ln -sf National/south_africa.h charge.h; $(MAKE) all
spain:
	ln -sf National/spain.h charge.h; $(MAKE) all
swiss:
	ln -sf National/swiss.h charge.h; $(MAKE) all
uk:
	ln -sf National/uk.h charge.h; $(MAKE) all


tcharge: $(OBJ) $(HEAD)
	$(CC) $(CFLAGS) -o tcharge $(OBJ) $(INCL) $(XLIB_DIR) -lX11

man: Doc/tcharge.man $(HEAD)
	@CURRENCY=`grep CURRENCY_NAME charge.h \
	 | awk '{print $$NF}' | tr -d '"'`;\
	sed -e "s/@DM/$$CURRENCY/g" -e "s,@SRCDIR,$(SRCDIR),g" \
	 Doc/tcharge.man > tcharge.1

all: tcharge man

all-headers:
	@cd National;\
	 for i in `ls | egrep -v "0|\."`; do \
	 echo $$i; ../Tools/mktc $$i >/dev/null || echo "Error!"; done

test-all:
	@for i in `ls National | egrep -v "0|(\.h)"`; do \
	 echo $$i; echo "------"; make clean; \
         ln -sf National/$$i.h charge.h; \
	 make all && grep -e '-warn' tcharge.1; \
	 ./tcharge -geometry +0+0 -update 1; done

install-src:
	install -d $(SRCDIR)
	tar -cf - * | { cd $(SRCDIR); tar -xf -; \
	 $(MAKE) clean; sed -e "s,@SRCDIR,$(SRCDIR),g" \
	 Doc/tcharge.html>t; mv t Doc/tcharge.html; }

install: $(BINDIR)/tcharge $(MANDIR)/tcharge.1 install-src


$(MANDIR)/tcharge.1: tcharge.1
	install -c -m 644 -o root -g root $? $@

$(BINDIR)/tcharge: tcharge
	install -s -c -m 755 -o root -g  root $? $@

tools:
	-(cd Tools; $(MAKE))

clean:
	rm -f $(OBJ) charge.h tcharge tcharge.1 *.bin core
	-(cd Tools; $(MAKE) clean)

depend:
	makedepend -- $(CFLAGS) -- $(SRC)
