/* Makefile.in -- cpp input for the src directory's Makefile
   Copyright (C) 1993, 1994 John Harper <jsh@ukc.ac.uk>

   Jade is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   Jade is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with Jade; see the file COPYING.  If not, write to
   the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */

#ifdef PROFILE
 CFLAGS = -g -pg
 LDFLAGS = -g -pg
#else
 /* The reason for these contradictory flags is so that I can get a binary
    with full debugging information by simply relinking.  */
 CFLAGS = -g
 LDFLAGS = -s
#endif

#define MAKEFILE_CONFIG
#include "config.h"

COMMON_SRCS =	buffers.c commandline.c commands.c edit.c editcommands.c \
		editrect.c find.c glyphs.c housekeeping.c io.c keys.c lisp.c \
		lispcmds.c lispmach.c main.c misc.c movement.c refresh.c \
		render.c streams.c stringmem.c symbols.c undo.c values.c \
		windows.c
COMMON_HDRS =	jade.h edit.h lisp.h value.h keys.h config.h stringmem.h \
		doc-strings.h

X11_SRCS +=	x11_commandline.c x11_display.c x11_eventloop.c x11_keys.c \
		x11_misc.c x11_render.c x11_windows.c
X11_HDRS +=	x11_defs.h x11_windowsys.h

UNIX_SRCS +=	lists.c unix_misc.c unix_processes.c unix_memory.c \
		unix_server.c
UNIX_HDRS +=	unix_defs.h

AMIGA_SRCS +=	amiga_clipboard.c amiga_commandline.c amiga_display.c \
		amiga_eventloop.c amiga_keys.c amiga_memory.c amiga_menus.c \
		amiga_minrexx.c amiga_misc.c amiga_render.c amiga_server.c \
		amiga_stksize.c amiga_windows.c
AMIGA_HDRS +=	amiga_defs.h amiga_windowsys.h

SRCS = $(COMMON_SRCS)
HDRS = $(COMMON_HDRS)

RE_LIB = regexp/libregexp.a
LIBS = $(RE_LIB)

#ifdef HAVE_X11
SRCS += $(X11_SRCS)
HDRS += $(X11_HDRS)
LIBS += -L$(XLIBDIR) -lX11
#endif /* HAVE_X11 */

#ifdef HAVE_UNIX
SRCS += $(UNIX_SRCS)
HDRS += $(UNIX_HDRS)
#endif /* HAVE_UNIX */

#ifdef HAVE_AMIGA
SRCS += $(AMIGA_SRCS)
HDRS += $(AMIGA_HDRS)
#endif /* HAVE_AMIGA */

OBJS = $(SRCS:.c=.o)

/* Redefine how to make `.o' from `.c', the -DJADE_DIR has to be here
   so CFLAGS is available to the user.  */
.c.o :
	$(CC) -c $(CFLAGS) $(CPPFLAGS) -DJADE_DIR=_JADE_DIR -o $@ $<

all : jade jadeclient

jade : jade_protos.h $(OBJS) $(RE_LIB)
	$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)

jade_protos.h : stripproto $(SRCS)
	./stripproto -o $@ $(SRCS)

/* I guess that properly this should depend on $(SRCS) but that would mean
   that whenever *any* source file is modified everything has to be re-built!
   This way when a doc-string is changed in a source file you should delete
   the doc-strings.h file to force it to be rebuilt.  */
doc-strings.h : makedoc
	./makedoc DOC.bare doc-strings.h $(COMMON_SRCS) $(X11_SRCS) \
					 $(UNIX_SRCS) $(AMIGA_SRCS)
	cp DOC.bare ../DOC

stripproto : stripproto.o
	$(CC) $(LDFLAGS) -o $@ stripproto.o

makedoc : makedoc.o
	$(CC) $(LDFLAGS) -o $@ makedoc.o

/* Doesn't check if libregexp.a is up to date -- just that it exists  */
$(RE_LIB) :
	(cd regexp && $(MAKE))

#ifdef HAVE_UNIX
jadeclient : unix_client.o
	$(CC) $(LDFLAGS) -o $@ unix_client.o
#endif

#ifdef HAVE_AMIGA
jadeclient : amiga_client.o
	$(CC) $(LDFLAGS) -o $@ amiga_client.o
#endif

nobak :
	-rm -f *~

clean : nobak
	-rm -f *.o jade_protos.h doc-strings.h core

realclean : clean
	-rm -f jade jadeclient DOC.bare makedoc stripproto
	-rm -f config.* Makefile
	-(cd regexp && $(MAKE) clean)

buffers.o	: $(HDRS)
commandline.o	: $(HDRS)
commands.o	: $(HDRS)
edit.o		: $(HDRS)
editcommands.o	: $(HDRS)
editrect.o	: $(HDRS)
find.o		: $(HDRS)
glyphs.o	: $(HDRS)
housekeeping.o	: $(HDRS)
io.o		: $(HDRS)
keys.o		: $(HDRS)
lisp.o		: $(HDRS)
lispcmds.o	: $(HDRS)
lispmach.o	: $(HDRS)
main.o		: $(HDRS) revision.h
misc.o		: $(HDRS) revision.h
movement.o	: $(HDRS)
refresh.o	: $(HDRS)
render.o	: $(HDRS)
streams.o	: $(HDRS)
stringmem.o	: $(HDRS)
symbols.o	: $(HDRS)
undo.o		: $(HDRS)
values.o	: $(HDRS)
windows.o	: $(HDRS)

#ifdef HAVE_X11
x11_commandline.o : $(HDRS)
x11_display.o	: $(HDRS)
x11_eventloop.o : $(HDRS)
x11_keys.o	: $(HDRS)
x11_misc.o	: $(HDRS)
x11_render.o	: $(HDRS)
x11_windows.o	: $(HDRS) revision.h
#endif /* HAVE_X11 */

#ifdef HAVE_UNIX
unix_memory.o	: $(HDRS)
unix_misc.o	: $(HDRS)
unix_processes.o : $(HDRS)
unix_server.o	: $(HDRS)
#endif /* HAVE_UNIX */

#ifdef HAVE_AMIGA
amiga_client.o	: amiga_server.h
amiga_clipboard.o : $(HDRS)
amiga_commandline.o: $(HDRS)
amiga_display.o : $(HDRS)
amiga_eventloop.o : $(HDRS)
amiga_keys.o	: $(HDRS)
amiga_memory.o	: $(HDRS)
amiga_menus.o	: $(HDRS)
amiga_minrexx.o : $(HDRS)
amiga_misc.o	: $(HDRS)
amiga_render.o	: $(HDRS)
amiga_server.o	: $(HDRS) amiga_server.h
amiga_stksize.o : $(HDRS)
amiga_windows.o : $(HDRS) revision.h
#else
lists.o		: $(HDRS)
#endif /* HAVE_AMIGA */
