# This is the developer's makefile, not the user's makefile.
# Don't use it unless you know exactly what you do!


# Some important programs:
SHELL = /bin/sh
MAKE = make


# Choose one of the packers:

# Standard Unix packer. Compress afterwards.
#PACK = tar
#PACKOPT = -cvf
#PACKEXT = .tar

# GNU tar together with compress.
#PACK = tar
#PACKOPT = cvfhz
#PACKEXT = .tar.Z

# GNU tar together with GNU gzip. Excellent performance.
PACK = tar
PACKOPT = cvfhz
PACKEXT = .tar.z

# Popular Amiga packer. Good performance.
#PACK = lha
#PACKOPT = a
#PACKEXT = .lzh

# Popular DOS packer.
#PACK = zip
#PACKOPT = -r
#PACKEXT = .zip

# Popular Atari packer.
#PACK = zoo
#PACKOPT = -add
#PACKEXT = .zoo

# The distribution's top directory is called TOPDIR here.
# Use clisp-YYYY-MM-DD where DD.MM.YYYY is the date.
TOPDIR = clisp
T = $(TOPDIR)

SOURCES1 = $T/ANNOUNCE $T/COPYRIGHT $T/GNU-GPL $T/INSTALL $T/SUMMARY $T/configure
# exclude $T/src/l*0?d = $T/src/lisparit0.d
#SOURCES2 = $T/src/*[^d] $T/src/*[^0]?d $T/src/[^l]*0?d
# exclude $T/src/l*0?d $T/src/*ne $T/src/*w?n $T/src/*s = $T/src/lisparit0.d $T/src/readline $T/src/newreadline $T/src/stdwin $T/src/queens
SOURCES2 = $T/src/*[^dens] $T/src/*[^0]?d $T/src/[^l]*0?d $T/src/*[^n]e $T/src/*[^w]?n
SOURCES3 = $T/utils $T/unix $T/dos $T/dosdjgpp $T/doswatcom $T/windows $T/windowswatcom $T/os2 $T/amiga $T/atari $T/acorn
SOURCES4 = $T/tests $T/doc/*.txt $T/makefile.developer

SOURCES = $(SOURCES1) $(SOURCES2) $(SOURCES3) $(SOURCES4)

DOSDIR = /c:/clisp/src
TEMPDIR = /tmp/clispdos


all : makefiles oldconfigures configures src/FILES src/version.h src/winabout.c src/wincopyr.c

makefiles : dos/makefile dosdjgpp/makefile doswatcom/makefile windows/makefile windowswatcom/makefile os2/makefile atari/makefile.cross acorn/makefile.cc acorn/makefile.gcc src/readline/Makefile.dos src/readline/Makefile.go32 src/newreadline/Makefile.dos src/newreadline/Makefile.go32

dos/makefile : makemake
	makemake dos gcc > dos/makefile.tmp
	utils/move-if-change dos/makefile.tmp dos/makefile

dosdjgpp/makefile : makemake
	makemake dosdjgpp gcc > dosdjgpp/makefile.tmp
	utils/move-if-change dosdjgpp/makefile.tmp dosdjgpp/makefile

doswatcom/makefile : makemake
	makemake doswatcom wcl386 > doswatcom/makefile.tmp
	utils/move-if-change doswatcom/makefile.tmp doswatcom/makefile

windows/makefile : makemake
	makemake windows gcc > windows/makefile.tmp
	utils/move-if-change windows/makefile.tmp windows/makefile

windowswatcom/makefile : makemake
	makemake windowswatcom wcl386 > windowswatcom/makefile.tmp
	utils/move-if-change windowswatcom/makefile.tmp windowswatcom/makefile

os2/makefile : makemake
	makemake os2 gcc > os2/makefile.tmp
	utils/move-if-change os2/makefile.tmp os2/makefile

atari/makefile.cross : makemake src/VERSION
	makemake cross atari gcc > atari/makefile.tmp
	utils/move-if-change atari/makefile.tmp atari/makefile.cross

acorn/makefile.cc : makemake src/VERSION
	makemake acorn ansi > acorn/makefile.tmp
	utils/move-if-change acorn/makefile.tmp acorn/makefile.cc

acorn/makefile.gcc : makemake src/VERSION
	makemake acorn gcc > acorn/makefile.tmp
	utils/move-if-change acorn/makefile.tmp acorn/makefile.gcc

makemake : src/makemake.in
	(echo "#!/bin/sh" ; cat src/makemake.in) > makemake
	chmod a+x makemake

src/readline/Makefile.dos : src/readline/Makefile.in
	sed -e 's/@srcdir@/./' -e 's/@CC@/gcc/' -e 's/@ALLOCA@//' -e 's/@RANLIB@/ar s/' -e 's/@LIBS@//' -e 's/^RM =.*$$/RM = del/' -e 's/^CP =.*$$/CP = copy/' -e 's/config.h//' -e 's/\(^	.*\)\$$(OBJECTS)/\1@objects/' < src/readline/Makefile.in > src/readline/Makefile.dos

src/readline/Makefile.go32 : src/readline/Makefile.in
	sed -e 's/@srcdir@/./' -e 's/@CC@/gcc/' -e 's/@ALLOCA@//' -e 's/@RANLIB@/ranlib/' -e 's/@LIBS@//' -e 's/^RM =.*$$/RM = del/' -e 's/^CP =.*$$/CP = copy/' -e 's/config.h//' -e 's/\(^	.*\)\$$(OBJECTS)/\1@objects/' < src/readline/Makefile.in > src/readline/Makefile.go32

src/newreadline/Makefile.dos : src/newreadline/Makefile.in
	sed -e 's/@srcdir@/./' -e 's/@CC@/gcc/' -e 's/@CFLAGS@/-g -O/' -e 's/@LDFLAGS@//' -e 's/@DEFS@/-DHAVE_CONFIG_H/' -e 's/@ALLOCA@//' -e 's/@RANLIB@/ar s/' -e 's/@LIBS@//' -e 's/^RM =.*$$/RM = del/' -e 's/^CP =.*$$/CP = copy/' -e 's/^MV =.*$$/MV = ren/' -e 's/ config.h//' -e 's/\(^	.*\)\$$(OBJECTS)/\1@objects/' < src/newreadline/Makefile.in > src/newreadline/Makefile.dos

src/newreadline/Makefile.go32 : src/newreadline/Makefile.in
	sed -e 's/@srcdir@/./' -e 's/@CC@/gcc/' -e 's/@CFLAGS@/-g -O/' -e 's/@LDFLAGS@//' -e 's/@DEFS@/-DHAVE_CONFIG_H/' -e 's/@ALLOCA@//' -e 's/@RANLIB@/ranlib/' -e 's/@LIBS@//' -e 's/^RM =.*$$/RM = del/' -e 's/^CP =.*$$/CP = copy/' -e 's/^MV =.*$$/MV = ren/' -e 's/ config.h//' -e 's/\(^	.*\)\$$(OBJECTS)/\1@objects/' < src/newreadline/Makefile.in > src/newreadline/Makefile.go32


OLDCONFIGURES = src/configure.old src/readline/configure.old src/newreadline/configure.old src/stdwin/configure.old

oldconfigures : $(OLDCONFIGURES)

AUTOCONF1_FILES = src/autoconf-1.7/aclocal.m4 src/autoconf-1.7/acgeneral.m4 src/autoconf-1.7/acspecific.m4

src/configure.old : src/configure.old.in $(AUTOCONF1_FILES)
	cd src ; autoconf-1.7/autoconf -m autoconf-1.7 configure.old.in > configure.old ; chmod a+x configure.old

src/readline/configure.old : src/readline/configure.old.in $(AUTOCONF1_FILES)
	cd src/readline ; ../autoconf-1.7/autoconf -m ../autoconf-1.7 configure.old.in > configure.old ; chmod a+x configure.old

src/newreadline/configure.old : src/newreadline/configure.old.in $(AUTOCONF1_FILES)
	cd src/newreadline ; ../autoconf-1.7/autoconf -m ../autoconf-1.7 configure.old.in > configure.old ; chmod a+x configure.old

src/stdwin/configure.old : src/stdwin/configure.old.in $(AUTOCONF1_FILES)
	cd src/stdwin ; ../autoconf-1.7/autoconf -m ../autoconf-1.7 configure.old.in > configure.old ; chmod a+x configure.old


CONFIGURES = src/configure src/readline/configure src/newreadline/configure src/stdwin/configure

configures : $(CONFIGURES)

AUTOCONF2_FILES = src/autoconf-2.1/aclocal.m4 src/autoconf-2.1/acgeneral.m4 src/autoconf-2.1/acspecific.m4

src/configure : src/configure.in $(AUTOCONF2_FILES)
	cd src ; autoconf-2.1/autoconf -m autoconf-2.1

src/readline/configure : src/readline/configure.in $(AUTOCONF2_FILES)
	cd src/readline ; ../autoconf-2.1/autoconf -m ../autoconf-2.1

src/newreadline/configure : src/newreadline/configure.in $(AUTOCONF2_FILES)
	cd src/newreadline ; ../autoconf-2.1/autoconf -m ../autoconf-2.1

src/stdwin/configure : src/stdwin/configure.in $(AUTOCONF2_FILES)
	cd src/stdwin ; ../autoconf-2.1/autoconf -m ../autoconf-2.1


# Syntaxcheck
check-configures : $(OLDCONFIGURES) $(CONFIGURES)
	set -e; for f in $(OLDCONFIGURES) $(CONFIGURES); do bash -x -n $$f; done


view-man :
	grep -v '^#[ie]' src/_clisp.1 | groff -Tascii -mandoc | less

view-html :
	grep -v '^#[ie]' src/_clisp.html > /tmp/clisp.html
	Mosaic /tmp/clisp.html &


src/FILES : src/FILES.1
	groff -Tascii -mandoc src/FILES.1 > src/FILES

src/version.h : src/VERSION
	(echo '/* Generated automatically from src/VERSION. */' ; sed -e 's/^/#define VERSION "/' -e 's/$$/"/' src/VERSION ) > src/version.h

