/* Imakefile for the X Desktop Manager.
 * ====================================
 *
 * To create a Makefile from this file, use the xmkmf script supplied
 * with X11R4, or use imake directly.
 *
 * XDTM V2.4 requires the existence of the following tools and 
 * libraries:
 *            + The X Window System Release 4 or greater header files 
 *              and libraries
 *            + The Athena Widget Set (header files + library)
 *            + lex or flex
 *            + yacc or bison
 *            + a smile on your face :-)
 */

/* If you want to use bison instead of yacc then define the symbol BISON */

/* #define BISON */
  
/* If you want to use flex instead of lex, then define the symbol FLEX. */
 
/* #define FLEX */
 

/* If you are going to let imake install xdtm for you in your default
 * directories then define install_defines below, this will compile the
 * locations of the default system config. and help files into xdtm
 * automatically. 
 * Otherwise comment out Install_defines if you want to edit the xdtm.h
 * file by hand to set the default positions. For example, to compile 
 * the program to use a help file in /tmp/help comment out the
 * Install_defines and edit xdtm.h so that SYSTEM_HELP is "/tmp/help".
 */

#define Install_defines   -DSYSTEM_HELP=\"$(LIBDIR)/xdtm/help\" \
                          -DSYSTEM_XDTMRC=\"$(LIBDIR)/xdtm/xdtmrc\" \
                          -DSYSTEM_HELP_PERM=\"$(LIBDIR)/xdtm/perm.help\"

/* Leave the following define even if you comment out the above one. */
#ifndef Install_defines
#define Install_defines  /* Empty */
#endif

/**/# X Desktop Manager version 2.4
/**/# =============================
/**/#
/**/# XDTM has four operating system dependent flags which should be added
/**/# to XDTMOPTIONS:
/**/#
/**/# HAS_STRSTR        This flag should be enabled on systems which  
/**/#                   have the strstr(3) string function. If it is
/**/#                   not enabled xdtm will supply a replacement.
/**/#
/**/# USE_CWD           If your system has the getcwd(3) library routine
/**/#                   then define this flag, otherwise the getwd(3)
/**/#                   will be used.
/**/#
/**/# TRUE_SYSV         If your system does NOT have any BSD extensions
/**/#                   like sockets and symbolic links then define
/**/#                   this flag.
/**/#
/**/# ECHO_N            If the echo(1) program on your machine uses the
/**/#                   '-n' flag to specify that a newline should NOT
/**/#                   be printed after the string then define this
/**/#                   flag. If your echo(1) program supports the '\c'
/**/#                   notation then do NOT define this flag.
/**/#                   If your not sure enter '/bin/echo -n hello' if
/**/#                   the '-n' is printed then do not define this flag.
/**/#
/**/# Additionaly I have found that some linkers demand a space between the 
/**/# -L flag and the library name (eg. HP-UX) if your system also has
/**/# this problem uncomment the 'insane_linker' define below.
/**/#
/**/# If make fails with a syntax error try expanding any tabs in this
/**/# file to spaces. (use the expand(1) utility)
/**/#

    PROTO_DEFINES =
#    PROTO_DEFINES = -DNeedFunctionPrototypes -DNeedWidePrototypes

/* SunOS defines (Comment LOCAL_LDFLAGS out if you want dynamic linking) */
#ifdef SunArchitecture
#     XDTMOPTIONS = -DHAS_STRSTR -DECHO_N -L/usr/openwin/lib
#     XDTMOPTIONS = -DHAS_STRSTR -DECHO_N -L/usr/local/lib/X11R5
     XDTMOPTIONS = -DHAS_STRSTR -DECHO_N
     LOCAL_LDFLAGS = -Bstatic
     EXTRA_LIBRARIES = -Bdynamic -ldl
#endif

/* AIX defines (Comment LOCAL_LDFLAGS out if you want dynamic linking) */
#ifdef RsArchitecture
     XDTMOPTIONS = -DHAS_STRSTR -DECHO_N
