# @(#) rlsMakefile 97/12/10 1.1
# makefile for pForth
# Portable Forth written in 'C'
# Phil Burk

.SUFFIXES: .c .o

# Options include: PF_SUPPORT_FP PF_NO_MALLOC PF_NO_INIT PF_DEBUG
# See "docs/pf_ref.htm" file for more info.

SOURCEDIR = csrc
OBJECTDIR = objects
EMBOBJECTDIR = embobjects

FULL_WARNINGS =  -O2 \
        -fsigned-char \
        -fno-builtin \
        -fno-unroll-loops \
        -fpeephole \
        -fno-keep-inline-functions \
        -x c++ \
        -Wcast-qual \
        -Wall \
        -Wwrite-strings \
        -Winline  \
        -Wmissing-prototypes \
        -Wmissing-declarations
        
CCOPTS = -DPF_SUPPORT_FP $(FULL_WARNINGS)
COMPILER = gcc

EMBCCOPTS = -DPF_NO_INIT -DPF_NO_MALLOC -DPF_NO_FILEIO \
    -DPF_NO_CLIB -DPF_STATIC_DIC

#######################################
# Build file lists from wildcards.
PFITEMP    = ${wildcard ${SOURCEDIR}/*.h}
PFINCLUDES = ${PFITEMP:${SOURCEDIR}/pfdicdat.h=}
PFSOURCE   = ${wildcard ${SOURCEDIR}/*.c}
PFTEMP     = ${PFSOURCE:%.c=%.o}
PFOBJS     = ${PFTEMP:${SOURCEDIR}/%=${OBJECTDIR}/%}
PFEMBOBJS  = ${PFTEMP:${SOURCEDIR}/%=${EMBOBJECTDIR}/%}

COMPILE = $(COMPILER) $(CCOPTS) $(CDEFS)

${OBJECTDIR}/%.o:  $(PFINCLUDES)  ${SOURCEDIR}/%.c
	$(COMPILE) -O -o ${OBJECTDIR}/$*.o -c ${SOURCEDIR}/$*.c
	
${EMBOBJECTDIR}/%.o:  $(PFINCLUDES) ${SOURCEDIR}/%.c ${SOURCEDIR}/pfdicdat.h 
	$(COMPILE) -O -o ${EMBOBJECTDIR}/$*.o -c ${SOURCEDIR}/$*.c $(EMBCCOPTS)

all: pforth pforth.dic

pffiles:
	echo "ITEMP FILES -----------------"
	echo ${PFITEMP}
	echo "INCLUDE FILES -----------------"
	echo ${PFINCLUDES}
	echo "'C' FILES ---------------------"
	echo ${PFSOURCE}
	echo "OBJECT FILES ------------------"
	echo ${PFOBJS}
	echo "EMBEDDED OBJECT FILES ------------------"
	echo ${PFEMBOBJS}
	
# build pforth by compiling 'C' source
pforth: $(PFINCLUDES) $(PFOBJS)
	$(COMPILER) $(PFOBJS) -lm -o pforth

# build basic dictionary by running newly built pforth and including system.fth
pforth.dic: pforth
	pforth -i system.fth

${SOURCEDIR}/pfdicdat.h: pforth pforth.dic
	@(echo 'INCLUDE utils/savedicd.fth'; \
          echo 'SDAD';         \
          echo 'bye')                                 | \
	pforth -dpforth.dic
	cp pfdicdat.h ${SOURCEDIR}


pfemb: $(PFINCLUDES) $(PFEMBOBJS)
	$(COMPILER) $(PFEMBOBJS) -lm -o pfemb
	
clean:
	rm -f $(PFOBJS) $(PFEMBOBJS) pforth *.dic core ${SOURCEDIR}/pfdicdat.h pfemb

