Root/gforth/Makefile

1# Makefile for OpenWRT for cross-compiling GForth
2#
3# Copyright (C) 1995,1996,1997,1998,2000,2003,2006,2007,2008,2009 Free
4# Software Foundation, Inc.
5#
6# Copyright (C) 2010 David K├╝hling. License: GPLv3+
7
8## Note for tuning: In theory you could strip down the resulting packages size
9## a lot, if you removed gforth and gforth-fast executables and only included
10## the (somewhat slower) gforth-itc and/or gforth-ditc interpreter binary that
11## rely on classic indirect threaded code without the (code-bloating) engine
12## optimizations.
13##
14## Also we could create multiple packages here 'gforth-minimal' and 'gforth'?
15
16include $(TOPDIR)/rules.mk
17
18PKG_NAME:=gforth
19PKG_SNAPSHOT_DATE=20100918
20PKG_VERSION=0.7.0-$(PKG_SNAPSHOT_DATE)
21PKG_RELEASE:=5
22
23PKG_BUILD_DEPENDS:= gforth/host libltdl libffi
24PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
25PKG_FIXUP:=libtool
26
27PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
28PKG_SOURCE_URL:=\
29    http://downloads.qi-hardware.com/people/dvdkhlng/ \
30    http://mosquito.dyndns.tv/~spock/
31#PKG_SOURCE_URL:= file://~/forth/gforth/
32PKG_MD5SUM:=5ada9cc3f72fea8ea002bbae4b39d118
33
34# Alternate download #1 via CVS: this doesn't work, as CVS is missing the
35# kernel.fi images needed for boot-strapping :(
36# PKG_SOURCE_PROTO:=cvs
37# PKG_SOURCE_VERSION="-D$(PKG_SNAPSHOT_DATE) 23:59"
38# PKG_SOURCE_URL=:pserver:anonymous@c1.complang.tuwien.ac.at:/nfs/unsafe/cvs-repository/src-master
39# PKG_SOURCE_SUBDIR:=gforth
40# PKG_SOURCE:=gforth-$(PKG_SNAPSHOT_DATE).tar.gz
41
42include $(INCLUDE_DIR)/host-build.mk
43include $(INCLUDE_DIR)/package.mk
44
45define Package/gforth
46  SECTION:=lang
47  CATEGORY:=Languages
48  TITLE:=GForth
49  DEPENDS:= +libltdl +libffi
50  URL:=http://www.gnu.org/software/gforth/
51endef
52
53define Package/gforth/description
54  Gforth is a fast and portable implementation of the ANS Forth
55  language.
56endef
57
58## The host-GForth uses -ltdl to link against the staging dir version of
59## libltdl. However, when the host-GForth runs, it won't find that library,
60## as no library path is encoded into the ltdl dependency (why?). So here we
61## override LD_LIBRARY_PATH for all the build steps that might run the
62## host-GForth.
63HOST_CONFIGURE_VARS += LTDL_LIBRARY_PATH=$(STAGING_DIR_HOST)/lib \
64    no_dynamic_default=1
65
66## Engine's dispatch would be crippled when compiling with -Os, also dynamic
67## superinstructions don't seem to work in that case
68EXTRA_CFLAGS += -O2
69
70define Host/Configure
71    $(call Host/Configure/Default)
72endef
73
74## On the host, we only compile and install minimum number of gforth
75## components
76define Host/Compile
77    $(call Host/Compile/Default, gforth gforth.fi)
78endef
79
80define Host/Install
81    $(INSTALL_DIR) $(STAGING_DIR_HOST)/bin
82    $(INSTALL_DIR) $(STAGING_DIR_HOST)/lib
83    $(INSTALL_BIN) $(HOST_BUILD_DIR)/gforth $(STAGING_DIR_HOST)/bin/
84    $(INSTALL_DATA) $(HOST_BUILD_DIR)/gforth.fi $(STAGING_DIR_HOST)/lib/
85endef
86
87## Configuration of the target gforth (see also gforth-update-image.in!)
88FORTHSIZES=--dictionary-size=1M \
89    --data-stack-size=16k \
90    --fp-stack-size=16k \
91    --return-stack-size=16k \
92    --locals-stack-size=16k
93
94CONFIGURE_VARS += FORTHSIZES="$(FORTHSIZES)"
95PKG_BUILD_LIBCC_DIR = $(PKG_BUILD_DIR)/lib/gforth/$(PKG_VERSION)/libcc-named/
96CROSS_PREFORTH = $(PKG_BUILD_DIR)/preforth
97LIBCC_BUILD_SRC = cstr.fs unix/socket.fs
98MAKE_VARS += libccdir=$(GFORTH_LIBCC_DIR)
99
100## Here we call configure, then patch the cross-GForth source tree to replace
101## the 'preforth' script with a script that calls our host-compiled GForth.
102## We also extract the name of the GForth kernel image used for the target
103## architecture, and the source files used by GForth for implementing the
104## assembler/disassembler for the target architecture.
105define Build/Configure
106    $(call Build/Configure/Default,)
107    cp ./files/gforth-update-image.in ./files/gforth-wrapper.in \
108        $(PKG_BUILD_DIR)/
109    cd $(PKG_BUILD_DIR) && ./config.status --file gforth-update-image \
110        && ./config.status --file gforth-wrapper
111    echo "#!/bin/sh" > $(CROSS_PREFORTH).in
112    echo "export LD_LIBRARY_PATH=$(STAGING_DIR_HOST)/lib;" >> $(CROSS_PREFORTH).in
113    echo '$(STAGING_DIR_HOST)/bin/gforth -i $(STAGING_DIR_HOST)/lib/gforth.fi "$$$$@"' >> $(CROSS_PREFORTH).in
114    chmod a+x $(PKG_BUILD_DIR)/preforth.in
115    cp $(CROSS_PREFORTH).in $(CROSS_PREFORTH)
116endef
117
118## Forth code snippet used for pre-compiling Gforth's libcc based C-interface
119## wrappers on the host, so they can be used on the target. Use $(call) to
120## substitute $(1) with a list of Gforth's interface definition files (such as
121## 'cstr.fs' etc).
122define GforthLibccCompile
123   s" $(PKG_BUILD_LIBCC_DIR)" libcc-named-dir-v 2! \
124   libcc-path clear-path \
125   libcc-named-dir libcc-path also-path \
126   :noname 2drop s" $(GFORTH_LIBCC_DIR)" ; is replace-rpath \
127   : end-c-library try end-c-library endtry-iferror then ; \
128   $(1:%=include $(PKG_BUILD_DIR)/%) \
129   bye
130endef
131
132## Compilation is pretty manual to only build the parts we need. By default
133## the GForth Makefile attempts to auto-tune by recursively calling itself for
134## compilation, then running the GForth binary through unit-tests. This won't
135## work with a cross-compile environment.
136##
137## Todo: we currently always build the -ll-reg version of the engine. On
138## 64-bit architectures this might not work? Damn it, why is the check for
139## 'long long' in the Gforth Makefile, not the configure script?
140## Todo: develop a clean upstream patch to configure/Makefile
141define Build/Compile
142    $(call Build/Compile/Default,kernel/version.fs gforth-ditc \
143        engine/prim-fast.i engine/prim_lab-fast.i engine/prim_names-fast.i \
144        engine/prim_superend-fast.i engine/profile-fast.i \
145        engine/prim_num-fast.i engine/prim_grp-fast.i \
146        engine/costs-fast.i engine/super2-fast.i)
147    $(call Build/Compile/Default, -C $(PKG_BUILD_DIR)/engine \
148        gforth-fast-ll-reg gforth-ll-reg \
149        OPT=-ll-reg OPTDEFINES="-DFORCE_LL -DFORCE_REG" OPTOBJECTS=)
150
151    cp $(PKG_BUILD_DIR)/engine/gforth-ll-reg \
152        $(PKG_BUILD_DIR)/gforth
153    cp $(PKG_BUILD_DIR)/engine/gforth-fast-ll-reg \
154        $(PKG_BUILD_DIR)/gforth-fast
155
156    rm -rf $(PKG_BUILD_DIR)/lib/gforth/$(PKG_VERSION)/libcc-named/
157    export includedir=$(PKG_BUILD_DIR)/include; \
158    $(PKG_BUILD_DIR)/preforth $(PKG_BUILD_DIR)/envos.fs \
159        $(PKG_BUILD_DIR)/libcc.fs \
160         -e '$(call GforthLibccCompile,$(LIBCC_BUILD_SRC))'
161endef
162
163##
164## define lists of GForth's sources to package for loading in the target system
165##
166
167GFORTH_FI_SRC = \
168    assert.fs \
169    backtrac.fs \
170    blocked.fb \
171    blocks.fs \
172    bufio.fs \
173    code.fs \
174    debug.fs \
175    debugs.fs \
176    dis-gdb.fs \
177    ekey.fs \
178    envos.fs \
179    savesys.fs \
180    environ.fs \
181    errors.fs \
182    exboot.fs \
183    except.fs \
184    extend.fs \
185    float.fs \
186    glocals.fs \
187    hash.fs \
188    history.fs \
189    intcomp.fs \
190    mkdir.fs \
191    libcc.fs \
192    locals.fs \
193    look.fs \
194    mkdir.fs \
195    prelude.fs \
196    quotes.fs \
197    search.fs \
198    see.fs \
199    see-ext.fs \
200    simp-see.fs \
201    source.fs \
202    startup.fs \
203    struct.fs \
204    struct0x.fs \
205    stuff.fs \
206    tasker.fs \
207    termsize.fs \
208    utf-8.fs \
209    vt100.fs \
210    vt100key.fs \
211    wordinfo.fs \
212    arch/386/asm.fs arch/386/disasm.fs \
213    arch/amd64/asm.fs arch/amd64/disasm.fs \
214    arch/alpha/asm.fs arch/alpha/disasm.fs arch/alpha/testasm.fs\
215    arch/arm/asm.fs arch/arm/disasm.fs \
216    arch/arm/testdisasm.fs arch/arm/testdisasm.out arch/arm/Makefile \
217    arch/mips/asm.fs arch/mips/disasm.fs arch/mips/insts.fs \
218    arch/mips/testasm.fs arch/mips/testdisasm.fs \
219    arch/power/asm.fs arch/power/disasm.fs arch/power/inst.fs
220
221LIBCC_SRC = cstr.fs unix/socket.fs
222LIBCC_DIST_SRC = libffi.fs fflib.fs $(LIBCC_SRC)
223
224# todo: strip down (really?)
225GFORTH_SRC = $(GFORTH_FI_SRC) $(LIBCC_DIST_SRC) \
226    ans-report.fs ansi.fs answords.fs \
227    colorize.fs comp-i.fs complex.fs \
228    depth-changes.fs dosekey.fs doskey.fs ds2texi.fs \
229    envos.dos envos.os2 etags.fs fft.fs filedump.fs fi2c.fs \
230    fsl-util.4th glosgen.fs gray.fs httpd.fs install-tags.fs \
231    make-app.fs doc/makedoc.fs locate.fs more.fs onebench.fs \
232    other.fs prims2x.fs prims2x0.6.2.fs proxy.fs random.fs \
233    regexp.fs sokoban.fs string.fs table.fs tags.fs \
234    tt.fs \
235    unbuffer.fs wordsets.fs xwords.fs \
236    test/tester.fs test/ttester.fs \
237    test/coretest.fs test/postpone.fs test/dbltest.fs \
238    test/string.fs test/float.fs test/search.fs test/gforth.fs \
239    test/other.fs test/signals.fs test/checkans.fs \
240    test/primtest.fs test/coreext.fs test/deferred.fs \
241    test/coremore.fs test/gforth-nofast.fs test/libcc.fs \
242    test/macros.fs \
243    compat/strcomp.fs \
244    bubble.fs siev.fs matrix.fs fib.fs \
245    oof.fs oofsampl.fs objects.fs objexamp.fs mini-oof.fs moof-exm.fs \
246    moofglos.fs fixpath.fs \
247    add.fs lib.fs oldlib.fs sieve.fs \
248    endtry-iferror.fs recover-endtry.fs
249
250GFORTH_SHARE_DIR = /usr/share/gforth/$(PKG_VERSION)
251GFORTH_LIB_DIR = /usr/lib/gforth/$(PKG_VERSION)
252GFORTH_LIBCC_DIR = $(GFORTH_LIB_DIR)/libcc-named
253GFORTH_BIN_DIR = /usr/bin
254GFORTH_WRAPPED_BIN = gforth gforth-fast
255
256## Select files for package. Note how we rename the GForth kernel image to
257## 'kernel.fi' here, so that 'postinst' can refer to it without depending on
258## architecture-specific naming.
259define Package/gforth/install
260        # create directories
261    $(INSTALL_DIR) $(1)/$(GFORTH_BIN_DIR)
262    $(INSTALL_DIR) $(1)/$(GFORTH_SHARE_DIR)
263    $(INSTALL_DIR) $(1)/$(GFORTH_LIB_DIR)
264    $(INSTALL_DIR) $(1)/$(GFORTH_LIBCC_DIR)
265    $(INSTALL_DIR) $(1)/$(GFORTH_SHARE_DIR)/../site-forth
266
267        # install low-level gforth binaries (for image generation)
268    $(INSTALL_BIN) $(PKG_BUILD_DIR)/gforth-ditc $(1)/$(GFORTH_LIB_DIR)/
269    $(INSTALL_BIN) $(PKG_BUILD_DIR)/gforthmi $(1)/$(GFORTH_BIN_DIR)/
270
271        # Install (empty) site-init script
272    $(INSTALL_DATA) $(PKG_BUILD_DIR)/siteinit.fs \
273        $(1)/$(GFORTH_SHARE_DIR)/../site-forth/
274
275        # install the correct Gforth kernel image
276    echo "$(INSTALL_DATA) $(PKG_BUILD_DIR)/@kernel_fi@ $(1)/$(GFORTH_SHARE_DIR)/" > $(PKG_BUILD_DIR)/install-kernel.sh.in
277    cd $(PKG_BUILD_DIR) && ./config.status --file install-kernel.sh
278    . $(PKG_BUILD_DIR)/install-kernel.sh
279
280        # install updating script and wrap gforth interpreter binaries so that
281        # image is generated on first attempt to run the interpreter.
282    $(call pkg_install_bin, \
283        gforth-wrapper gforth-update-image, \
284        $(PKG_BUILD_DIR),$(1)/$(GFORTH_BIN_DIR))
285    for i in $(GFORTH_WRAPPED_BIN); do \
286      ln -sf gforth-wrapper $(1)/$(GFORTH_BIN_DIR)/$$$$i; \
287      $(INSTALL_BIN) $(PKG_BUILD_DIR)/$$$$i \
288        $(1)/$(GFORTH_BIN_DIR)/$$$$i.real; \
289    done
290
291        # install Gforth sources (for generating gforth.fi)
292    $(call pkg_install_files, \
293        $(GFORTH_SRC), \
294        $(PKG_BUILD_DIR), \
295        $(1)/$(GFORTH_SHARE_DIR))
296
297        # install pre-generated C-interface wrappers (libcc)
298    -for i in $(LIBCC_BUILD_SRC); do \
299          which libtool; \
300      ls -l $(PKG_BUILD_LIBCC_DIR)/.libs; \
301      libtool --mode=install $(INSTALL_DATA) \
302        $(PKG_BUILD_LIBCC_DIR)/`basename $$$$i .fs`.la \
303        $(1)/$(GFORTH_LIBCC_DIR)/; \
304        ls -l $(1)/$(GFORTH_LIBCC_DIR)/; \
305    done
306# -libtool --finish $(1)/$(GFORTH_LIBCC_DIR)
307    -rm -f $(1)/$(GFORTH_LIBCC_DIR)/*.a
308endef
309
310## Directly after installation generate updated interpreter image from
311## installed source code.
312define Package/gforth/postinst
313#! /bin/sh
314if [ -z "$$IPKG_OFFLINE_ROOT" ]; then
315    # only attempt to update image on target, never on host
316    $(GFORTH_BIN_DIR)/gforth-update-image
317fi
318endef
319
320define Package/gforth/prerm
321#! /bin/sh
322if [ -z "$$IPKG_OFFLINE_ROOT" ]; then
323    rm -f $(GFORTH_LIB_DIR)/gforth.fi
324fi
325endef
326
327$(eval $(call HostBuild))
328$(eval $(call BuildPackage,gforth))
329
330# The following comments configure the Emacs editor. Just ignore them.
331# Local Variables:
332# compile-command: "make -C ~/h/src/qi/openwrt-xburst package/gforth/compile -j2 V=99"
333# End:
334

Archive Download this file



interactive