/*
 * $Id: Imakefile,v 1.124 1998/01/29 03:05:57 jik Exp $
 *
 * xrn - an X-based NNTP news reader
 *
 * Copyright (c) 1988-1993, Ellen M. Sentovich and Rick L. Spickelmier.
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose and without fee is hereby granted, provided
 * that the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of the University of California not
 * be used in advertising or publicity pertaining to distribution of 
 * the software without specific, written prior permission.  The University
 * of California makes no representations about the suitability of this
 * software for any purpose.  It is provided "as is" without express or
 * implied warranty.
 *
 * THE UNIVERSITY OF CALIFORNIA DISCLAIMS ALL WARRANTIES WITH REGARD TO 
 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 
 * FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE FOR
 * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */

/*
 * Imakefile - Imakefile for XRN
 */

/*
 * If you want to compile the MOTIF version of XRN, define MOTIF here.
 *
 * *** NOTE WELL *** that the Motif version of XRN is not yet
 * completely implemented, it probably doesn't work properly, and it's
 * unsupported.  If you want to help finish it, please let me know.
 * Otherwise, you probably shouldn't try to compile it.
 */
/* #define MOTIF */

/*
 * If you want the program to be called something other than "xrn",
 * change PROGRAMS.  If you want the app-defaults class to be something
 * other than XRn, change APPDEFAULTS.
 */

PROGRAMS = xrn
#ifdef MOTIF
APPDEFAULTS = XRn_Motif
#else
APPDEFAULTS = XRn
#endif

/*
 * What language do you want messages to be in?  Legal values are
 * "english", "german", and "french"; case is significant!
 */
LANGUAGE= english
/* LANGUAGE= german */
/* LANGUAGE= french */

#ifdef BandAidCompiler
#include BandAidCompiler
#endif

/*
 * If you use InterNetNews, set this define to the location of your
 * InterNetNews library.
 */
/* #define INN /usr/local/lib/libinn.a */

#ifdef INN
/*
 * If you are using INN and the INN header files are not installed
 * where the compiler will find them, add a "-Idir" flag here to specify
 * where they are.
 */
INNINC= 
#endif

/*
 * If you need to link against special libraries, put them in
 * XRN_LOAD_FLAGS.  What's here may or may not be right for your
 * system.  If in doubt, leave it alone and see what happens.
 */

#if defined(XmacIIServer) || defined(SGIArchitecture)
XRN_LOAD_FLAGS = -lPW
#endif

#if defined(RsArchitecture)
XRN_LOAD_FLAGS = -lPW -lbsd
#endif

#if defined(AMIX)
XRN_LOAD_FLAGS = -lucb -lm -lgen
#endif

#if defined(SunArchitecture) && (OSMajorVersion > 4)
#define SolarisArchitecture
XRN_LOAD_FLAGS = -lgen
#endif

#if defined(BSD386Architecture) || defined(NetBSDArchitecture)
XRN_LOAD_FLAGS = -lcompat
#endif

#ifdef SCO
XRN_LOAD_FLAGS = -lintl
#endif

#if defined(MotoR4Architecture)
XRN_LOAD_FLAGS = -lnsl -lsocket -lgen
#endif

/*
 * You probably won't need to change most of this.
 */

#ifdef MOTIF
# ifndef XMLIB
   XMLIB = -lXm
# endif
 # set this to whatever your system needs, might should put this above
 # in the O.S. sections
 XM_LIB_PATH = -L/usr/dt/lib
 X_LIBRARIES = $(XM_LIB_PATH) $(XMLIB) $(XAWLIB) $(XMULIB) $(XTOOLLIB) $(XLIB) $(XMEXTRA_LIBS)
 DEPLIBS = $(DEPXMLIB) $(DEPXAWLIB) $(DEPXTOOLLIB) $(DEPXLIB)
#else
 X_LIBRARIES = XawClientLibs
 DEPLIBS = XawClientDepLibs
#endif

/*
 * Special compiler flags for your platform.  If in doubt, just leave
 * them alone and see what happens.
 */

#if defined(HPArchitecture)
XRN_DEFINES = -D_HPUX_SOURCE
#endif /* HPArchitecture */

#if defined(aiws)
XRN_DEFINES = -a -Nn3000 -Nd4000
#else
# if defined(HCRevision)
XRN_DEFINES = -DUNIXCPP -DNOSTDHDRS
# else
#  if defined(gould)
XRN_DEFINES = -DNOVOID -DLONGINT -UINTSPRINTF
#  else
#   if defined(SolarisArchitecture)
XRN_DEFINES = -DSOLARIS
#   endif
#  endif
# endif
#endif

/*
 * You probably don't need to change anything in this block.
 */

