# -*- makefile -*-
# 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
COMMENT5 = comment5
PERL = perl
GROFF = nroff -man
# GROFF = groff -mandoc

# 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. Good performance.
#PACK = tar
#PACKOPT = cvfhz
#PACKEXT = .tar.gz

# GNU tar together with bzip2. Slow, but excellent compression rates.
PACK = tar
PACKOPT = cvfhj --exclude CVS --exclude .cvsignore --exclude build\*
PACKEXT = .tar.bz2

# 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/clisp.spec $T/configure #$T/HTML-index.html
#SOURCES2 = $T/src/*
# exclude $T/src/g*t = $T/src/gettext
SOURCES2 = $T/src/*[^t] $T/src/[^g]*t $T/src/.??*
# exclude $T/src/gettext/*o/*p = $T/src/gettext/po/tmp
SOURCES3 = $T/src/gettext/*[^o] $T/src/gettext/po/*[^p]
SOURCES4 = $T/ffcall $T/sigsegv $T/libiconv $T/utils
SOURCES5 = $T/unix $T/os2 $T/cygwin32 $T/win32gcc $T/win32msvc $T/win32bc $T/amiga $T/acorn $T/nextapp
SOURCES6 = $T/modules
SOURCES7 = $T/tests $T/emacs $T/doc $T/Makefile.devel

SOURCES = $(SOURCES1) $(SOURCES2) $(SOURCES3) $(SOURCES4) $(SOURCES5) $(SOURCES6) $(SOURCES7)

DOSDIR = /c:/clisp/src
EMXDIR = /c:/emx
RSXDIR = /c:/rsx
TEMPDIR = /tmp/clispdos


all : makefiles configures potfiles src/FILES src/VERSION utils/comment5.c src/intparam.c src/uninames.c src/asmi386.h src/ari80386.msvc.c src/sp80386.msvc.c ffcall/avcall/avcall.h.msvc ffcall/vacall/config.h.msvc ffcall/vacall/vacall.h.msvc ffcall/trampoline/config.h.msvc ffcall/callback/vacall_r/config.h.msvc ffcall/callback/vacall_r/vacall_r.h.msvc ffcall/callback/trampoline_r/config.h.msvc acorn/pathname.txt htmldoc

ffcall-i386 : ffcall/avcall/avcall-i386-msvc.c ffcall/vacall/vacall-i386-msvc.c ffcall/callback/vacall_r/vacall-i386-msvc.c

htmldoc:
	cd doc && make impnotes.html &&	cp impnotes.html ../src && cd ..;

makefiles : os2/makefile win32gcc/makefile win32msvc/makefile.msvc4 win32msvc/makefile.msvc5 win32bc/makefile acorn/makefile.cc acorn/makefile.gcc

os2/makefile : makemake
	./makemake os2 gcc > os2/makefile

win32gcc/makefile : makemake
	./makemake --with-dir-key win32gcc gcc > win32gcc/makefile

win32msvc/makefile.msvc4 : makemake
	./makemake --with-dir-key --with-dynamic-ffi \
		win32msvc msvc4 > win32msvc/makefile.msvc4

win32msvc/makefile.msvc5 : makemake
	./makemake --with-dir-key --with-export-syscalls --with-dynamic-ffi \
		win32msvc msvc5 > win32msvc/makefile.msvc5

win32bc/makefile : makemake
	./makemake --with-dir-key win32bc bcc32i > win32bc/makefile

acorn/makefile.cc : makemake src/VERSION
	./makemake acorn ansi | $(PERL) acorn/swap-ext.pl > acorn/makefile.cc

acorn/makefile.gcc : makemake src/VERSION
	./makemake acorn gcc | $(PERL) acorn/swap-ext.pl > acorn/makefile.gcc

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


CONFIGURES = src/configure src/gettext/configure modules/wildcard/configure modules/regexp/configure modules/clx/new-clx/configure ffcall/configure ffcall/avcall/configure ffcall/vacall/configure ffcall/trampoline/configure ffcall/callback/configure ffcall/callback/vacall_r/configure ffcall/callback/trampoline_r/configure libiconv/configure sigsegv/configure utils/hln/configure

configures : ffcall/autoconf/aclocal.m4 sigsegv/autoconf/aclocal.m4 $(CONFIGURES) src/gettext/config.h.in

AUTOCONF_FILES = src/autoconf/aclocal.m4 src/autoconf/acgeneral.m4 src/autoconf/acspecific.m4

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

src/gettext/configure : src/gettext/configure.in src/gettext/aclocal.m4 src/gettext/autoconf/acgeneral.m4 src/gettext/autoconf/acspecific.m4
	cd src/gettext ; $(MAKE) -f Makefile.devel configure

src/gettext/config.h.in : src/gettext/configure.in src/gettext/aclocal.m4 src/gettext/autoconf/acgeneral.m4 src/gettext/autoconf/acspecific.m4 src/gettext/acconfig.h
	cd src/gettext ; $(MAKE) -f Makefile.devel config.h.in

modules/wildcard/configure : modules/wildcard/configure.in $(AUTOCONF_FILES)
	cd modules/wildcard ; ../../src/autoconf/autoconf -m ../../src/autoconf

modules/regexp/configure : modules/regexp/configure.in $(AUTOCONF_FILES)
	cd modules/regexp ; ../../src/autoconf/autoconf -m ../../src/autoconf

modules/clx/new-clx/configure : modules/clx/new-clx/configure.in $(AUTOCONF_FILES)
	cd modules/clx/new-clx ; ../../../src/autoconf/autoconf -m ../../../src/autoconf

ffcall/autoconf/aclocal.m4 : src/autoconf/aclocal.m4
	cd ffcall ; $(MAKE) -f Makefile.devel autoconf/aclocal.m4

ffcall/configure : ffcall/configure.in ffcall/autoconf/aclocal.m4 $(AUTOCONF_FILES)
	cd ffcall ; $(MAKE) -f Makefile.devel configure

ffcall/avcall/configure : ffcall/avcall/configure.in ffcall/autoconf/aclocal.m4 $(AUTOCONF_FILES)
	cd ffcall ; $(MAKE) -f Makefile.devel avcall/configure

ffcall/vacall/configure : ffcall/vacall/configure.in ffcall/autoconf/aclocal.m4 $(AUTOCONF_FILES)
	cd ffcall ; $(MAKE) -f Makefile.devel vacall/configure

ffcall/trampoline/configure : ffcall/trampoline/configure.in ffcall/autoconf/aclocal.m4 $(AUTOCONF_FILES)
	cd ffcall ; $(MAKE) -f Makefile.devel trampoline/configure

ffcall/callback/configure : ffcall/callback/configure.in ffcall/autoconf/aclocal.m4 $(AUTOCONF_FILES)
	cd ffcall ; $(MAKE) -f Makefile.devel callback/configure

ffcall/callback/vacall_r/configure : ffcall/callback/vacall_r/configure.in ffcall/autoconf/aclocal.m4 $(AUTOCONF_FILES)
	cd ffcall ; $(MAKE) -f Makefile.devel callback/vacall_r/configure

ffcall/callback/trampoline_r/configure : ffcall/callback/trampoline_r/configure.in ffcall/autoconf/aclocal.m4 $(AUTOCONF_FILES)
	cd ffcall ; $(MAKE) -f Makefile.devel callback/trampoline_r/configure

libiconv/autoconf/aclocal.m4 : src/autoconf/aclocal.m4
	cd libiconv ; $(MAKE) -f Makefile.devel autoconf/aclocal.m4

libiconv/configure : libiconv/configure.in libiconv/autoconf/aclocal.m4 $(AUTOCONF_FILES)
	cd libiconv ; $(MAKE) -f Makefile.devel configure

sigsegv/autoconf/aclocal.m4 : src/autoconf/aclocal.m4
	cd sigsegv ; $(MAKE) -f Makefile.devel autoconf/aclocal.m4

sigsegv/configure : sigsegv/configure.in sigsegv/autoconf/aclocal.m4 $(AUTOCONF_FILES)
	cd sigsegv ; $(MAKE) -f Makefile.devel configure

utils/hln/configure : utils/hln/configure.in $(AUTOCONF_FILES)
	cd utils/hln ; ../../src/autoconf/autoconf -m ../../src/autoconf


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


potfiles :
	cd src/gettext/po ; $(MAKE) -f Makefile.devel


view-man :
	grep -v '^#[ie]' src/_clisp.1 | $(GROFF) -Tascii | less

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


src/FILES : src/FILES.1
	$(GROFF) -Tascii src/FILES.1 > src/FILES

src/VERSION : src/version.h
	fgrep _NUMBER src/version.h | sed 's/^.*_NUMBER "\(.*\)"$$/\1/' > src/VERSION

utils/comment5.c : utils/comment5.d
	cd utils && $(COMMENT5) comment5

src/intparam.c : src/intparam.d
	cd src && $(COMMENT5) intparam

src/uninames.c : utils/unicode/ftp.unicode.org/UnicodeData.txt utils/gen-uninames
	$${CLISP} utils/gen-uninames utils/unicode/ftp.unicode.org/UnicodeData.txt src/uninames.c

src/asmi386.h : src/asmi386.hh
	sed -e 's,//.*$$,,' < src/asmi386.hh > src/asmi386.h

src/ari80386.msvc.c : src/ari80386.d src/asmi386.sh
	src/asmi386.sh -no-C < src/ari80386.d > src/ari80386.msvc.c

src/sp80386.msvc.c : src/sp80386.d src/asmi386.sh
	src/asmi386.sh -no-C < src/sp80386.d > src/sp80386.msvc.c

ffcall/avcall/avcall.h.msvc : ffcall/avcall/avcall.h.in
	cd ffcall ; $(MAKE) -f Makefile.devel avcall/avcall.h.msvc

ffcall/avcall/avcall-i386-msvc.c : ffcall/avcall/avcall-i386.S ffcall/avcall/asmi386.sh
	cd ffcall ; $(MAKE) -f Makefile.devel avcall/avcall-i386-msvc.c

ffcall/vacall/config.h.msvc : ffcall/vacall/config.h.in
	cd ffcall ; $(MAKE) -f Makefile.devel vacall/config.h.msvc

ffcall/vacall/vacall.h.msvc : ffcall/vacall/vacall.h.in
	cd ffcall ; $(MAKE) -f Makefile.devel vacall/vacall.h.msvc

ffcall/vacall/vacall-i386-msvc.c : ffcall/vacall/vacall-i386.S ffcall/vacall/asmi386.sh
	cd ffcall ; $(MAKE) -f Makefile.devel vacall/vacall-i386-msvc.c

ffcall/trampoline/config.h.msvc : ffcall/trampoline/config.h.in
	cd ffcall ; $(MAKE) -f Makefile.devel trampoline/config.h.msvc

ffcall/callback/vacall_r/config.h.msvc : ffcall/callback/vacall_r/config.h.in
	cd ffcall ; $(MAKE) -f Makefile.devel callback/vacall_r/config.h.msvc

ffcall/callback/vacall_r/vacall_r.h.msvc : ffcall/callback/vacall_r/vacall_r.h.in
	cd ffcall ; $(MAKE) -f Makefile.devel callback/vacall_r/vacall_r.h.msvc

ffcall/callback/vacall_r/vacall-i386-msvc.c : ffcall/callback/vacall_r/vacall-i386.S ffcall/callback/vacall_r/asmi386.sh
	cd ffcall ; $(MAKE) -f Makefile.devel callback/vacall_r/vacall-i386-msvc.c

ffcall/callback/trampoline_r/config.h.msvc : ffcall/callback/trampoline_r/config.h.in
	cd ffcall ; $(MAKE) -f Makefile.devel callback/trampoline_r/config.h.msvc

acorn/pathname.txt : src/pathname.d
	cat src/pathname.d | sed -e '1,/Burwood/d' | sed -e '/Komponenten/,$$d' | sed -e 's/^# //g' -e 's/^#$$//g' > acorn/pathname.txt


distrib : linux-distrib src-distrib

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

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

src--distrib : force
	ln -s . $(TOPDIR)
	$(PACK) $(PACKOPT) /tmp/clispsrc$(PACKEXT) $(SOURCES)
	rm -f $(TOPDIR)
# No need for this. François Pinard doesn't like CLISP's submissions any more.
# Doesn't matter; the KDE project's translations work independently too.
#	cd src/gettext/po && $(PACK) $(PACKOPT) /tmp/$(TOPDIR)-potfiles$(PACKEXT) *.po*

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

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

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)/lispinit.mem $(TEMPDIR)
	cp -p $(DOSDIR)/*.lisp $(TEMPDIR)
#	cp -p $(DOSDIR)/*.fas $(TEMPDIR)
	mkdir $(TEMPDIR)/locale
	for lang in en de fr es; do mkdir $(TEMPDIR)/locale/$$lang; mkdir $(TEMPDIR)/locale/$$lang/LC_MESSAGES; cp -p $(DOSDIR)/locale/$$lang/LC_MESSAGES/clisp.mo $(TEMPDIR)/locale/$$lang/LC_MESSAGES/clisp.mo; done
	cp -p $(DOSDIR)/README $(DOSDIR)/README.de $(DOSDIR)/README.en $(DOSDIR)/README.es $(DOSDIR)/clisp.1 $(DOSDIR)/clisp.html $(DOSDIR)/impnotes.html $(DOSDIR)/clisp.gif $(DOSDIR)/clreadline.3 $(DOSDIR)/clreadline.html $(TEMPDIR)
	from-ibmpc $(TEMPDIR)/clisp.1 os2/clisp.1
	from-ibmpc $(TEMPDIR)/clisp.html os2/clisp.html
	from-ibmpc $(TEMPDIR)/impnotes.html os2/impnotes.html
	from-ibmpc $(TEMPDIR)/clreadline.3 os2/clreadline.3
	from-ibmpc $(TEMPDIR)/clreadline.html os2/clreadline.html
	cd os2 ; $(GROFF) -Tascii clisp.1 > clisp.man
	cd os2 ; $(GROFF) -Tdvi clisp.1 > clisp.dvi
	cd os2 ; $(GROFF) -Tascii clreadline.3 > clreadline.man
	cd os2 ; $(GROFF) -Tdvi 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 CLOS-guide.txt LISP-tutorial.txt editors.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
	cp -p $(EMXDIR)/bin/emx.exe $(TEMPDIR)/emx.exe
	to-ibmpc os2/emx-faq.doc $(TEMPDIR)/emx-faq.doc
	cp -p $(EMXDIR)/doc/emxrt.doc $(TEMPDIR)/emx-user.doc
	cp -p $(EMXDIR)/dll/emx.dll $(TEMPDIR)
	cp -p $(EMXDIR)/dll/emxlibc.dll $(TEMPDIR)
	cp -p $(EMXDIR)/etc/termcap.dat $(TEMPDIR)
	cd $(TEMPDIR) ; $(PACK) $(PACKOPT) /tmp/clisp$(PACKEXT) *
	rm -rf $(TEMPDIR)

force :
