Fix REPOSITION-FILE, HISTORY, locked file handle and other problems.
[pforth] / build / unix / Makefile
index 5285ad3..8896f7c 100644 (file)
@@ -2,13 +2,14 @@
 # Portable Forth written in 'C'
 # by Phil Burk
 # For more info visit http://www.softsynth.com/pforth/
 # Portable Forth written in 'C'
 # by Phil Burk
 # For more info visit http://www.softsynth.com/pforth/
+#
+# See "help" target below.
 
 .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.
 
 
 .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.
 
-# Note for Mac OS X, use cc instead of gcc
 COMPILER = gcc
 
 PFORTHDIR   := $(shell cd ../../; pwd)
 COMPILER = gcc
 
 PFORTHDIR   := $(shell cd ../../; pwd)
@@ -22,6 +23,9 @@ PFORTHAPP    = $(PFORTHDIR)/pforth_standalone
 OBJECTDIR    = $(PFORTHDIR)/objects
 TEMPOBJECTDIR = $(PFORTHDIR)/tempobjects
 
 OBJECTDIR    = $(PFORTHDIR)/objects
 TEMPOBJECTDIR = $(PFORTHDIR)/tempobjects
 
+# This is needed to get pForth to build on Snow Leopard and other 64 bit platforms.
+WIDTHOPT=
+
 FULL_WARNINGS =  \
         -fsigned-char \
         -fno-builtin \
 FULL_WARNINGS =  \
         -fsigned-char \
         -fno-builtin \
@@ -34,8 +38,12 @@ FULL_WARNINGS =  \
         -Winline  \
         -Wmissing-prototypes \
         -Wmissing-declarations
         -Winline  \
         -Wmissing-prototypes \
         -Wmissing-declarations
-        
-CCOPTS = -DPF_SUPPORT_FP -DPF_POSIX_IO -O2 $(FULL_WARNINGS) $(EXTRA_CCOPTS)
+
+DEBUGOPTS = -g
+CCOPTS = $(WIDTHOPT) -x c -DPF_SUPPORT_FP -O2 $(FULL_WARNINGS) $(EXTRA_CCOPTS) $(DEBUGOPTS)
+
+IO_SOURCE = ${CSRCDIR}/posix/pf_io_posix.c
+#IO_SOURCE = ${CSRCDIR}/stdio/pf_io_stdio.c
 
 EMBCCOPTS = -DPF_STATIC_DIC
 
 
 EMBCCOPTS = -DPF_STATIC_DIC
 
