# ----------------------------------------------------------------------------- #
# Copyright (C) 2001 Berlin h-peter recktenwald <phpr@snafu.de>, QT licensed	#
# Makefile for lib4th - lib4th will NOT assemble with original nasm!		#
# ----------------------------------------------------------------------------- #
# 	compiled "lib4th" does not depend on GNU-copyrighted software		#
# ----------------------------------------------------------------------------- #
.EXPORT_ALL_VARIABLES:	# MConfig lib4th 02, configureable items, for Makefile  #
#
# (assure that LIBDIR -below- is in libraries search path or, in /etc/ld.so.conf)
# compile:
#	make all
#	make 4
#	make test
#	make docs html xref
#	make install
# or:
#	make devel 4
#
# tested w. "root", with a user which is in the sudoers' list and, with a
# non-privileged user w. r/x permissions by group to external utils & dir's.
# the non-"root" user can <make> files and test, but not <make install>.
# ----------------------------------------------------------------------------- #
# may be passed in, by environmental vari:
#	F8DEBUG		enable L4 debugging words/code
#	F8V		set to '@' to supressing 'verbosity'
#	F8D		if non-empty, suppressing "4" getting stripped 
#	NOSTRIP		whether stripping, at all
#	NOSSTRIP	whether stripping the static(ally linked prog/)lib
# NOTE:
#	SSTRIP_PROG	defaults to non-standard ./util/sstrip
# re-define to something more appropriate if useing a binutils version 
# more recent than 2.11.90, the latest ones when applied to an already 
# <sstrip>ped binary instead of rejecting stripped those down to almost
# nothing!
#
# ----------------------------------------------------------------------------- #
# configure:
# ----------------------------------------------------------------------------- #

# for development add working directory of source package to '/etc/ld.so.conf'
# before installing verify that stored library would be in ld.so search path.

# ownership of installed programs if lib4th compiled by "root"-user
USER	= hp
GROUP	= users

# lib4th setup, capabilities
# 	preferred initial variant, <FIG> or <ANS> or none, i.e. { only forth }
# 	if unset, vectored words default to ANS mode
#STD4TH = __FIG
STD4TH = __ANS

# 	permit multiple DOES> in a defining word
MDOES  =
MDOES  = -d__mdoes

# 	set/find w/ or w/o mmx operations, dep'd on actual cpu
MMX    =
MMX    = $(shell ./util/mmxinfo|grep "1">/dev/null&&echo "-d__MMX")

# 	"Rational Numbers" extension,
#	full wordset adds 10K+ to kernel lib, 4K+ if <sstrip>ped.
RANUM  = -d__RATIONAL
#	with floating pt. support, requires RANUM defined
ANSFPS = -d__ANSFLOAT
# 	FLOATING wordsets, aliased rational numbers words, requires ANSFPS df'd
ANSFPA = -d__ANSALIAS
#	additional, single cells' pairs rational number words
#SRANUM = -d__SRANUM
SRANUM =

# 	w/w.o. g.o.t. related 4th words
GOT    =
#	(w/o g.o.t. saves the impressive amount of 2 (t-w-o) bytes...)
#GOT    = -d__startgot_omit


# ----------------------------------------------------------------------------- #
# <strip>ping was somewhat peculiar, mainly due to the signal handlers		#
# which occasionally were rendered non-functional, after minor(!) changes	#
# <sstrip> could also be applied to lib4th, finally, after all linking done.	#
# ----------------------------------------------------------------------------- #
# whether stripping
#	at all
STRIP_ANY = y
#	dyn library, <sstrip> saves about 200K (and some execution/startup time)
STRIP_LIB = y
#	dyn. linked programs, i.e. "f8", "calc4th"
STRIP_PRG = y
#	static programs, i.e. "4", stripped is ca. 300K smaller!
ifdef F8DEBUG
STRIP_P4S =
else
STRIP_P4S = y
endif
#	whether the <sstrip> utility should be used
#	f8 and calc4th (and 4), only: strip everything which is not required.
#	<install> binaries without -s option, otherwise "unknown file format" error.
ifdef NOSSTRIP
else
NOSSTRIP    =
endif
# define to a(ny) value to globally disable stripping - for <debpak>:
ifdef NOSTRIP
else
NOSTRIP	    =
endif

# "asmutils"
#	expected in some main dir "asmutils-{version}" where the 
#	asmutils' includefiles are:
AUINC   =/usr/src/asm/asmutils/inc/
#	for asmutils' version:
AUDIR	=/usr/src/asm/asmutils
#	insert version and extn. if asmutils is not (linked 
#	to) a versioned directory, e.g. "asmutils-0.15"
AV	=
AX	=
#	host system (is *not* "GNU")
OS	= LINUX
#	au 0.16 requires cpl mode aout or elf, l4 is only ELF
OM	= ELF
#	au 0.16 for <stat> struct, otherwise cpl'd empty
OC	= __S_KERNEL__

#	Linux source for syscall and other host dependent data
SRCINC	= /usr/src/linux
#	optional, path to dpans html docs, for the html-glossaries
#ANSDIR	=
ANSDIR	= /usr/local/doc/forth/ans6-html

# additional flags for the assembler, "nasm"
#	accumulated to mandatory, other flags in Makefile
#ASINC	= -e
ASINC	=


# install path'
#	glossary
DOCDIR	= /usr/share/doc/lib4th
#	dll, LIBDIR should also be entered to '/etc/ld.so.conf'
LIBDIR	= /usr/local/lib
#	support and supplemental source files
LIBF8D	= $(LIBDIR)/f8
#	where the (test-)programs go
PRGDIR  = /usr/local/bin