src/winabout.c : src/winabout.txt
	sed -e 's/"/\\"/g' -e 's/^/"/' -e 's/$$/" CRLFstring/' < src/winabout.txt > src/winabout.c

src/wincopyr.c : COPYRIGHT
	sed -e 's/"/\\"/g' -e 's/^/"/' -e 's/$$/" CRLFstring/' < COPYRIGHT > src/wincopyr.c


check-old : force
	src/autoconf-1.7/autoheadercheck src/configure.old src/unixconf.h.in
	src/autoconf-1.7/autoheadercheck src/readline/configure.old src/readline/config.h.in
	src/autoconf-1.7/autoheadercheck src/newreadline/configure.old src/newreadline/config.h.in
	src/autoconf-1.7/autoheadercheck src/stdwin/configure.old src/stdwin/H/config.h.in


distrib : linux-distrib dos-distrib src-distrib

# Before doing a "make src-distrib", don't forget
# * update src/NEWS and src/VERSION,
# * "make",
# * "make check-old",
# * "make check-configures",
# * check that src/genclisph.d is up to date.

src-distrib : src/FILES force
	$(MAKE) src--distrib TOPDIR=clisp-`cat src/VERSION`

src--distrib : force
	ln -s . $(TOPDIR)
	$(PACK) $(PACKOPT) /tmp/clispsrc$(PACKEXT) $(SOURCES)
	$(PACK) $(PACKOPT) /tmp/clispsrc-readline$(PACKEXT) $T/src/readline
	$(PACK) $(PACKOPT) /tmp/clispsrc-newreadline$(PACKEXT) $T/src/newreadline
	$(PACK) $(PACKOPT) /tmp/clispsrc-stdwin$(PACKEXT) $T/src/stdwin
	$(PACK) $(PACKOPT) /tmp/clispsrc-queens$(PACKEXT) $T/src/queens
	rm -f $(TOPDIR)