@@ -43,17 +51,17 @@ EMBCCOPTS = -DPF_STATIC_DIC
 # Build file lists from wildcards.
 PFITEMP    = ${wildcard ${CSRCDIR}/*.h}
 PFINCLUDES = ${PFITEMP:${CSRCDIR}/pfdicdat.h=}
 # Build file lists from wildcards.
 PFITEMP    = ${wildcard ${CSRCDIR}/*.h}
 PFINCLUDES = ${PFITEMP:${CSRCDIR}/pfdicdat.h=}
-PFSOURCE   = ${wildcard ${CSRCDIR}/*.c} ${CSRCDIR}/posix/pf_io_posix.c
+PFSOURCE   = ${wildcard ${CSRCDIR}/*.c} ${IO_SOURCE}
 PFTEMP     = ${PFSOURCE:%.c=%.o}
 PFOBJS     = ${PFTEMP:${CSRCDIR}/%=${TEMPOBJECTDIR}/%}
 PFEMBOBJS  = ${PFTEMP:${CSRCDIR}/%=${OBJECTDIR}/%}
 
 COMPILE = $(COMPILER) $(CCOPTS) $(CDEFS)
 PFTEMP     = ${PFSOURCE:%.c=%.o}
 PFOBJS     = ${PFTEMP:${CSRCDIR}/%=${TEMPOBJECTDIR}/%}
 PFEMBOBJS  = ${PFTEMP:${CSRCDIR}/%=${OBJECTDIR}/%}
 
 COMPILE = $(COMPILER) $(CCOPTS) $(CDEFS)
-       
-${TEMPOBJECTDIR}/%.o:  ${TEMPOBJECTDIR}/posix $(PFINCLUDES)  ${CSRCDIR}/%.c
+
+${TEMPOBJECTDIR}/%.o:  ${TEMPOBJECTDIR} $(PFINCLUDES)  ${CSRCDIR}/%.c
        $(COMPILE) -O -o ${TEMPOBJECTDIR}/$*.o -c ${CSRCDIR}/$*.c
        $(COMPILE) -O -o ${TEMPOBJECTDIR}/$*.o -c ${CSRCDIR}/$*.c
-       
-${OBJECTDIR}/%.o:  ${OBJECTDIR}/posix $(PFINCLUDES) ${CSRCDIR}/%.c ${CSRCDIR}/pfdicdat.h 
+
+${OBJECTDIR}/%.o:  ${OBJECTDIR} $(PFINCLUDES) ${CSRCDIR}/%.c ${CSRCDIR}/pfdicdat.h
        $(COMPILE) -O -o ${OBJECTDIR}/$*.o -c ${CSRCDIR}/$*.c $(EMBCCOPTS)
 
 all: $(PFORTHAPP)
        $(COMPILE) -O -o ${OBJECTDIR}/$*.o -c ${CSRCDIR}/$*.c $(EMBCCOPTS)
 
 all: $(PFORTHAPP)
@@ -69,31 +77,52 @@ pffiles:
        @echo ${PFOBJS}
        @echo "EMBEDDED OBJECT FILES ------------------"
        @echo ${PFEMBOBJS}
        @echo ${PFOBJS}
        @echo "EMBEDDED OBJECT FILES ------------------"
        @echo ${PFEMBOBJS}
-       
-${TEMPOBJECTDIR}/posix: 
+
+${TEMPOBJECTDIR}:
        mkdir -p ${TEMPOBJECTDIR}/posix
        mkdir -p ${TEMPOBJECTDIR}/posix
+       mkdir -p ${TEMPOBJECTDIR}/stdio
 
 
-${OBJECTDIR}/posix: 
+${OBJECTDIR}:
        mkdir -p ${OBJECTDIR}/posix
        mkdir -p ${OBJECTDIR}/posix
+       mkdir -p ${OBJECTDIR}/stdio
 
 
-# build pforth by compiling 'C' source
+# Build pforth by compiling 'C' source.
 $(PFDICAPP): $(PFINCLUDES) $(PFOBJS)
 $(PFDICAPP): $(PFINCLUDES) $(PFOBJS)
-       $(COMPILER) $(PFOBJS) -lm -o $(PFDICAPP)
-
-pfdicapp: $(PFDICAPP)
+       $(COMPILER) $(PFOBJS) $(WIDTHOPT)  -lm -o $(PFDICAPP)
 
 
-# build basic dictionary by running newly built pforth and including system.fth
+# Build basic dictionary image by running newly built pforth and including "system.fth".
 $(PFDICDAT): $(PFDICAPP)
        cd $(FTHDIR); $(PFDICAPP) -i system.fth ; mv pfdicdat.h $(PFDICDAT)
 
 $(PFDICDAT): $(PFDICAPP)
        cd $(FTHDIR); $(PFDICAPP) -i system.fth ; mv pfdicdat.h $(PFDICDAT)
 
-$(PFORTHAPP): ${TEMPOBJECTDIR}/posix $(PFDICDAT) $(PFINCLUDES) $(PFEMBOBJS)
-       $(COMPILER) $(PFEMBOBJS) -lm -o $(PFORTHAPP)
+$(PFORTHAPP): $(PFDICDAT) $(PFEMBOBJS)
+       $(COMPILER) $(PFEMBOBJS) $(WIDTHOPT) -lm -o $(PFORTHAPP)
        @echo ""
        @echo "Standalone pForth executable written to $(PFORTHAPP)"
        @echo ""
        @echo "Standalone pForth executable written to $(PFORTHAPP)"
-       
+
+
+# target aliases
+pfdicapp: $(PFDICAPP)
+
+pfdicdat: $(PFDICDAT)
+
+pforthapp: $(PFORTHAPP)
+
+help:
+       @echo "Use 'make all' to build standalone pForth executable."
+       @echo "PForth can be built in several stages using these targets:"
+       @echo "   pfdicapp = executable pForth with minimal dictionary. All from 'C'."
+       @echo "   pfdicdat = image of full dictionary build by compiling Forth code."
+       @echo "   pforthapp = executable with embedded dictionary image. DEFAULT 'all' target."
+       @echo ""
+       @echo "   The file 'fth/pfdicdat.h' is generated by pForth. It contains a binary image of the Forth dictionary."
+       @echo "   It allows pForth to work as a standalone image that does not need to load a dictionary file."
+
+
 clean:
 clean:
-       -rm -f $(PFOBJS) $(PFEMBOBJS)
-       -rm $(PFORTHAPP)
-       -rm $(PFDICDAT)
-       -rm $(PFORTHDIC)
-       -rm $(PFDICAPP)
+       rm -f $(PFOBJS) $(PFEMBOBJS)
+       rm -f $(PFORTHAPP)
+       rm -f $(PFDICDAT)
+       rm -f $(PFORTHDIC)
+       rm -f $(PFDICAPP)
+       rm -rf $(OBJECTDIR) $(TEMPOBJECTDIR)
+