LOCAL_LDFLAGS = -bnso -bI:/lib/syscalls.exp
#endif

/* A/UX defines  */
#ifdef MacIIArchitecture
     XDTMOPTIONS = -D_SYSV_SOURCE -D_BSD_SOURCE
#endif

/* Interactive UNIX 
     XDTMOPTIONS = -Xp -DTRUE_SYSV -D_POSIX_SOURCE -D_XOPEN_SOURCE
*/

/* HP-UX defines (Comment LOCAL_LDFLAGS out if you want dynamic linking) */
#ifdef HPArchitecture
#define insane_linker
     XDTMOPTIONS = -DECHO_N -DUSE_CWD -DHAS_STRSTR 
     LOCAL_LDFLAGS = -Wl,-a,archive 
#endif

/* Other defines 
     XDTMOPTIONS = -DHAS_STRSTR -DUSE_CWD -DTRUE_SYSV -DECHO_N 
*/

/**/# Put the name of your C compiler in here, I find gcc best but xdtm 
/**/# will now compile with non-ANSI (K&R) compilers (usually cc).
/**/#
/**/# If using the A/UX cc add '-B /usr/lib/big/ to use the compiler
/**/# with the large symbol table.

              CC = cc -I. -I..  $(XDTMOPTIONS) Install_defines

     CDEBUGFLAGS = -O  /* put -g or -O here. */

/* IBM AIX TO FIX A COMPILER BUG WHEN -O IS SET*/
#ifdef RsArchitecture
     CDEBUGFLAGS =     /* put -g or nothing here, DO NOT OPTIMIZE */
#endif

            SRCS = main.c menus.c appman.c dirman.c \
                   fileman.c parse.c Ext/termwindow.c Ext/iconman.c \
                   Xedw/XedwList.c Xedw/XedwForm.c lexical.l parser.y \
                   scroll_hack.c mystrstr.c buttons.c \
                   display.c listoption.c map.c newfile.c \
                   quit.c doubleclick.c dialogs.c

            OBJS = appman.o \
                   buttons.o \
                   dialogs.o \
                   display.o \
                   dirman.o \
                   doubleclick.o \
                   fileman.o \
                   listoption.o \
                   map.o \
                   main.o \
                   menus.o \
                   mystrstr.o \
                   newfile.o \
                   parse.o \
                   parser.o \
                   lexical.o \
                   quit.o \
                   scroll_hack.o

         DEPLIBS = Ext Xedw regexp

#ifdef insane_linker
 LOCAL_LIBRARIES = -L Ext -lExt -L Xedw -L regexp -lregexp -lXedw $(XAWLIB) $(XMULIB) $(XTOOLLIB) $(XLIB) -lm
#else
# LOCAL_LIBRARIES = -L Ext -lExt -LXedw -Lregexp -lregexp -lXedw $(XAWLIB) $(XMULIB) $(XTOOLLIB) $(XLIB) -lm
 LOCAL_LIBRARIES = -L Ext -lExt -LXedw -Lregexp -lregexp -lXedw -L/usr/local/lib/X11R5 $(XAWLIB) $(XMULIB) $(XTOOLLIB) $(XLIB) -lm
#endif

#ifdef FLEX
             LEX = flex
          LFLAGS = -f -t
#else
   SYS_LIBRARIES = -ll
             LEX = lex
          LFLAGS = -t
#endif

#ifdef BISON
            YACC = bison
          YFLAGS = -y -d
#else
            YACC = yacc
          YFLAGS = -d
#endif


#define IHaveSubdirs
#define PassCDebugFlags 'CC=$(CC)' 'CFLAGS=$(CFLAGS)' 

         SUBDIRS = Ext Xedw regexp

/**/# Make xdtm 
all:: Message xdtm

ComplexProgramTarget(xdtm)

