Fixed lots of warning and made code compatible with C89 and ANSI with -pedantic.
[debian/pforth] / build / unix / Makefile
1 # makefile for pForth
2 # Portable Forth written in 'C'
3 # by Phil Burk
4 # For more info visit http://www.softsynth.com/pforth/
5 #
6 # See "help" target below.
7
8 .SUFFIXES: .c .o
9
10 # Options include: PF_SUPPORT_FP PF_NO_MALLOC PF_NO_INIT PF_DEBUG
11 # See "docs/pf_ref.htm" file for more info.
12
13 COMPILER = gcc
14
15 PFORTHDIR   := $(shell cd ../../; pwd)
16 CSRCDIR      = $(PFORTHDIR)/csrc
17 FTHDIR       = $(PFORTHDIR)/fth
18
19 PFDICAPP     = $(FTHDIR)/pforth
20 PFORTHDIC    = $(FTHDIR)/pforth.dic
21 PFDICDAT     = ${CSRCDIR}/pfdicdat.h
22 PFORTHAPP    = $(PFORTHDIR)/pforth_standalone
23 OBJECTDIR    = $(PFORTHDIR)/objects
24 TEMPOBJECTDIR = $(PFORTHDIR)/tempobjects
25
26 # This is needed to get pForth to build on Snow Leopard and other 64 bit platforms.
27 WIDTHOPT=
28
29 FULL_WARNINGS =  \
30         -c89 \
31         -fsigned-char \
32         -fno-builtin \
33         -fno-unroll-loops \
34         -fpeephole \
35         -fno-keep-inline-functions \
36         -pedantic \
37         -Wcast-qual \
38         -Wall \
39         -Wwrite-strings \
40         -Winline  \
41         -Wmissing-prototypes \
42         -Wmissing-declarations
43
44 DEBUGOPTS = -g
45 CCOPTS = $(WIDTHOPT) -x c -DPF_SUPPORT_FP -O2 $(FULL_WARNINGS) $(EXTRA_CCOPTS) $(DEBUGOPTS)
46
47 IO_SOURCE = ${CSRCDIR}/posix/pf_io_posix.c
48 #IO_SOURCE = ${CSRCDIR}/stdio/pf_io_stdio.c
49
50 EMBCCOPTS = -DPF_STATIC_DIC
51
52 #######################################
53 # Build file lists from wildcards.
54 PFITEMP    = ${wildcard ${CSRCDIR}/*.h}
55 PFINCLUDES = ${PFITEMP:${CSRCDIR}/pfdicdat.h=}
56 PFSOURCE   = ${wildcard ${CSRCDIR}/*.c} ${IO_SOURCE}
57 PFTEMP     = ${PFSOURCE:%.c=%.o}
58 PFOBJS     = ${PFTEMP:${CSRCDIR}/%=${TEMPOBJECTDIR}/%}
59 PFEMBOBJS  = ${PFTEMP:${CSRCDIR}/%=${OBJECTDIR}/%}
60
61 COMPILE = $(COMPILER) $(CCOPTS) $(CDEFS)
62
63 ${TEMPOBJECTDIR}/%.o:  ${TEMPOBJECTDIR} $(PFINCLUDES)  ${CSRCDIR}/%.c
64         $(COMPILE) -O -o ${TEMPOBJECTDIR}/$*.o -c ${CSRCDIR}/$*.c
65
66 ${OBJECTDIR}/%.o:  ${OBJECTDIR} $(PFINCLUDES) ${CSRCDIR}/%.c ${CSRCDIR}/pfdicdat.h
67         $(COMPILE) -O -o ${OBJECTDIR}/$*.o -c ${CSRCDIR}/$*.c $(EMBCCOPTS)
68
69 all: $(PFORTHAPP)
70
71 pffiles:
72         @echo "ITEMP FILES -----------------"
73         @echo ${PFITEMP}
74         @echo "INCLUDE FILES -----------------"
75         @echo ${PFINCLUDES}
76         @echo "'C' FILES ---------------------"
77         @echo ${PFSOURCE}
78         @echo "OBJECT FILES ------------------"
79         @echo ${PFOBJS}
80         @echo "EMBEDDED OBJECT FILES ------------------"
81         @echo ${PFEMBOBJS}
82
83 ${TEMPOBJECTDIR}:
84         mkdir -p ${TEMPOBJECTDIR}/posix
85         mkdir -p ${TEMPOBJECTDIR}/stdio
86
87 ${OBJECTDIR}:
88         mkdir -p ${OBJECTDIR}/posix
89         mkdir -p ${OBJECTDIR}/stdio
90
91 # Build pforth by compiling 'C' source.
92 $(PFDICAPP): $(PFINCLUDES) $(PFOBJS)
93         $(COMPILER) $(PFOBJS) $(WIDTHOPT)  -lm -o $(PFDICAPP)
94
95 # Build basic dictionary image by running newly built pforth and including "system.fth".
96 $(PFDICDAT): $(PFDICAPP)
97         cd $(FTHDIR); $(PFDICAPP) -i system.fth ; mv pfdicdat.h $(PFDICDAT)
98
99 $(PFORTHAPP): $(PFDICDAT) $(PFEMBOBJS)
100         $(COMPILER) $(PFEMBOBJS) $(WIDTHOPT) -lm -o $(PFORTHAPP)
101         @echo ""
102         @echo "Standalone pForth executable written to $(PFORTHAPP)"
103
104
105 # target aliases
106 pfdicapp: $(PFDICAPP)
107
108 pfdicdat: $(PFDICDAT)
109
110 pforthapp: $(PFORTHAPP)
111
112 help:
113         @echo "Use 'make all' to build standalone pForth executable."
114         @echo "PForth can be built in several stages using these targets:"
115         @echo "   pfdicapp = executable pForth with minimal dictionary. All from 'C'."
116         @echo "   pfdicdat = image of full dictionary build by compiling Forth code."
117         @echo "   pforthapp = executable with embedded dictionary image. DEFAULT 'all' target."
118         @echo ""
119         @echo "   The file 'fth/pfdicdat.h' is generated by pForth. It contains a binary image of the Forth dictionary."
120         @echo "   It allows pForth to work as a standalone image that does not need to load a dictionary file."
121
122 test: $(PFORTHAPP)
123         cd $(FTHDIR); ../pforth_standalone -q t_corex.fth
124         cd $(FTHDIR); ../pforth_standalone -q t_strings.fth
125         cd $(FTHDIR); ../pforth_standalone -q t_locals.fth
126         cd $(FTHDIR); ../pforth_standalone -q t_alloc.fth
127         cd $(FTHDIR); ../pforth_standalone -q t_floats.fth
128
129 clean:
130         rm -f $(PFOBJS) $(PFEMBOBJS)
131         rm -f $(PFORTHAPP)
132         rm -f $(PFDICDAT)
133         rm -f $(PFORTHDIC)
134         rm -f $(PFDICAPP)
135         rm -rf $(OBJECTDIR) $(TEMPOBJECTDIR)
136