# bigforth makefile

DATE= $$(LC_ALL=C date '+%d%b%Y' | tr '[A-Z]' '[a-z]')
SRCREV=2.5.0
MINOSREV=1.5.0
BINREV=$(SRCREV)
PATREV=1.0.1
EWOODREV=1.0.2
ESHMREV=1.0.2
DOCREV=obsolete

package =
prefix = $(package)/usr/local
exec_prefix = /usr/local
libdir = $(package)${exec_prefix}/lib/bigforth
srcdir = $(package)$(libdir)/src
bindir = $(package)${exec_prefix}/bin

TEXI2DVI = texi2dvi
DVI2PS	= dvips -Z
TEXI2HTML = texi2html
MAKEINFO = makeinfo

INI = .bigforthrc
XINI = .xbigforthrc
INSTDIR = $(libdir)
BININSTDIR = $(bindir)
CC = gcc -m32 -m32
CP = cp
MV = mv
EXE = 
CFLAGS = -g -O2 -fno-omit-frame-pointer -Wall -DVERSION_DATE='"'"$(DATE)"'"' -DINSTDIR='"'"$(INSTDIR)"'"' -fno-strict-aliasing 
LDLIBS = -ldl 
ARCH = linux
SHELL = /bin/sh

WARNING	= 
#WARNING = warning on

BYE	= cr bye
SAVE	= ' .blk is .status warning on savesystem
XSAVE	= warning on savesystem

OBJS	= bigforth.o xbigforth.o linker.o
SOURCE	= bigforth.c linker.S
KERNSRC	= forth.fb target.fb
SYSSRC	= assem486.fb stream.fb errore.fs hash.fs fileint.fb output.fb \
	  strings.fs savemod.fb tasker.fb vt100key.fs disass.fb \
	  tools.fb except.fs sedit.fb struct.fs lambda.fs idle.fs callback.fs \
	  startup.fb ftast.fb environ.fs random.fs version.h minos-version.h \
	  forth200x.fs
XCSRC	= x.fs glconst.fs
XSRC	= startx.fs minos.fs oof.fb x11.fs xpm.fs locals.fs editor.fs \
	  ediwind.fs edit.fs opengl.fs xstyle.fs status.fb splines.fb \
	  pipes.fb ptty.fs login.fs pixmap.fs png.fs browser.fs \
	  points.fs qsort.fs string.fs sincos.fs utf-8.fs xrender.fs \
	  $(XINI) xft-font.fs imlib.fs Estyle.fs substitute.fs i18n.fs i18n-months.fs \
	  minos-base.fs displays.fs minos-fonts.fs vdisplays.fs \
	  actors.fs widgets.fs minos-boxes.fs minos-buttons.fs \
	  minos-viewport.fs minos-windows.fs minos-complex.fs \
	  resources.fs minos-float.fs convert-m.sh float.fb theseus*.fs \
	  win32.fs win32ex.fs w95style.fs
BUILDSRC	= configure.ac config.sub config.guess Makefile.in install-sh
EXTRAS = gpl-about.m menu.fs adjust.m adjust-path.fs fft.fb complex.fb fileop.fb
SRC	= $(SOURCE) $(KERNSRC) $(SYSSRC) $(XCSRC) $(XSRC) $(BUILDSRC) $(XINI) $(XINI:%=%.in) $(INI) $(INI:%=%.in) $(EXTRAS)
MINIICONS = bigforth/icons/{dot-dir,dotdot-dir,script,dir,diropen,file,sym,INFO,WARNING,FATAL,QUESTION,ERROR,NONE}.png

all:	build ok

build:	bigforth$(EXE) forthker-$(ARCH)$(EXE) xbigforth$(EXE) xbigforth.fi theseus

ok:	xbigforth.fi xbigforth$(EXE)
	-@./xbigforth -e '." *** bigFORTH build successful ***" cr bye'

theseus:	theseus.fs
	sed -e "s,^#! xbigforth,#! $(BININSTDIR)/xbigforth$(EXE)," <theseus.fs >theseus

version.h:	Makefile.in
	echo '"'$(SRCREV)'"' >$@

minos-version.h:	Makefile.in
	echo '"'$(MINOSREV)'"' >$@

%.o:	%.c version.h
	$(CC) $(CFLAGS) -c $<

xbigforth.o:	bigforth.c version.h minos-version.h
	$(CC) $(CFLAGS) -DMINOS -c $< -o $@

%.o:	%.S
	$(CC) -c $<

bigforth$(EXE): bigforth.o linker.o
	$(CC) $(CFLAGS) bigforth.o linker.o $(LDLIBS) -o bigforth
	strip bigforth$(EXE)

forthker-$(ARCH)$(EXE): bigforth$(EXE)
	$(CP) $< $@

xbigforth$(EXE): xbigforth.o linker.o
	$(CC) $(CFLAGS)  xbigforth.o linker.o $(LDLIBS) -o $@
	strip $@