/**/# Make the lexical analyzer as a seperate program for debugging.

NormalProgramTarget(lexical, lexical.c,,$(LOCAL_LIBRARIES),-DDEBUG_LEX)

/**/# Make the parser as a seperate program for debugging

NormalProgramTarget(parser, lexical.c parser.c,,$(LOCAL_LIBRARIES),-DDEBUG_YACC)

NamedMakeSubdirs(Ext, Ext)

NamedMakeSubdirs(Xedw, Xedw)

NamedMakeSubdirs(regexp, regexp)

/**/# Insert the icon directory into the system xdtmrc, keep the original
/**/# in xdtmrc.orig, which is moved back to xdtmrc after the modified 
/**/# xdtmrc has been installed.

install::
	$(MV) xdtmrc xdtmrc.orig
	sed -e 's^\"{icon dir}\"^\"$(LIBDIR)/xdtm/icons\"^' \
	   xdtmrc.orig > xdtmrc
	sed -e 's^iconfile^$(LIBDIR)/xdtm/new_xdtm.xbm^' Xdtm.ad.tmpl > Xdtm.ad

/**/# Install the xdtm execute script file, used to prevent xterms closing
/**/# when the inferier process dies.
InstallProgram(xdtm.sh, $(BINDIR))

/**/# Install the helpfile, system xdtmrc, icon bitmaps and the default
/**/# application defaults.

MakeDirectories(install, $(LIBDIR)/xdtm)
InstallNonExec(help, $(LIBDIR)/xdtm)
InstallNonExec(perm.help, $(LIBDIR)/xdtm)
InstallNonExec(xdtmrc, $(LIBDIR)/xdtm)
InstallNonExec(bitmaps/new_xdtm.xbm, $(LIBDIR)/xdtm)
MakeDirectories(install, $(LIBDIR)/xdtm/icons)
InstallAppDefaults(Xdtm)

install::
	$(CP) icons$(PATHSEP)*$(PATHSEP)*.icon $(LIBDIR)/xdtm/icons
	$(RM) xdtmrc
	$(MV) xdtmrc.orig xdtmrc

/**/# Make the emacs TAGS file

etags:
	etags -t *.h $(SRCS)  

clean::
	$(RM) lexical.c parser.c parser.h xdtmrc.new *.tab.*

parser.c parser.h: parser.y         
	$(YACC) $(YFLAGS) parser.y      
	$(MV) y.tab.c parser.c          
	$(MV) y.tab.h parser.h      

lexical.c: parser.h lexical.l
	$(LEX) $(LFLAGS) lexical.l > lexical.c

lexical.o: parser.h

tar: 
	(make clean;tar cf - .  | compress > ../xdtm-2.4.tar.Z)

shar:
	@echo "This will only work if you have shar 3.49 or later"
	@echo "I have named this version of shar 'shar3.49'"
	(make clean;shar3.49 -a -n xdtm -c -F -o ../xdtm -L 60 ./README .)

Message:
	@( \
	echo "********************************************************"; \
	echo "*        Compiling the X Desktop Manager V2.4          *"; \
	echo "*                                                      *"; \
	echo "*   Have you configured the master Imakefile in this   *"; \
	echo "*            directory for this machine?               *"; \
	echo "*                                                      *"; \
	echo "*   Have you made the Makefiles in Xedw and regexp?    *"; \
	echo "*           if not type 'make Makefiles'               *"; \ 
	echo "*                                                      *"; \
	echo "* Available targets: xdtm          (default)           *"; \
	echo "*                    install     - install xdtm        *"; \
	echo "*                    install.man - install man page    *"; \
	echo "*                    etags       - Make emacs tags     *"; \
	echo "*                    clean       - Clean directory     *"; \
	echo "*                    tar         - Archive xdtm        *"; \
	echo "*                    shar        - Archive xdtm        *"; \
	echo "********************************************************"; \
	echo ""; \
	)


