#
# Copyright (c) 1999-2009, Paul Mattes.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#     * Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above copyright
#       notice, this list of conditions and the following disclaimer in the
#       documentation and/or other materials provided with the distribution.
#     * Neither the names of Paul Mattes nor the names of his contributors
#       may be used to endorse or promote products derived from this software
#       without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY PAUL MATTES "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL PAUL MATTES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

# Makefile for x3270 (for use without xmkmf/imake)

RM = rm -f
CC = @CC@

SRCS = about.c actions.c ansi.c apl.c charset.c child.c CmeBSB.c Cme.c \
	CmeLine.c CmplxMenu.c ctlr.c dialog.c display8.c ft.c ft_cut.c \
	ft_dft.c host.c Husk.c idle.c keymap.c keypad.c keysym2ucs.c kybd.c \
	macros.c main.c menubar.c popups.c print.c printer.c proxy.c \
	resolver.c resources.c rpq.c save.c screen.c scroll.c see.c select.c \
	sf.c status.c tables.c telnet.c toggles.c trace_ds.c unicode.c \
	unicode_dbcs.c utf8.c util.c xio.c
VOBJS = about.o actions.o ansi.o apl.o charset.o child.o CmeBSB.o Cme.o \
	CmeLine.o CmplxMenu.o ctlr.o dialog.o display8.o fallbacks.o ft.o \
	ft_cut.o ft_dft.o host.o Husk.o idle.o keymap.o keypad.o keysym2ucs.o \
	kybd.o macros.o main.o menubar.o popups.o print.o printer.o proxy.o \
	resolver.o resources.o rpq.o save.o screen.o scroll.o see.o select.o \
	sf.o status.o tables.o telnet.o toggles.o trace_ds.o unicode.o \
	unicode_dbcs.o utf8.o util.o xio.o
OBJS1 = $(VOBJS) version.o
FONTS = 3270-12.pcf.gz 3270-12b.pcf.gz 3270-20.pcf.gz 3270-20b.pcf.gz \
	3270.pcf.gz 3270b.pcf.gz 3270gr.pcf.gz 3270gt12.pcf.gz \
	3270gt12b.pcf.gz 3270gt16.pcf.gz 3270gt16b.pcf.gz 3270gt24.pcf.gz \
	3270gt24b.pcf.gz 3270gt32.pcf.gz 3270gt32b.pcf.gz 3270gt8.pcf.gz \
	3270h.pcf.gz

all:: x3270 x3270if $(FONTS)

LIBDIR = @libdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
sysconfdir = @sysconfdir@
datarootdir = @datarootdir@
LIBX3270DIR = @LIBX3270DIR@
MANDIR = @mandir@
BINDIR = @bindir@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
CIFONTDIR = @CIFONTDIR@

#CDEBUGFLAGS = -g -Wall

XCPPFLAGS = -I. @XINC@ -DLIBX3270DIR=\"$(LIBX3270DIR)\" @XANSI@ @XPRECOMP@ @CPPFLAGS@
CFLAGS = @CFLAGS@ $(XCPPFLAGS) $(CDEBUGFLAGS)
LDFLAGS = @XLIB@ @LDFLAGS@
LIBS = @LIBS@ -lXaw -lXmu -lXt -lX11

version.o: $(VOBJS) version.txt mkversion.sh
	@chmod +x mkversion.sh version.txt
	sh ./mkversion.sh $(CC) x3270

fallbacks.c: mkfb X3270.xad
	$(RM) $@
	./mkfb X3270.xad $@

x3270: $(OBJS1)
	$(CC) -o $@ $(OBJS1) $(LDFLAGS) $(LIBS)
x3270if: x3270if.o
	$(CC) -o $@ x3270if.o $(LDFLAGS) $(LIBS)

3270-12.pcf.gz: 3270-12.bdf
	bdftopcf 3270-12.bdf | gzip >$@
3270-12b.pcf.gz: 3270-12b.bdf
	bdftopcf 3270-12b.bdf | gzip >$@
3270-20.pcf.gz: 3270-20.bdf
	bdftopcf 3270-20.bdf | gzip >$@
3270-20b.pcf.gz: 3270-20b.bdf
	bdftopcf 3270-20b.bdf | gzip >$@
