Date:2010-09-18 20:47:21 (13 years 6 months ago)
Author:David Kühling
Commit:4bfce3b6e2ea095ea3d9f5d2d1018cc0a1e5ce09
Message:Major overhaul and cleanup. Support for .ubi image file installations.

Only compile&install a minimum host Gforth for bootstrapping the target
Gforth, removing strange emacs-dependencies that cropped up earlier.

Image file can now be built on the nanonote using 'gforth-update-image'
command. Also, Gforth is now run through a wrapper that calls
'gforth-update-image' automatically, if necessary.

Also first attempts at supporting libcc C-interface libraries pre-compiled on
the host.

Tested to compile on amd64 and i386.
Files: gforth/Makefile (7 diffs)
gforth/files/gforth-update-image.in (1 diff)
gforth/files/gforth-wrapper.in (1 diff)

Change Details

gforth/Makefile
1616include $(TOPDIR)/rules.mk
1717
1818PKG_NAME:=gforth
19PKG_SNAPSHOT_DATE=2010913
19PKG_SNAPSHOT_DATE=20100918
2020PKG_VERSION=0.7.0-$(PKG_SNAPSHOT_DATE)
21PKG_RELEASE:=4
21PKG_RELEASE:=1
2222
23
24PKG_BUILD_DEPENDS:= gforth/host libltdl/host
23PKG_BUILD_DEPENDS:= gforth/host libltdl/host libtool/host libffi
2524PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
2625PKG_FIXUP:=libtool
2726
...... 
3029    http://user.cs.tu-berlin.de/~dvdkhlng/ \
3130    http://mosquito.dyndns.tv/~spock/
3231#PKG_SOURCE_URL:= file://~/forth/gforth/
33PKG_MD5SUM:=4b52f42aac9c78121dedeca7aa998b37
32PKG_MD5SUM:=f912b58c2434a9e1df7d4f8db75636da
3433
3534# Alternate download #1 via CVS: this doesn't work, as CVS is missing the
3635# kernel.fi images needed for boot-strapping :(
...... 
5655  language.
5756endef
5857
59HOST_CONFIGURE_VARS += LTDL_LIBRARY_PATH=$(STAGING_DIR_HOST)/lib
60
61## Engine's dispatch would be crippled when compiling with -Os, also dynamic
62## superinstructions don't seem to work in that case
63EXTRA_CFLAGS += -O2
64
6558## The host-GForth uses -ltdl to link against the staging dir version of
6659## libltdl. However, when the host-GForth runs, it won't find that library,
6760## as no library path is encoded into the ltdl dependency (why?). So here we
6861## override LD_LIBRARY_PATH for all the build steps that might run the
6962## host-GForth.
63HOST_CONFIGURE_VARS += LTDL_LIBRARY_PATH=$(STAGING_DIR_HOST)/lib \
64    no_dynamic_default=1 \
65    LD_LIBRARY_PATH=$(STAGING_DIR_HOST)/lib
66
67## Engine's dispatch would be crippled when compiling with -Os, also dynamic
68## superinstructions don't seem to work in that case
69EXTRA_CFLAGS += -O2
7070
7171define Host/Configure
72    export LD_LIBRARY_PATH=$(STAGING_DIR_HOST)/lib; \
7372    $(call Host/Configure/Default)
7473endef
7574
75## On the host, we only compile and install minimum number of gforth
76## components
7677define Host/Compile
7778    export LD_LIBRARY_PATH=$(STAGING_DIR_HOST)/lib; \
78    $(call Host/Compile/Default)
79    $(call Host/Compile/Default, gforth gforth.fi)
7980endef
8081
8182define Host/Install
8283    export LD_LIBRARY_PATH=$(STAGING_DIR_HOST)/lib; \
83    $(call Host/Install/Default)
84    $(INSTALL_DIR) $(STAGING_DIR_HOST)/bin
85    $(INSTALL_DIR) $(STAGING_DIR_HOST)/lib
86    $(INSTALL_BIN) $(HOST_BUILD_DIR)/gforth $(STAGING_DIR_HOST)/bin/
87    $(INSTALL_DATA) $(HOST_BUILD_DIR)/gforth.fi $(STAGING_DIR_HOST)/lib/
8488endef
8589
86## Configuration of the target gforth
90## Configuration of the target gforth (see also gforth-update-image.in!)
8791FORTHSIZES=--dictionary-size=1M \
8892    --data-stack-size=16k \
8993    --fp-stack-size=16k \
...... 
9195    --locals-stack-size=16k
9296
9397CONFIGURE_VARS += FORTHSIZES="$(FORTHSIZES)"
94
98PKG_BUILD_LIBCC_DIR = $(PKG_BUILD_DIR)/lib/gforth/$(PKG_VERSION)/libcc-named/
9599CROSS_PREFORTH = $(PKG_BUILD_DIR)/preforth
100LIBCC_BUILD_SRC = cstr.fs unix/socket.fs
101MAKE_VARS += libccdir=$(GFORTH_LIBCC_DIR)
96102
97103## Here we call configure, then patch the cross-GForth source tree to replace
98104## the 'preforth' script with a script that calls our host-compiled GForth.
...... 
101107## assembler/disassembler for the target architecture.
102108define Build/Configure
103109    $(call Build/Configure/Default,)
104    echo "@kernel_fi@" > $(PKG_BUILD_DIR)/kernel_fi.in
105    cd $(PKG_BUILD_DIR) && ./config.status --file kernel_fi
106    echo "@asm_fs@ @disasm_fs@" > $(PKG_BUILD_DIR)/asm_fs.in
107    cd $(PKG_BUILD_DIR) && ./config.status --file asm_fs
110    cp ./files/gforth-update-image.in ./files/gforth-wrapper.in \
111        $(PKG_BUILD_DIR)/
112    cd $(PKG_BUILD_DIR) && ./config.status --file gforth-update-image \
113        && ./config.status --file gforth-wrapper
108114    echo "#!/bin/sh" > $(CROSS_PREFORTH)
109115    echo "export LD_LIBRARY_PATH=$(STAGING_DIR_HOST)/lib;" >> $(CROSS_PREFORTH)
110    echo '$(STAGING_DIR_HOST)/bin/gforth -i $(STAGING_DIR_HOST)/lib/gforth/$(PKG_VERSION)/gforth.fi "$$$$@"' >> $(CROSS_PREFORTH)
116    echo '$(STAGING_DIR_HOST)/bin/gforth -i $(STAGING_DIR_HOST)/lib/gforth.fi "$$$$@"' >> $(CROSS_PREFORTH)
111117    chmod a+x $(PKG_BUILD_DIR)/preforth
112118endef
113119
120## Forth code snippet used for pre-compiling Gforth's libcc based C-interface
121## wrappers on the host, so they can be used on the target. Use $(call) to
122## substitute $(1) with a list of Gforth's interface definition files (such as
123## 'cstr.fs' etc).
124define GforthLibccCompile
125   s" $(PKG_BUILD_LIBCC_DIR)" libcc-named-dir-v 2! \
126   libcc-path clear-path \
127   libcc-named-dir libcc-path also-path \
128   :noname 2drop s" $(GFORTH_LIBCC_DIR)" ; is replace-rpath \
129   : end-c-library try end-c-library endtry-iferror then ; \
130   $(1:%=include $(PKG_BUILD_DIR)/%) \
131   bye
132endef
133
114134## Compilation is pretty manual to only build the parts we need. By default
115135## the GForth Makefile attempts to auto-tune by recursively calling itself for
116136## compilation, then running the GForth binary through unit-tests. This won't
...... 
121141## 'long long' in the Gforth Makefile, not the configure script?
122142## Todo: develop a clean upstream patch to configure/Makefile
123143define Build/Compile
124    $(MAKE) -C $(PKG_BUILD_DIR) kernel/version.fs gforth-ditc \
144    $(call Build/Compile/Default,kernel/version.fs gforth-ditc \
125145        engine/prim-fast.i engine/prim_lab-fast.i engine/prim_names-fast.i \
126146        engine/prim_superend-fast.i engine/profile-fast.i \
127147        engine/prim_num-fast.i engine/prim_grp-fast.i \
128        engine/costs-fast.i engine/super2-fast.i
129    $(MAKE) -C $(PKG_BUILD_DIR)/engine gforth-fast-ll-reg gforth-ll-reg \
130        OPT=-ll-reg OPTDEFINES="-DFORCE_LL -DFORCE_REG" OPTOBJECTS=
131    cd $(PKG_BUILD_DIR) && \
132            cp engine/gforth-ll-reg ./gforth && \
133        cp engine/gforth-fast-ll-reg ./gforth-fast
148        engine/costs-fast.i engine/super2-fast.i)
149    $(call Build/Compile/Default, -C $(PKG_BUILD_DIR)/engine \
150        gforth-fast-ll-reg gforth-ll-reg \
151        OPT=-ll-reg OPTDEFINES="-DFORCE_LL -DFORCE_REG" OPTOBJECTS=)
152
153    cp $(PKG_BUILD_DIR)/engine/gforth-ll-reg \
154        $(PKG_BUILD_DIR)/gforth
155    cp $(PKG_BUILD_DIR)/engine/gforth-fast-ll-reg \
156        $(PKG_BUILD_DIR)/gforth-fast
157
158    rm -rf $(PKG_BUILD_DIR)/lib/gforth/$(PKG_VERSION)/libcc-named/
159    export includedir=$(PKG_BUILD_DIR)/include; \
160    $(PKG_BUILD_DIR)/preforth $(PKG_BUILD_DIR)/envos.fs \
161        $(PKG_BUILD_DIR)/libcc.fs \
162         -e '$(call GforthLibccCompile,$(LIBCC_BUILD_SRC))'
134163endef
135164
136165##
...... 
220249    add.fs lib.fs oldlib.fs sieve.fs \
221250    endtry-iferror.fs recover-endtry.fs
222251
223GFORTH_BIN = gforth gforth-fast gforthmi
224
225252GFORTH_SHARE_DIR = /usr/share/gforth/$(PKG_VERSION)
226253GFORTH_LIB_DIR = /usr/lib/gforth/$(PKG_VERSION)
254GFORTH_LIBCC_DIR = $(GFORTH_LIB_DIR)/libcc-named
227255GFORTH_BIN_DIR = /usr/bin
256GFORTH_WRAPPED_BIN = gforth gforth-fast
228257
229258## Select files for package. Note how we rename the GForth kernel image to
230259## 'kernel.fi' here, so that 'postinst' can refer to it without depending on
231260## architecture-specific naming.
232261define Package/gforth/install
262        # create directories
233263    $(INSTALL_DIR) $(1)/$(GFORTH_BIN_DIR)
234264    $(INSTALL_DIR) $(1)/$(GFORTH_SHARE_DIR)
235265    $(INSTALL_DIR) $(1)/$(GFORTH_LIB_DIR)
266    $(INSTALL_DIR) $(1)/$(GFORTH_LIBCC_DIR)
236267    $(INSTALL_DIR) $(1)/$(GFORTH_SHARE_DIR)/../site-forth
237    $(INSTALL_DATA) $(PKG_BUILD_DIR)/$$$$(cat $(PKG_BUILD_DIR)/kernel_fi) $(1)/$(GFORTH_SHARE_DIR)/kernel.fi
268
269        # install low-level gforth binaries (for image generation)
238270    $(INSTALL_BIN) $(PKG_BUILD_DIR)/gforth-ditc $(1)/$(GFORTH_LIB_DIR)/
239    $(INSTALL_DATA) $(PKG_BUILD_DIR)/siteinit.fs $(1)/$(GFORTH_SHARE_DIR)/../site-forth/
240    $(call pkg_install_bin,$(GFORTH_BIN),$(PKG_BUILD_DIR),$(1)/$(GFORTH_BIN_DIR))
241    $(call pkg_install_files,$(GFORTH_SRC),$(PKG_BUILD_DIR),$(1)/$(GFORTH_SHARE_DIR))
271    $(INSTALL_BIN) $(PKG_BUILD_DIR)/gforthmi $(1)/$(GFORTH_BIN_DIR)/
272
273        # Install (empty) site-init script
274    $(INSTALL_DATA) $(PKG_BUILD_DIR)/siteinit.fs \
275        $(1)/$(GFORTH_SHARE_DIR)/../site-forth/
276
277        # install the correct Gforth kernel image
278    echo "$(INSTALL_DATA) $(PKG_BUILD_DIR)/@kernel_fi@ $(1)/$(GFORTH_SHARE_DIR)/" > $(PKG_BUILD_DIR)/install-kernel.sh.in
279    $(PKG_BUILD_DIR)/config.status --file $(PKG_BUILD_DIR)/install-kernel.sh
280    . $(PKG_BUILD_DIR)/install-kernel.sh
281
282        # install updating script and wrap gforth interpreter binaries so that
283        # image is generated on first attempt to run the interpreter.
284    $(call pkg_install_bin, \
285        gforth-wrapper gforth-update-image, \
286        $(PKG_BUILD_DIR),$(1)/$(GFORTH_BIN_DIR))
287    for i in $(GFORTH_WRAPPED_BIN); do \
288      ln -sf gforth-wrapper $(1)/$(GFORTH_BIN_DIR)/$$$$i; \
289      $(INSTALL_BIN) $(PKG_BUILD_DIR)/$$$$i \
290        $(1)/$(GFORTH_BIN_DIR)/$$$$i.real; \
291    done
292
293        # install Gforth sources (for generating gforth.fi)
294    $(call pkg_install_files, \
295        $(GFORTH_SRC), \
296        $(PKG_BUILD_DIR), \
297        $(1)/$(GFORTH_SHARE_DIR))
298
299        # install pre-generated C-interface wrappers (libcc)
300    -for i in $(LIBCC_BUILD_SRC); do \
301      libtool --mode=install $(INSTALL_BIN) \
302        $(PKG_BUILD_LIBCC_DIR)/`basename $$$$i .fs`.la \
303        $(1)/$(GFORTH_LIBCC_DIR)/; \
304    done
305    -libtool --finish $(1)/$(GFORTH_LIBCC_DIR)
306    -rm -f $(1)/$(GFORTH_LIBCC_DIR)/*.a
242307endef
243308
244FORTHKFLAGS= --die-on-signal -i kernel.fi
245
246## make sure this is never evaluated before the configure step ran, else
247## $(shell) below is going to fail! We use the $(shell) to use the correct
248## Gforth assembler implementation that was chosen by gforth's configure
249## script, when building the forth image.
250STARTUP = exboot.fs startup.fs $(shell cat $(PKG_BUILD_DIR)/asm_fs)
251
252## Directly after installation load the source once and generate a
253## corresponding interpreter image. GForth needs that for quick startup.
309## Directly after installation generate updated interpreter image from
310## installed source code.
254311define Package/gforth/postinst
255312#! /bin/sh
256echo "Creating GForth interpreter image..."
257export GFORTH="$(GFORTH_BIN_DIR)/gforth $(FORTHSIZES) $(FORTHKFLAGS) $(STARTUP)"
258gforthmi $(GFORTH_LIB_DIR)/gforth.fi $(FORTHSIZES) $(FORTHKFLAGS) $(STARTUP)
313$(GFORTH_BIN_DIR)/gforth-update-image
259314endef
260315
261316define Package/gforth/prerm
gforth/files/gforth-update-image.in
1#! /bin/sh
2#
3# Part of gforth package for OpenWrt: update Gforth pre-compiled interpreter
4# image from installed sources
5#
6# Copyright (C) 2010 David Kuehling <dvdkhlng TA gmx TOD de>
7#
8# License: GPLv3+, NO WARRANTY
9#
10
11# Rationale for choice of stack sizes, see Gforth Manual chapter 13.6
12FORTHSIZES="--dictionary-size=1M \
13    --data-stack-size=16k \
14    --fp-stack-size=15872 \
15    --return-stack-size=15360 \
16    --locals-stack-size=14848"
17
18STARTUP="exboot.fs startup.fs @asm_fs@ @disasm_fs@"
19
20FORTHKFLAGS="--die-on-signal -i @kernel_fi@"
21
22GFORTH_SHARE_DIR=/usr/share/gforth/@PACKAGE_VERSION@
23GFORTH_LIB_DIR=/usr/lib/gforth/@PACKAGE_VERSION@
24GFORTH_BIN_DIR=/usr/bin
25
26GFORTH_FI=${GFORTH_LIB_DIR}/gforth.fi
27
28echo "Creating Gforth interpreter image..."
29
30mkdir -p $GFORTH_LIB_DIR
31
32check_writable(){
33    if [ -f $GFORTH_FI ] && ! [ -w $GFORTH_FI ]; then
34    return 1
35    elif ! [ -w $GFORTH_LIB_DIR ]; then
36    return 1
37    fi
38
39    return 0
40}
41
42if ! check_writable; then
43    cat <<EOF
44  You do not have permissions to create/modify the
45  image file:
46    $GFORTH_FI
47
48  Are you not root?
49EOF
50    exec false
51fi
52
53export libccdir=${GFORTH_LIB_DIR}/libcc-named
54export GFORTH="/usr/bin/gforth.real ${FORTHSIZES} ${FORTHKFLAGS} ${STARTUP}"
55gforthmi ${GFORTH_FI}.new ${FORTHSIZES} ${FORTHKFLAGS} ${STARTUP} &&
56mv -f ${GFORTH_FI}.new ${GFORTH_FI}
57exit $?
58
59
60
gforth/files/gforth-wrapper.in
1#! /bin/sh
2#
3# Part of gforth package for OpenWrt: Wrapper to call check for and create
4# Gforth image before running executable.
5#
6# Copyright (C) 2010 David Kuehling <dvdkhlng TA gmx TOD de>
7#
8# License: GPLv3+, NO WARRANTY
9#
10dirname=$(dirname "$0")
11binary=$dirname/$(basename "$0").real
12
13GFORTH_LIB_DIR=/usr/lib/gforth/@PACKAGE_VERSION@
14GFORTH_FI=$GFORTH_LIB_DIR/gforth.fi
15
16# try to (re)generate the gforth.fi image file
17do_update(){
18    $dirname/gforth-update-image &> /dev/null
19    status=$?
20    [ $status = 0 ] && return 0
21
22cat<<EOF
23  Gforth image $GFORTH_FI
24  is missing and regeneration failed:
25
26  '$dirname/gforth-update-image'
27  aborted with exit code $status.
28
29  Try to re-run 'gforth-update-image' manually to
30  see what is wrong. Also please report this
31  problem to <discussion@lists.qi-hardware.com>
32  and/or <dvdkhlng ta gmx tod de>.
33
34  As a workaround, you can run a kernel-only Gforth
35  (with reduced functionality), using:
36
37  $binary -i @kernel_fi@
38EOF
39
40  exec false
41}
42
43if ! [ -f "$GFORTH_FI" ]; then
44    do_update
45fi
46
47# if everything is ok, we'll come here and run the actual Gforth executable
48# (gforth.real, gforth-fast.real etc.)
49exec "$binary" "$@"
50

Archive Download the corresponding diff file



interactive