#ifdef OV_CAMBRIDGE
LEX		= flex
SITE_DEFINES	+= -DOV_CAMBRIDGE -I.
IMAKE_DEFINES	+= -DOV_CAMBRIDGE
ifeq ($(findstring gcc,$(CC)),gcc)
CDEBUGFLAGS	= -g -Wall -DGCC_WALL -pedantic
endif
REGEX_OBJS	= /tools/lib/gnuregex.o

depend::	regex.h

regex.h:	/tools/include/gnuregex.h
	ln -s /tools/include/gnuregex.h regex.h
#endif /* OV_CAMBRIDGE */

#ifdef FreeBSDArchitecture
EXTRA_LIBRARIES	+= -lgnuregex
#endif

#ifdef LINUX_DIST
IMAKE_DEFINES	+= -DLINUX_DIST
SITE_DEFINES	+= -I/b/build/regex-0.12
SITE_DEFINES	+= -DCONFIG_H_IS_OK -D_GNU_SOURCE
LEX		=  flex
CDEBUGFLAGS	+= -Wall -DGCC_WALL -g -pedantic
REGEX_OBJS	= /b/build/regex-0.12/regex.o
#endif

#if defined(INN)
INN_LOAD_FLAGS = INN
INN_DEFINES = -DINN $(INNINC)
CLIENTSRC =
CLIENTOBJ =
#else
CLIENTSRC = clientlib.c
CLIENTOBJ = clientlib.o
#endif

/*
 * You probably don't need to edit anything below this line.
 */

#ifdef MOTIF
GUI_DEFINES = -DMOTIF
#endif

#if HasVoidSignalReturn
SIGNAL_DEFINES = -DVOID_SIGNAL
#endif

LOCAL_LIBRARIES = $(X_LIBRARIES) $(XRN_LOAD_FLAGS) $(INN_LOAD_FLAGS)
DEFINES = $(XRN_DEFINES) $(GUI_DEFINES) $(SIGNAL_DEFINES) $(INN_DEFINES) \
        $(SITE_DEFINES) -DXRN_LANG_$(LANGUAGE) \
	-DXRNAPPDIR=\"$(XAPPLOADDIR)\" \
	-DXRN_APP_CLASS=\"$(APPDEFAULTS)\" -DXRN

HDRS = mesg_strings.h
SRCS = avl.c $(CLIENTSRC) compose.c cursor.c dialogs.c \
       refile.c mesg.c error_hnds.c newsrcfile.c resources.c    \
       internals.c save.c server.c utils.c xrn.c \
       xthelper.c rcyacc.c cancel.c vprintf.c tempnam.c strstr.c \
       strtok.c mesg_strings.c Text.c ngMode.c artMode.c allMode.c \
       addMode.c snapshot.c artstruct.c Buttons.c InfoLine.c ButtonBox.c \
       busyCursor.c varfile.c activecache.c sort.c getdate2.c hash.c \
       killfile.c InfoDialog.c Frame.c Xmisc.c file_cache.c
LOCAL_OBJS = avl.o $(CLIENTOBJ) compose.o cursor.o dialogs.o \
       refile.o mesg.o error_hnds.o newsrcfile.o resources.o    \
       internals.o save.o server.o utils.o xrn.o \
       xthelper.o rcyacc.o cancel.o vprintf.o tempnam.o strstr.o \
       strtok.o mesg_strings.o Text.o ngMode.o artMode.o allMode.o \
       addMode.o snapshot.o artstruct.o Buttons.o InfoLine.o ButtonBox.o \
       busyCursor.o varfile.o activecache.o sort.o getdate2.o hash.o \
       killfile.o InfoDialog.o Frame.o Xmisc.o file_cache.o
OBJS = $(LOCAL_OBJS) $(REGEX_OBJS)

all:: mesg_strings.h

depend:: rclex.c rcyacc.c mesg_strings.h getdate2.c

ComplexProgramTarget($(PROGRAMS))
InstallAppDefaults($(APPDEFAULTS))

/*
 * This line is in two places, above and here, because some versions
 * of Make unfortunately have a bug which causes them to process
 * dependencies in reverse of the order they appear in the Makefile.
 * On those systems, if the "all:: mesg_strings.h" line below isn't
 * present, typing "xmkmf" followed by "make" won't work, because the
 * program will try to build the XRN object and $(PROGRAMS) before it
 * tries to build mesg_strings.h.  Doing "make depend" solves this
 * problem, but I don't want to require people to do "make depend" in
 * order to build the program, so I'm adding a second dependency on
 * mesg_strings.h, after the "all:: xrn" dependency generated by the
 * ComplexProgramTarget invocation above.
 */
all:: mesg_strings.h

#if HasSaberC == YES
# saber_xrn:: rclex.c
# osaber_xrn:: rclex.c
#endif