scr2str$(EXE) str2scr$(EXE):	scr2str.c
	$(CC) $(CFLAGS) $< -o scr2str$(EXE)
	ln -s scr2str$(EXE) str2scr$(EXE)

forthker-%.fi: $(KERNSRC)
	-@$(CP) $@ $@~
	./bigforth -e ": :$* ; include forth.fb save-target forthker-$* $(BYE)"

bigforth.fi: forthker-$(ARCH).fi $(SYSSRC) Makefile
	-@$(MV) $@ $@~
	env LIBDIR=$(libdir) SRC=$(srcdir) ./forthker-$(ARCH) -e "$(WARNING) include startup.fb $(SAVE) bigforth $(BYE)"

xbigforth.fi: bigforth.fi xconst.fm glconst.fm $(XSRC) $(INI)
	-@$(MV) $@ $@~
	./bigforth -e "$(WARNING) use x.fs use glconst.fs use float.fb include startx.fs $(XSAVE) xbigforth $(BYE)"

xconst.fm: $(XCSRC) forthker-$(ARCH).fi $(SYSSRC)
	-@$(MV) $@ $@~
	./bigforth -e "$(WARNING) include x.fs m' xconst savemod xconst $(BYE)"

glconst.fm: $(XCSRC) forthker-$(ARCH).fi $(SYSSRC)
	-@$(MV) $@ $@~
	./bigforth -e "$(WARNING) use x.fs include glconst.fs m' glconst savemod glconst $(BYE)"

float.fm: float.fb forthker-$(ARCH).fi $(SYSSRC)
	-@$(MV) $@ $@~
	./bigforth -e "$(WARNING) use x.fs use glconst.fs include float.fb m' float savemod float $(BYE)"

CPYDIST = bigforth/{README,COPYING,CREDITS,LGPLv3}

DOSDIST = bigforth/{forthker-*,bigforth,xbigforth}$(EXE) bigforth/forthker-*.fi bigforth/{version.h,minos-version.h}

DOCDIST = bigforth/help/{*.html,[a-z]*.gif,*.jpg,*.sh} bigforth/doc/bigforth.texi

EXAMPLEDIST = bigforth/3dskull/{*.fs,*.m,*.dat} $(DRAGONDIST)