linux-distrib : force
	$(MAKE) linux--distrib

linux--distrib : force
	cd make.gcc && $(MAKE) PACK="$(PACK)" PACKOPT="$(PACKOPT)" PACKEXT="$(PACKEXT)" distrib

dos-distrib : force
	$(MAKE) dos--distrib PACK="zip" PACKOPT="-r" PACKEXT=".zip"

dos--distrib : force
	mkdir $(TEMPDIR)
	cp -p $(DOSDIR)/ANNOUNCE $(DOSDIR)/COPYRIGHT $(DOSDIR)/GNU-GPL $(DOSDIR)/SUMMARY $(DOSDIR)/NEWS $(TEMPDIR)
	cp -p $(DOSDIR)/lisp.exe $(TEMPDIR)
	cp -p $(DOSDIR)/lisp_1mb.exe $(TEMPDIR)
	cp -p $(DOSDIR)/compiled.mem $(TEMPDIR)/lispinit.mem
	cp -p $(DOSDIR)/*.lsp $(TEMPDIR)
	# cp -p $(DOSDIR)/*.fas $(TEMPDIR)
	cp -p $(DOSDIR)/README $(DOSDIR)/clisp.1 $(DOSDIR)/clisp.html $(DOSDIR)/impnotes.txt $(DOSDIR)/clreadline.3 $(TEMPDIR)
	from-ibmpc $(TEMPDIR)/clisp.1 dos/clisp.1
	from-ibmpc $(TEMPDIR)/clisp.html dos/clisp.html
	from-ibmpc $(TEMPDIR)/impnotes.txt dos/impnotes.txt
	from-ibmpc $(TEMPDIR)/clreadline.3 dos/clreadline.3
	cd dos ; groff -Tascii -mandoc clisp.1 > clisp.man
	cd dos ; groff -Tdvi -mandoc clisp.1 > clisp.dvi
	cd dos ; groff -Tascii -mandoc clreadline.3 > clreadline.man
	cd dos ; groff -Tdvi -mandoc clreadline.3 > clreadline.dvi
	to-ibmpc dos/clisp.man $(TEMPDIR)/clisp.man
	cp -p dos/clisp.dvi $(TEMPDIR)/clisp.dvi
	to-ibmpc dos/clreadline.man $(TEMPDIR)/clreadline.man
	cp -p dos/clreadline.dvi $(TEMPDIR)/clreadline.dvi
	cd doc ; for f in *.txt; do to-ibmpc $$f $(TEMPDIR)/$$f; done
	cd src/readline/doc ; $(MAKE) rluserman.dvi
	cp -p src/readline/doc/rluserman.dvi $(TEMPDIR)/readline.dvi
	to-ibmpc dos/emx-faq.doc $(TEMPDIR)/emx-faq.doc
	cp -p /c:/emx/doc/user.doc $(TEMPDIR)/emx-user.doc || cp -p /c:/emx/doc/emxrt.doc $(TEMPDIR)/emx-user.doc
	cp -p dos/delay.exe $(TEMPDIR)/delay.exe
	cd $(TEMPDIR) ; $(PACK) $(PACKOPT) /tmp/clisp$(PACKEXT) *
	rm -rf $(TEMPDIR)

os2-distrib : force
	$(MAKE) os2--distrib PACK="zip" PACKOPT="-r" PACKEXT=".zip"

os2--distrib : force
	mkdir $(TEMPDIR)
	cp -p $(DOSDIR)/ANNOUNCE $(DOSDIR)/COPYRIGHT $(DOSDIR)/GNU-GPL $(DOSDIR)/SUMMARY $(DOSDIR)/NEWS $(TEMPDIR)
	cp -p $(DOSDIR)/lisp.exe $(TEMPDIR)
	cp -p $(DOSDIR)/compiled.mem $(TEMPDIR)/lispinit.mem
	cp -p $(DOSDIR)/*.lsp $(TEMPDIR)
	# cp -p $(DOSDIR)/*.fas $(TEMPDIR)
	cp -p $(DOSDIR)/README $(DOSDIR)/clisp.1 $(DOSDIR)/html $(DOSDIR)/impnotes.txt $(DOSDIR)/clreadline.3 $(TEMPDIR)
	from-ibmpc $(TEMPDIR)/clisp.1 os2/clisp.1
	from-ibmpc $(TEMPDIR)/clisp.html os2/clisp.html
	from-ibmpc $(TEMPDIR)/impnotes.txt os2/impnotes.txt
	from-ibmpc $(TEMPDIR)/clreadline.3 os2/clreadline.3
	cd os2 ; groff -Tascii -mandoc clisp.1 > clisp.man
	cd os2 ; groff -Tdvi -mandoc clisp.1 > clisp.dvi
	cd os2 ; groff -Tascii -mandoc clreadline.3 > clreadline.man
	cd os2 ; groff -Tdvi -mandoc clreadline.3 > clreadline.dvi
	to-ibmpc os2/clisp.man $(TEMPDIR)/clisp.man
	cp -p os2/clisp.dvi $(TEMPDIR)/clisp.dvi
	to-ibmpc os2/clreadline.man $(TEMPDIR)/clreadline.man
	cp -p os2/clreadline.dvi $(TEMPDIR)/clreadline.dvi
	cd doc ; for f in *.txt; do to-ibmpc $$f $(TEMPDIR)/$$f; done
	cd src/readline/doc ; $(MAKE) rluserman.dvi
	cp -p src/readline/doc/rluserman.dvi $(TEMPDIR)/readline.dvi
	to-ibmpc dos/emx-faq.doc $(TEMPDIR)/emx-faq.doc
	cp -p /c:/emx/doc/user.doc $(TEMPDIR)/emx-user.doc || cp -p /c:/emx/doc/emxrt.doc $(TEMPDIR)/emx-user.doc
	cp -p /c:/emx/dll/emx.dll $(TEMPDIR)
	cp -p /c:/emx/dll/emxlibc.dll $(TEMPDIR)
	# cp -p /c:/emx/etc/termcap.dat $(TEMPDIR)
	cd $(TEMPDIR) ; $(PACK) $(PACKOPT) /tmp/clisp$(PACKEXT) *
	rm -rf $(TEMPDIR)

force :