3270.pcf.gz: 3270.bdf
	bdftopcf 3270.bdf | gzip >$@
3270b.pcf.gz: 3270b.bdf
	bdftopcf 3270b.bdf | gzip >$@
3270gr.pcf.gz: 3270gr.bdf
	bdftopcf 3270gr.bdf | gzip >$@
3270gt12.pcf.gz: 3270gt12.bdf
	bdftopcf 3270gt12.bdf | gzip >$@
3270gt12b.pcf.gz: 3270gt12b.bdf
	bdftopcf 3270gt12b.bdf | gzip >$@
3270gt16.pcf.gz: 3270gt16.bdf
	bdftopcf 3270gt16.bdf | gzip >$@
3270gt16b.pcf.gz: 3270gt16b.bdf
	bdftopcf 3270gt16b.bdf | gzip >$@
3270gt24.pcf.gz: 3270gt24.bdf
	bdftopcf 3270gt24.bdf | gzip >$@
3270gt24b.pcf.gz: 3270gt24b.bdf
	bdftopcf 3270gt24b.bdf | gzip >$@
3270gt32.pcf.gz: 3270gt32.bdf
	bdftopcf 3270gt32.bdf | gzip >$@
3270gt32b.pcf.gz: 3270gt32b.bdf
	bdftopcf 3270gt32b.bdf | gzip >$@
3270gt8.pcf.gz: 3270gt8.bdf
	bdftopcf 3270gt8.bdf | gzip >$@
3270h.pcf.gz: 3270h.bdf
	bdftopcf 3270h.bdf | gzip >$@

install:: x3270 x3270if
	[ -d $(DESTDIR)$(BINDIR) ] || \
		mkdir -p $(DESTDIR)$(BINDIR)
	$(INSTALL_PROGRAM) x3270 $(DESTDIR)$(BINDIR)/x3270
	$(INSTALL_PROGRAM) x3270if $(DESTDIR)$(BINDIR)/x3270if
install::
	[ -d $(DESTDIR)$(LIBX3270DIR) ] || \
		mkdir -p $(DESTDIR)$(LIBX3270DIR)
	[ -r $(DESTDIR)$(LIBX3270DIR)/ibm_hosts ] || \
		$(INSTALL_DATA) ibm_hosts $(DESTDIR)$(LIBX3270DIR)/ibm_hosts
install::
	[ -d $(DESTDIR)$(CIFONTDIR) ] || \
		mkdir -p $(DESTDIR)$(CIFONTDIR)
	@for i in $(FONTS); \
	do	(set -x; $(INSTALL_DATA) $$i $(DESTDIR)$(CIFONTDIR)/$$i); \
	done
	-chmod u+w $(DESTDIR)$(CIFONTDIR) $(DESTDIR)$(CIFONTDIR)/fonts.dir
	mkfontdir $(DESTDIR)$(CIFONTDIR)
	chmod u=rwx,go=rx $(DESTDIR)$(CIFONTDIR)
	chmod a=r $(DESTDIR)$(CIFONTDIR)/fonts.dir

install.man:
	[ -d $(DESTDIR)$(MANDIR)/man1 ] || \
		mkdir -p $(DESTDIR)$(MANDIR)/man1
	[ -d $(DESTDIR)$(MANDIR)/man5 ] || \
		mkdir -p $(DESTDIR)$(MANDIR)/man5
	$(INSTALL_DATA) x3270.man $(DESTDIR)$(MANDIR)/man1/x3270.1
	$(INSTALL_DATA) x3270if.man $(DESTDIR)$(MANDIR)/man1/x3270if.1
	$(INSTALL_DATA) x3270-script.man $(DESTDIR)$(MANDIR)/man1/x3270-script.1
	$(INSTALL_DATA) ibm_hosts.man $(DESTDIR)$(MANDIR)/man5/ibm_hosts.5

clean::
	$(RM) x3270 x3270if *.o *pcf.gz mkfb fallbacks.c

depend:
	gccmakedep $(XCPPFLAGS) -s "# DO NOT DELETE" $(SRCS)

# -------------------------------------------------------------------------
# dependencies generated by makedepend

# DO NOT DELETE