ICONDIST = bigforth/icons/*.png bigforth/icons/minos1+.icn

SRCDIST = bigforth/{BUGS,ToDo,config.guess,config.sub,install-sh,configure{,.ac},{Makefile,$(INI),$(XINI)}{,.in},[^E]*.f[sb],Estyle.fs,*.m,bigforth.c,scr2str.c,*.S,iss.sh,tips.txt,forthker-*.fi,xpmtoicn,convert-m.sh} $(ICONDIST)

MINISRCDIST = $(SRC:%=bigforth/%)

DRAGONDIST = bigforth/pattern/dragon{,-back,-head,-wing,-claw}.png \
	bigforth/pattern/{bark,normal-w1,back,focus}.png

PATDIST = bigforth/pattern/{back,backtext,dark,focus,light,normal}{-c,-h,-p,-w,-w1,-m,-d,}.ppm \

EDIST1 =	bigforth/Estyle/wood/{Makefile,*.inc} \
	bigforth/Estyle/wood/{button,arrow,[hv]slider,[rt]button}-[dfps][blmrt]*.{pov,png} bigforth/Estyle-wood.fs

EDIST2 =	bigforth/Estyle/ShinyMetal/* bigforth/Estyle-ShinyMetal.fs

COMPRESS = J
TAR = tar -$(COMPRESS)chf
COMPSUB = .xz

docdist:	all
	cd ..; $(TAR) bigforth/bigforth-doc-"$(DOCREV)".tar$(COMPSUB) $(DOCDIST)

srcdist:
	cd ..; $(TAR) bigforth/bigforth-"$(SRCREV)".tar$(COMPSUB) $(SRCDIST) $(CPYDIST) $(EXAMPLEDIST)

minidist:
	cd ..; $(TAR) bigforth/bigforth-mini-"$(SRCREV)".tar$(COMPSUB) $(MINISRCDIST) $(CPYDIST) $(DOSDIST) $(MINIICONS)

patdist:	all
	cd ..; $(TAR) bigforth/bigforth-pattern-"$(PATREV)".tar$(COMPSUB) $(PATDIST)

edist1:		all
	cd ..; $(TAR) bigforth/bigforth-edata-wood-"$(EWOODREV)".tar$(COMPSUB) $(EDIST1)

edist2:		all
	cd ..; $(TAR) bigforth/bigforth-edata-ShinyMetal-"$(ESHMREV)".tar$(COMPSUB) $(EDIST2)

dist:	all docdist srcdist patdist edist1 edist2

dist-files:
	@echo $(SRCDIST) $(DOCDIST) $(CPYDIST) $(DOSDIST) $(EXAMPLEDIST)

minidist-files:
	@echo $(MINISRCDIST) $(CPYDIST) $(DOSDIST) $(MINIICONS)

INSTDIRS = pattern icons help src Estyle Estyle/wood Estyle/ShinyMetal

install:	build
	@install -d $(DESTDIR)$(BININSTDIR)
	@install -d $(DESTDIR)$(INSTDIR)
	@for i in $(INSTDIRS); do install -d $(DESTDIR)$(INSTDIR)/$$i; done
	@install -m 644 {forthker-$(ARCH),bigforth,xbigforth}.fi {glconst,xconst}.fm $(DESTDIR)$(INSTDIR)
	@install -m 644 $(INI) $(DESTDIR)$(INSTDIR)
	@install -m 644 $(XINI) $(DESTDIR)$(INSTDIR)
	@install -m 755 {forthker-$(ARCH),bigforth,xbigforth}$(EXE) convert-m.sh $(DESTDIR)$(BININSTDIR)
	@install -m 755 theseus $(DESTDIR)$(BININSTDIR)/theseus
	@$(RM) theseus
	@install -m 644 {BUGS,ToDo,README,COPYING,LGPLv3,CREDITS,Makefile,*.f[sb],*.m,*.c,*.S,iss.sh,tips.txt} $(DESTDIR)$(INSTDIR)/src
	@install -m 644 icons/*.png $(DESTDIR)$(INSTDIR)/icons
	@install -m 644 pattern/dragon{,-back,-claw,-head,-wing}.png pattern/bark.png $(DESTDIR)$(INSTDIR)/pattern
	@if [ -d help ]; then install -m 644 help/{*.html,[a-z]*.gif,*.jpg,*.sh} $(DESTDIR)$(INSTDIR)/help; fi
	@if [ -f pattern/back-p.ppm ]; then install -m 644 pattern/{back,backtext,dark,focus,light,normal}{-c,-h,-p,-w,-w1,-m,-d,}.ppm $(DESTDIR)$(INSTDIR)/pattern; fi
	@if [ -d Estyle/wood ]; then install -m 644 Estyle/wood/{button,arrow,[hv]slider,[rt]button}-[dfps][blmrt]*.png $(DESTDIR)$(INSTDIR)/Estyle/wood; fi
	@if [ -d Estyle/ShinyMetal ]; then install -m 644 Estyle/ShinyMetal/* $(DESTDIR)$(INSTDIR)/Estyle/ShinyMetal; fi

configure:	configure.ac
		autoconf

config.status:	configure
		if [ -f config.status ]; \
		then ./config.status --recheck; \
		else ./configure; fi

Makefile:	Makefile.in config.status
		CONFIG_FILES="$@" ./config.status

$(XINI):	$(XINI).in config.status
		CONFIG_FILES="$@" ./config.status

$(INI):	$(INI).in config.status
		CONFIG_FILES="$@" ./config.status

# This is the documentation part, and is not ready yet

doc/bigforth.dvi doc/bigforth.fns:	doc/bigforth.texi
		cd doc; $(TEXI2DVI) bigforth.texi

doc/bigforth.ps:	doc/bigforth.dvi
		$(DVI2PS) doc/bigforth.dvi -o $@

doc/bigforth.info doc/bigforth.info-*: doc/bigforth.texi
		-cd doc; $(MAKEINFO) bigforth.texi

doc/bigforth.txt:	doc/bigforth.texi
		-cd doc; $(MAKEINFO) --no-headers --no-split bigforth.texi >bigforth.txt

info:		doc/bigforth.info

ps:		doc/bigforth.ps

html:		doc/bigforth.texi
		-$(RMTREE) html
		-mkdir html
		cd html; $(TEXI2HTML) -menu -split_node ../doc/bigforth.texi

doc:		doc/bigforth.ps html doc/bigforth.txt

# make debian
debian.control:	Makefile
	echo "Source: bigforth" >$@
	echo "Section: programming" >>$@
	echo "Priority: optional" >>$@
	echo "Maintainer: Bernd Paysan <bernd.paysan@gmx.de>" >>$@
	echo "Build-Depends: debhelper (>= 4.1.16), build-essential, gcc" >>$@
	echo "Package: bigforth" >>$@
	echo "Version: $(SRCREV)" >>$@
	echo "Architecture: i386" >>$@
	echo "Description: bigFORTH+MINOS" >>$@
	echo " bigFORTH is a native code Forth. It is available for Linux and" >>$@
	echo " Windows 2000/XP under GPL. The most striking feature is the" >>$@
	echo " graphical user interface MINOS (GUI in Forth) and the form editor" >>$@
	echo " Theseus (Theseus is still beta)." >>$@

bigforth.deb:	all debian.control
	-rm -rf debian
	mkdir debian
	make package=debian install
	(cd debian; find . -name '*' -exec md5sum '{}' ';') >md5sums
	mkdir debian/DEBIAN
	cp debian.control debian/DEBIAN/control
	cp md5sums debian/DEBIAN
	dpkg-deb --build debian
	mv debian.deb bigforth_$(SRCREV)_i386.deb
	rm -rf debian.control md5sums debian

