#
# Makefile for mg3 and beyond, for use with Aztec v3.6 and beyond. Uses make
# to build things.  Uses 32-bit ints
#
CC = cc
LD = ln
# Names of the directories where we find sources
MG = /mg
AMIGA = /amiga
# and objects.... (must be configured for each user
LIBOBJ = AZTEC:rexxbind/rexxvars.o AZTEC:rexxbind/rexxglue.o

#
# set things up so we get .o files built correctly
#
PRE = -hi user:include/includes.pre
#
# Use 32bit ints, and enlarge the literal space for the compiler
INCLUDES = -I$(AMIGA) -I/h
CFLAGS = +L -Z4096 $(INCLUDES)
LFLAGS = 
LIBS = -lc32
ALIBS = -la32 -lc32

# list of amiga-specific source files
AMIGASRC1 = $(AMIGA)/ttymouse.c $(AMIGA)/ttymenu.c $(AMIGA)/menustack.c \
	$(AMIGA)/iconify.c $(AMIGA)/ttyicon.c $(AMIGA)/spawn.c \
	$(AMIGA)/offset.c

AMIGASRC2 = $(AMIGA)/ttyio.c $(AMIGA)/tty.c $(AMIGA)/ttykbd.c \
	$(AMIGA)/fileio.c $(AMIGA)/console.c $(AMIGA)/dirio.c $(AMIGA)/rexx.c

# list of mg system-independent source files
MGSRC1 = $(MG)/macro.c $(MG)/regex.c $(MG)/re_search.c $(MG)/dired.c \
	$(MG)/basic.c $(MG)/dir.c $(MG)/file.c $(MG)/line.c $(MG)/match.c \
	$(MG)/paragraph.c $(MG)/random.c $(MG)/region.c $(MG)/search.c \
	$(MG)/version.c $(MG)/window.c

MGSRC2 = $(MG)/word.c $(MG)/buffer.c $(MG)/display.c $(MG)/echo.c \
	$(MG)/extend.c $(MG)/help.c $(MG)/kbd.c $(MG)/keymap.c $(MG)/main.c \
	$(MG)/modes.c $(MG)/cinfo.c $(MG)/bind.c $(MG)/alloca.c

# list of amiga-specific object files
AMIGAOBJ = ttymouse.o ttymenu.o menustack.o iconify.o ttyicon.o spawn.o \
	ttyio.o tty.o ttykbd.o fileio.o console.o dirio.o offset.o rexx.o

# list of mg objects
MGOBJ1 = macro.o regex.o re_search.o dired.o basic.o dir.o file.o line.o \
	match.o paragraph.o random.o region.o search.o version.o window.o
MGOBJ2 = word.o buffer.o display.o echo.o extend.o help.o kbd.o keymap.o \
	main.o modes.o bind.o cinfo.o alloca.o

OBJ = $(MGOBJ1) $(MGOBJ2) $(AMIGAOBJ)

#
# The editor
#
xmg:	$(OBJ)
	$(LD) $(LFLAGS) -o xmg $(OBJ) $(LIBOBJ) $(LIBS)

#
# The editor with arp (be sure to set option use_arp in your config)
#
xmga:	$(OBJ)
	$(LD) $(LFLAGS) -o xmg $(OBJ) $(LIBOBJ) $(ALIBS)

# the delete command can only handle 10 command line args, so...
clean:
	-delete #?.o

clobber: clean
	-delete xmg

#
# build the dependency list for the .h files used by all sources. We do
# this in multiple passes so to avoid problems with the long command line
# generate when you slap all the sources together.
# Note that there are faster, but more environment-dependent, ways to do
# turn the output of the makemake's into an lmkfile. We avoid those
# on purpose.
#
depend:
	@echo "Making dependencies. The following include files will be missing:"
	@echo "config.h lisp.h syntax.h"
	@makemake >ram:mg-amg1 -M $(INCLUDES) $(AMIGASRC1)
	@grep "Couldn't open" ram:mg-amg1
	@makemake >ram:mg-amg2 -M $(INCLUDES) $(AMIGASRC2)
	@grep "Couldn't open" ram:mg-amg2
	@makemake >ram:mg-mg1 -M $(INCLUDES) $(MGSRC1)
	@grep "Couldn't open" ram:mg-mg1
	@makemake >ram:mg-mg2 -M $(INCLUDES) $(MGSRC2)
	@grep "Couldn't open" ram:mg-mg2
	@grep >ram:mgx-amg1 -v "Couldn't open" ram:mg-amg1
	@grep >ram:mgx-amg2 -v "Couldn't open" ram:mg-amg2
	@grep >ram:mgx-mg1 -v "Couldn't open" ram:mg-mg1
	@grep >ram:mgx-mg2 -v "Couldn't open" ram:mg-mg2
	@delete ram:mg-mg1 ram:mg-mg2 ram:mg-amg1 ram:mg-amg2
	@join $(AMIGA)/makefile.MANX ram:mgx-mg1 ram:mgx-mg2 ram:mgx-amg1 \
		ram:mgx-amg2 as makefile
	@delete ram:mgx-mg1 ram:mgx-mg2 ram:mgx-amg1 ram:mgx-amg2

# file dependencies will be appended after this line by "make depend"