# dyn lib compilation
#	recommended to assuring that lib4th doesn't duplicate any other libs' names, 
#	in which case <ld> would report an error and point to the name(s) concerned.
#	dynamically linked jobs use ld-linux.so (program interpreter) and lib4th.
SOLIB    = yes
#SOLIB    =

# lib & docs installation, access mode
#	'install' erkennt -m..buchstaben.. nicht !
PMFLAGS  = a+rxX-w
LMFLAGS  = a+r,o+w

# clean compiler state,
#	empty or, extra gcc compileflags
CFLAGS	=

#	empty or, extra linker flags
LDFLAGS =
#	strip local labels
LDFLAGS = -X
#	prevent silly, most stupid, useless 'libc' requirement which those GNU-ish i...
#	seem to insist upon; any(!) 'libc.a' which can be linked to lib4th/inc/libc.a, 
#	path to 'libc.a':
LIBCA	= /usr/lib

# don't change
# (static prog/lib segfault w. 'SIZE', dyn. won't work orderly: asmutils macroes? mmx alignmt?)
OPT    = SPEED
SOPT   = SPEED

# find/set cpu type (currently k6 only)
K6     = $(shell cat /proc/cpuinfo|grep "AMD-K6"||echo $(CFLAGS)|grep -i "cpu=k6\|arch=k6")
#K6     =

# optional, 
#	fetching os related constants from the actual source tree,
#	else edit <admin/unistd-na> to change the Linux defaults.
#	(sub)dir+name of the rsp files:
# -> topdir
LXSRC	= /usr/src/linux
# -> system call names
LXUST	= /include/asm/unistd.h
# -> kernel version
LXVER	= /include/linux/version.h
# -> PAGE_SIZE &c
LXPGS	= /include/asm/page.h
# -> file opr contols
FCNTL	= /include/asm/fcntl.h
# -> common i/o cntrls
IOCTL	= /include/asm/ioctls.h
# -> terminal i/o defns
TMIOS	= /include/asm/termios.h
# -> terminal state description
TMBIT	= /include/asm/termbits.h


# MAKE and L4 debugging, verbosity
ifdef F8V
	ifeq ("$(F8V)"," ")
V	=
	else
V	= $(F8V)
	endif
else
# laber-option (verbose output on/off):
#	off, errors and required(?) messages, only. - re src/*.log files
V = @
#	on, many words about what's going on...
#V =
endif

ifdef F8D
D	= $(F8D)
else
# make for debugging/tracing, disable stripped "4" program version
#D = -g
# or not
#	leave D undefined or empty
endif

# L4 debugging code is about 4K+ in lib4th
#	__MK_DBG enables inner switch, __DBG, both of which need be set to debugging
ifdef F8DEBUG
DEBUG	= $(F8DEBUG)
else
DEBUG   = -d__MK_DBG
endif
#DEBUG   =

# ----------------------------------------------------------------------------- #
# path+names of auxilary programs:
# ----------------------------------------------------------------------------- #

# where nasm listing should be stored
LISDIR  = $(TOPDIR)/doc/lis/

# sudoer program name
#	supposed to finding whether install &c, utils should & can be executed
#	per $(SD), by the particular user who compiles the lib4th programs...
#	user-mode for install, ldconfig, ln, mkdir, <sudo> enabled if in sudoers list
SD = sudo
UI = $(shell id -un)

# set/determine actual user and group
ifeq ($(UI),root)
U  = $(USER)
else
U  = $(UI)
endif
G  = $(GROUP)

# utils
# modifiers should begin with "-", otherwise expect failure of <make check>
#	cp and mv flags
BF = --backup=t

#	asembler - lib4th will NOT assemble with original nasm 0.98!
# ASM = /usr/bin/nasm
# ASM = /usr/src/asm/nasm/nasm
#  devel still a mere desaster (0.98-08,-09, 11/2001)
# ASM = /usr/src/asm/nasm.latest/nasm -O99
# ASM = /usr/src/asm/nasm.latest/nasm -O7
# ASM = /usr/src/asm/nasm-98-3e-20/nasm
# ok: -> nasm-3e, extd' by "[list +|-]" opt.
ASM = /usr/src/asm/nasm-98-3e-21/nasm
# ASM = /usr/src/asm/nasm-test/nasm -O1
#	'official' nasm devel vers' useless! hundreds of errors...
# ASM = /usr/src/asm/nasm-0.98.08/nasm -O0

#	re-def to preventing stupid faults by re-stripping down to 
#	nothing w/ (some vers. of) binutils more recent than 2.11.90
SSTRIP_PROG = $(TOPDIR)/util/sstrip
STRIP_PROG  = /usr/bin/strip
#	file access mode
CM = $(SU) $(shell which chmod)
#	copy files
CP = $(shell which cp) -p $(BF)
#	linux/ELF loader (w/ libc.so.6 = glibc-2.1.3)
DL = /lib/ld-linux.so.2
#	find files - for 'clean' and verification tags
FD = $(shell which find)
FS = $(SU) $(FD)
#	install progs & libs
IN = $(SU) $(shell which install||which ginstall) $(BF) -p 
#	dll into system data-base
LO = $(SU) /sbin/ldconfig
LC = $(LO) -l
#	linker	(v2.10.91)
LD = /usr/bin/ld
#	link files
LN = $(SU) /bin/ln -sf
#	list files
LS = $(shell which ls) -l 2>/dev/null
#	move files
MV = $(shell which mv) $(BF)
#	delete directories
RD = $(SU) /bin/rmdir
#	delete files (recursion is unreliable, use <find>, instead)
RM = $(SU) $(shell which rm) -f
#	terminate running jobs by name, w/ -ve signal no.
KA = /usr/bin/killall -9 

#
# ----------------------------------------------------------------------------- #
# MConfig, lib4th.01 <eof>