/*
 * If you are using flex instead of lex (for example, Linux uses flex
 * by default instead of lex), you should NOT be giving flex the "-l"
 * argument.  If you see "flex -l rclex.l" or "lex -l rclex.l" when
 * building, then you should probably add "LEX=flex" or "LEX=lex"
 * below.
 */
rclex.c: rclex.l

rcyacc.o: rclex.c avl.h news.h newsrcfile.h utils.h

mesg_strings.h: mesg_strings.c mesg_str.awk
	-rm -f mesg_str.tmp
	awk -f mesg_str.awk mesg_strings.c > mesg_str.tmp
	@set -x; if cmp -s mesg_str.tmp mesg_strings.h; then \
		rm -f mesg_str.tmp; \
	else \
		rm -f mesg_strings.h; \
		mv mesg_str.tmp mesg_strings.h; \
	fi

$(LOCAL_OBJS): config.h

clean::
	$(RM) mesg_strings.h mesg_str.tmp

xrn-man.c: xrn-man.sym config.h
	$(RM) xrn-man.tmp xrn-man.c
	awk 'BEGIN {printf("#include \"config.h\"\n");} {printf("#ifdef %s\nx%sx value %s value\n#else\nx%sx\n#endif\n",$$0,$$0,$$0,$$0);}' \
		xrn-man.sym > xrn-man.tmp
	mv xrn-man.tmp xrn-man.c

xrn-man.cpp: xrn-man.c
	$(RM) -f xrn-man.tmp xrn-man.cpp
	$(CC) -E $(CFLAGS) xrn-man.c > xrn-man.tmp
	mv xrn-man.tmp xrn-man.cpp

xrn-man.sed: xrn-man.cpp
	$(RM) -f xrn-man.tmp xrn-man.sed
	sed -e 's|^x\(.*\)x$$|/x\1_STARTx/,/x\1_ENDx/d|' \
	    -e 's|^x\(.*\)x value [ 	]*"\(.*\)"[ 	]* value.*|s,x\1x,\2,|' \
	    -e 's|^x\(.*\)x value [ 	]*\([^ 	].*[^ 	]\)[ 	]* value.*|s,x\1x,\2,|' \
	    -e 's|^x\(.*\)x value [ 	]*\([^ 	]\)[ 	]* value.*|s,x\1x,\2,|' \
	    -e 's|^x\(.*\)x.*||' \
	    -e '/^#/d' \
		xrn-man.cpp > xrn-man.tmp
	echo '/^x.*_STARTx/d' >> xrn-man.tmp
	echo '/^x.*_ENDx/d' >> xrn-man.tmp
	mv xrn-man.tmp xrn-man.sed

all:: $(PROGRAMS).man

$(PROGRAMS).man:: xrn-man.src xrn-man.sed
	$(RM) xrn-man.tmp $(PROGRAMS).man
	sed -f xrn-man.sed xrn-man.src > xrn-man.tmp
	mv xrn-man.tmp $(PROGRAMS).man

clean::
	$(RM) xrn-man.tmp xrn-man.c xrn-man.cpp xrn-man.sed $(PROGRAMS).man

#ifdef MOTIF
TKSED=	-e 's/MOTIF//' -e '/XAW/d' -e 's/notify()/Activate()/' \
	-e 's/unset()/Disarm()/' -e 's/set()/Arm()/' \
	-e 's/\([*.]\)label:/\1labelString:/' \
	-e 's/no-op(RingBell/beep(/' \
	-e 's/\.\([^.]*\)\.baseTranslations/*\1*translations/' \
	-e 's/baseTranslations/translations/' \
	-e 's/>Down/>osfDown/' -e 's/>Up/>osfUp/' \
	-e 's/>Left/>osfLeft/' -e 's/>Right/>osfRight/'
#else
TKSED=	-e 's/XAW//' -e '/MOTIF/d'
#endif
TKSED2=	-e 's/XawSet()/set()/' -e 's/XawNotify()/notify()/' \
	-e 's/XawUnSet()/unset()/'

$(APPDEFAULTS).ad: XRn.src
	-rm -f $(APPDEFAULTS).tmp $(APPDEFAULTS).ad
	sed -e 's/LANG_$(LANGUAGE)//' -e '/LANG_/d' $(TKSED) $(TKSED2) \
		-e 's/xAPP_CLASSx/$(APPDEFAULTS)/' \
		XRn.src > $(APPDEFAULTS).tmp
	mv $(APPDEFAULTS).tmp $(APPDEFAULTS).ad

all:: $(APPDEFAULTS).ad

clean::
	$(RM) $(APPDEFAULTS).ad $(APPDEFAULTS).tmp

getdate2.c: getdate.c
	sed -e 's/yy/getdate_yy/g' getdate.c > $@.tmp
	mv $@.tmp $@

clean::
	$(RM) getdate.c getdate2.c.tmp getdate2.c rclex.c rcyacc.c
