srcdir =	@srcdir@
VPATH =		@srcdir@

prefix =	@prefix@
exec_prefix =	@exec_prefix@

bindir =	$(exec_prefix)/bin

INSTALL =	@INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA =	@INSTALL_DATA@

SHELL =		/bin/sh
CC =		@CC@
AWK =		@AWK@
RM =		rm
DEFS =		@DEFS@
LIBS =		@LIBS@
CFLAGS =	@CFLAGS@
LDFLAGS =	@LDFLAGS@

#### End system configuration section ####

INCLUDES =	-I$(srcdir) -I$(srcdir)/../include -I$(srcdir)/../library -I$(srcdir)/../static -I.
DEFS =          -DHAVE_STRERROR
OUR_CFLAGS =	$(DEFS) $(INCLUDES) $(CFLAGS)
OUR_LDFLAGS =	$(LDFLAGS) -B../libsrc/ -L../libsrc

DATABASES =	africa antarctica asia australasia europe northamerica southamerica \
		pacificnew etcetera backward systemv solar87 solar88 solar89

IXPREFS_OBJ =	ixprefs.o main.o cli.o functions.o

TZDIR = 	$(prefix)/etc/zoneinfo

# Taken from the tzcode95g.tar.gz Makefile:
#
# If you want something other than Eastern United States time as a template
# for handling POSIX-style time zone environment variables,
# change the line below (after finding the zone you want in the
# time zone files, or adding it to a time zone file).
# (When a POSIX-style environment variable is handled, the rules in the template
# file are used to determine "spring forward" and "fall back" days and
# times; the environment variable itself specifies GMT offsets of standard and
# summer time.)
# Alternately, if you discover you've got the wrong time zone, you can just
#	zic -p rightzone
# to correct things.
# If you want POSIX compatibility, use "America/New_York".

POSIXRULES =	America/New_York

.c.o:
		$(CC) -c $(OUR_CFLAGS) $<

all :		ixprefs ixtrace ixrun ixtimezone ixstack ixpipe-handler \
		tzselect zoneinfo/GMT

ixprefs :	$(IXPREFS_OBJ) getopt.o getopt1.o
		$(CC) $(OUR_LDFLAGS) -o $@ $^ -lauto

ixprefs.o:	ixprefs.c
		sed -e '/clib/d' \
		    -e 's/pragmas/proto/' \
		    -e 's/_pragmas//' \
		    -e 's/	(TAG_DONE)/	(GTCB_Scaled), TRUE, (TAG_DONE)/' \
		    -e 's/OpenDiskFont/OpenFont/' \
		    -e 's/CreateMenus( ixprefsNewMenu, GTMN_FrontPen, 0L, TAG_DONE )/CreateMenusA( ixprefsNewMenu, NULL )/' \
		    -e 's/LayoutMenus( ixprefsMenus, VisualInfo, TAG_DONE )/LayoutMenus( ixprefsMenus, VisualInfo, GTMN_NewLookMenus, TRUE, TAG_DONE )/' \
		    -e 's/WA_PubScreenFallBack,	TRUE/WA_PubScreenFallBack,	TRUE, WA_NewLookMenus,	TRUE/' \
		    <$^ >tmp_ixprefs.c
		$(CC) -c $(OUR_CFLAGS) -o $@ tmp_ixprefs.c
		rm -f tmp_ixprefs.c

functions.o:	version.h ../library/ixemul.h

ixtrace :	ixtrace.o getopt.o
		$(CC) $(OUR_LDFLAGS) -o $@ $^ $(LIBS)

ixrun:		ixrun.o
		$(CC) $(OUR_LDFLAGS) -o $@ $^ $(LIBS)

ixstack:	ixstack.o
		$(CC) $(OUR_LDFLAGS) -o $@ $^ $(LIBS)

ixtimezone:	ixtimezone.o
		$(CC) $(OUR_LDFLAGS) -o $@ $^ $(LIBS)

ixpipe-handler:	ixpipe-handler.o
		$(CC) -nostdlib -o $@ $? -lc

zic:		zic.o ialloc.o scheck.o getopt.o
		$(CC) -o $@ $^ $(LIBS)

tzselect:	tzselect.ksh
		sed \
			-e 's|AWK=[^}]*|AWK=$(AWK)|g' \
			-e 's|TZDIR=[^}]*|TZDIR=$(TZDIR)|' \
			<$? >$@
		chmod +x $@

yearistype:	yearistype.sh
		rm -f $@
		cp $^ $@
		chmod +x $@

zoneinfo/GMT:	zic yearistype
		rm -rf zoneinfo
		mkdir zoneinfo
		rootme=`pwd` ; cd $(srcdir)/databases ; \
		$$rootme/zic -d $$rootme/zoneinfo -y "sh $$rootme/yearistype" -p $(POSIXRULES) $(DATABASES)

version.h:	../library/parse_version.c ../version.in
		gcc -o parse_version $<
		./parse_version $(srcdir) >$@
		rm -f parse_version

#
#	Clean up the local directory.
#

clean :
		rm -f *.o ixtrace ixprefs ixrun ixtimezone ixstack tzselect
		rm -f zic yearistype ixpipe-handler tmp_ixprefs.c
		rm -rf zoneinfo

clobber :	clean
		$(RM) -f Makefile version.h
