#
# 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 c3270 (console-based 3270 emulator)

RM = rm -f
CC = @CC@

all:: c3270 x3270if

SRCS = actions.c ansi.c apl.c c3270.c charset.c child.c ctlr.c \
	ft.c ft_cut.c ft_dft.c glue.c help.c host.c icmd.c idle.c keymap.c \
	kybd.c macros.c print.c printer.c proxy.c readres.c resolver.c \
	resources.c rpq.c screen.c see.c sf.c tables.c telnet.c toggles.c \
	trace_ds.c unicode.c unicode_dbcs.c utf8.c util.c xio.c XtGlue.c \
	menubar.c keypad.c
VOBJS = actions.o ansi.o apl.o c3270.o charset.o child.o ctlr.o fallbacks.o \
	ft.o ft_cut.o ft_dft.o glue.o help.o host.o icmd.o idle.o keymap.o \
	kybd.o macros.o print.o printer.o proxy.o readres.o resolver.o \
	resources.o rpq.o screen.o see.o sf.o tables.o telnet.o toggles.o \
	trace_ds.o unicode.o unicode_dbcs.o utf8.o util.o xio.o XtGlue.o \
	menubar.o keypad.o
OBJS1 = $(VOBJS) version.o

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@

#CDEBUGFLAGS = -g -Wall

XCPPFLAGS = -I. -DLIBX3270DIR=\"$(LIBX3270DIR)\" @XPOSIX@ @XANSI@ @XPRECOMP@ @CPPFLAGS@
CFLAGS = @CFLAGS@ $(XCPPFLAGS) $(CDEBUGFLAGS)
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@

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

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

keypad.o: keypad.c compiled_keypad.h

compiled_keypad.h: keypad.full keypad.labels keypad.map keypad.outline keypad.callbacks mkkeypad
	./mkkeypad >$@

mkkeypad: mkkeypad.o
	$(CC) -o $@ mkkeypad.o

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

@PR@all::

install:: c3270 x3270if
	[ -d $(DESTDIR)$(BINDIR) ] || \
		mkdir -p $(DESTDIR)$(BINDIR)
	$(INSTALL_PROGRAM) c3270 $(DESTDIR)$(BINDIR)/c3270
	$(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
@PR@install::

install.man:
	[ -d $(DESTDIR)$(MANDIR)/man1 ] || \
		mkdir -p $(DESTDIR)$(MANDIR)/man1
	[ -d $(DESTDIR)$(MANDIR)/man5 ] || \
		mkdir -p $(DESTDIR)$(MANDIR)/man5
	$(INSTALL_DATA) c3270.man $(DESTDIR)$(MANDIR)/man1/c3270.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

# Cygwin standalone distribution
standalone: c3270-standalone.zip

c3270-standalone.zip: c3270 make-cygwin-standalone runc3270.bat
	./make-cygwin-standalone

clean::
	$(RM) c3270 *.o mkfb fallbacks.c
@PR@clean::

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

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

# DO NOT DELETE
