CC = gcc

OFLAGS = -m486 -O3 -malign-loops=2 -malign-jumps=2 -malign-functions=2 
LDFLAGS = $(OFLAGS) -L.
CFLAGS = $(OFLAGS) -mprobe -DEMX -include config.emx -I.
ZFLAGS = -Zomf -Zcrtdll
EFLAGS = $(OFLAGS) -DEMX -include config.emx -I.

%.obj : %.c ; $(CC) $(CFLAGS) -c $< -o $@ -Zomf
%.o : %.c ; $(CC) $(CFLAGS) -c $< -o $@

%.res : %.rc
	rc -r $<

SOURCES = dir.c display.c echo_area.c filesys.c info-utils.c info.c \
	infodoc.c infomap.c m-x.c nodes.c search.c session.c \
	signals.c terminal.c tilde.c window.c indices.c \
	index-search.c makedoc.c nodemenu.c footnotes.c dribble.c variables.c \
        gc.c pc.c error.obj man.c clib.c xmalloc.c

INCL = display.h doc.h echo_area.h filesys.h general.h getopt.h \
	info-utils.h info.h infomap.h nodes.h search.h session.h \
	signals.h termdep.h terminal.h tilde.h indices.h window.h \
	footnotes.h dribble.h variables.h gc.h pc.h clib.h

OBJECTS = dir.obj display.obj doc.obj echo_area.obj filesys.obj \
	info-utils.obj infodoc.obj infomap.obj m-x.obj nodes.obj search.obj \
	session.obj signals.obj terminal.obj tilde.obj window.obj indices.obj \
	index-search.obj nodemenu.obj footnotes.obj dribble.obj variables.obj \
        gc.obj pc.obj error.obj man.obj clib.obj xmalloc.obj

OBJS = info.obj getopt.obj getopt1.obj xmalloc.obj

# The names of files which declare info commands.
CMDFILES = session.c echo_area.c infodoc.c m-x.c indices.c nodemenu.c \
	   footnotes.c variables.c

# The name of the program which builds documentation structure from CMDFILES.
MAKEDOC_OBJECTS = makedoc.obj clib.obj xmalloc.obj
MAKEDOC_SOURCE = makedoc.c clib.c xmalloc.c

all: info.exe gnuview.exe gnuinfo.dll gnuinfo.a gnuinfo.lib

install: all
	cp info.exe gnuview.exe h:/bin
	cp gnuinfo.dll h:/bin/dll
	cp gnuinfo.a gnuinfo.lib ../lib

clean:
	rm -f *.o *.obj *.a *.lib *.dll *.exe

gnuinfo.imp: gnuinfo.def
	emximp -o gnuinfo.imp gnuinfo.def

gnuinfo.a: gnuinfo.imp
	emximp -o gnuinfo.a gnuinfo.imp

gnuinfo.lib: gnuinfo.imp
	emximp -o gnuinfo.lib gnuinfo.imp

info.exe: gnuinfo.lib gnuinfo.dll $(OBJS) info.res
	$(CC) $(LDFLAGS) -o info.exe $(OBJS) info.res gnuinfo.lib $(ZFLAGS)

gnuview.exe: gnuview.obj getopt.obj getopt1.obj xmalloc.obj
	$(CC) $(LDFLAGS) -o gnuview.exe $^ $(ZFLAGS)

gnuinfo.dll: $(OBJECTS) gnuinfo.def
	gcc -o gnuinfo.dll gnuinfo.def $(OBJECTS) -ltermcap -Zdll $(ZFLAGS)

makedoc.exe: $(MAKEDOC_OBJECTS)
	$(CC) $(LDFLAGS) -o makedoc.exe $(MAKEDOC_OBJECTS) $(ZFLAGS)

# The files `doc.c' and `funs.h' are created by ./makedoc run over the source
# files which contain DECLARE_INFO_COMMAND.  `funs.h' is a header file
# listing the functions found.  `doc.c' is a structure containing pointers
# to those functions along with completable names and documentation strings.
funs.h: makedoc.exe $(CMDFILES)
	makedoc $(CMDFILES)

doc.obj:	doc.c
doc.c: 		funs.h
dribble.obj:	dribble.c dribble.h
display.obj:	display.c
echo_area.obj:	echo_area.c
filesys.obj:	filesys.c
info-utils.obj:	info-utils.c filesys.h
info.obj: 	info.h filesys.h getopt.h
gnuview.obj:	gnuview.c getopt.h
infodoc.obj:	infodoc.c
infomap.obj:	infomap.c
m-x.obj:	m-x.c
nodes.obj:	nodes.c
search.obj:	search.c
session.obj:	session.c
signals.obj:	signals.c
terminal.obj:	terminal.c
tilde.obj:	tilde.c
window.obj:	window.c
xmalloc.o:	xmalloc.c
indices.obj:	indices.c
index-search.obj:	index-search.c
makedoc.o:	makedoc.c

dir.obj: 	dir.c
display.obj: 	nodes.h info-utils.h search.h
display.obj: 	terminal.h window.h display.h
echo_area.obj: 	info.h
filesys.obj: 	general.h tilde.h filesys.h
footnotes.obj: 	footnotes.h
info-utils.obj: info-utils.h nodes.h search.h
info.obj: 	info.h getopt.h
infodoc.obj: 	info.h doc.h
infomap.obj: 	infomap.h funs.h
gc.obj:		info.h
m-x.obj: 	info.h
nodes.obj: 	search.h filesys.h
nodes.obj: 	nodes.h info-utils.h
search.obj: 	general.h search.h nodes.h
session.obj: 	info.h pc.h
signals.obj: 	info.h signals.h
terminal.obj: 	terminal.h termdep.h
tilde.obj: 	tilde.h
variables.obj: 	variables.c variables.h
window.obj: 	nodes.h window.h display.h
window.obj: 	info-utils.h search.h infomap.h
clib.obj:       clib.c clib.h general.h
error.obj:	error.c
pc.obj: 	pc.c pc.h
nodemenu.obj:	nodemenu.c

makedoc.obj:	makedoc.c;		$(CC) $(EFLAGS) -c $< -o $@ -Zomf
info.obj:	info.c;			$(CC) $(EFLAGS) -c $< -o $@ -Zomf
getopt.obj:	getopt.c getopt.h;	$(CC) $(EFLAGS) -c $< -o $@ -Zomf
getopt1.obj:	getopt1.c getopt.h;	$(CC) $(EFLAGS) -c $< -o $@ -Zomf

info.res:	info.rc
