Date:2010-07-29 00:46:48 (10 years 6 months ago)
Author:David Kühling
Commit:f03c9b20295ccdcea9012816f62232b419b0d131
Message:Build gforth interpreter image on installation (via 'postinst'); startup time now 200ms. Use correct target-arch dependent gforth kernel image. Add documentation.

Files: gforth/Makefile (5 diffs)
gforth/files/gforth (1 diff)

Change Details

gforth/Makefile
22#
33# Copyright (C) 2010 David Kühling. License: GPLv2+
44
5## Note for tuning: In theory you could strip down the resulting packages size
6## a lot, if you removed gforth and gforth-fast executables and only included
7## the (somewhat slower) gforth-itc and/or gforth-ditc interpreter binary that
8## rely on classic indirect threaded code without the (code-bloating) engine
9## optimizations.
10##
11## Also we could create multiple packages here 'gforth-minimal' and 'gforth'?
12
513include $(TOPDIR)/rules.mk
614
715PKG_NAME:=gforth
816PKG_VERSION:=0.7.0-20100725
9PKG_RELEASE:=4
17PKG_RELEASE:=5
1018
1119PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
1220PKG_SOURCE_URL:=http://mosquito.dyndns.tv/~spock/
...... 
6977# todo: compiler options / tuning (openwrt sets bad defaults?)
7078# todo: either gcc 3.4 or -Os makes primitives use doubly-indirect dispatch :(
7179
72CROSS_PREFORTH=$(PKG_BUILD_DIR)/preforth
80## Configuration of the target gforth
81FORTHSIZES=--dictionary-size=1M \
82    --data-stack-size=16k \
83    --fp-stack-size=16k \
84    --return-stack-size=16k \
85    --locals-stack-size=16k
86
87CROSS_CONFIGURE_VARS += FORTHSIZES="$(FORTHSIZES)" \
88    skipcode=".skip 16"
7389
74## here we call configure, then patch the cross-GForth source tree to replace
75## the 'preforth' script with a script that calls our host-compiled GForth
90CROSS_PREFORTH = $(PKG_BUILD_DIR)/preforth
91
92## Here we call configure, then patch the cross-GForth source tree to replace
93## the 'preforth' script with a script that calls our host-compiled GForth.
94## We also extract the name of the GForth kernel image used for the target
95## architecture.
7696define Build/Configure
7797    $(call Build/Configure/Default,)
98    echo "@kernel_fi@" > $(PKG_BUILD_DIR)/kernel_fi.in
99    cd $(PKG_BUILD_DIR) && ./config.status --file kernel_fi
78100    echo "#!/bin/sh" > $(CROSS_PREFORTH)
79101    echo "export LD_LIBRARY_PATH=$(STAGING_DIR_HOST)/lib;" >> $(CROSS_PREFORTH)
80102    echo '$(STAGING_DIR_HOST)/bin/gforth -i $(STAGING_DIR_HOST)/lib/gforth/$(PKG_VERSION)/gforth.fi "$$$$@"' >> $(CROSS_PREFORTH)
...... 
84106## Compilation is pretty manual to only build the parts we need. By default
85107## the GForth Makefile attempts to auto-tune by recursively calling itself for
86108## compilation, then running the GForth binary through unit-tests. This won't
87## work with a cross-compile environment
109## work with a cross-compile environment.
110##
111## todo: find out the correct kernel image and rename it 'kernel.fi', so we
112## can find it without adapting postinst script.
88113define Build/Compile
89114    $(MAKE) -C $(PKG_BUILD_DIR) kernel/version.fs gforth-ditc \
90115        engine/prim-fast.i engine/prim_lab-fast.i engine/prim_names-fast.i \
...... 
155180LIBCC_SRC = cstr.fs unix/socket.fs
156181LIBCC_DIST_SRC = libffi.fs fflib.fs $(LIBCC_SRC)
157182
158# todo: strip down
159FORTH_SRC = $(GFORTH_FI_SRC) $(LIBCC_DIST_SRC) \
183# todo: strip down (really?)
184GFORTH_SRC = $(GFORTH_FI_SRC) $(LIBCC_DIST_SRC) \
160185    ans-report.fs ansi.fs answords.fs \
161186    colorize.fs comp-i.fs complex.fs \
162187    depth-changes.fs dosekey.fs doskey.fs ds2texi.fs \
...... 
181206    add.fs lib.fs oldlib.fs sieve.fs \
182207    endtry-iferror.fs recover-endtry.fs
183208
184FS_INSTALL_DIR=/usr/share/gforth/$(PKG_VERSION)
209GFORTH_BIN = gforth gforth-fast gforthmi
210
211GFORTH_SHARE_DIR = /usr/share/gforth/$(PKG_VERSION)
212GFORTH_LIB_DIR = /usr/lib/gforth/$(PKG_VERSION)
213GFORTH_BIN_DIR = /usr/bin
185214
215## Select files for package. Note how we rename the GForth kernel image to
216## 'kernel.fi' here, so that 'postinst' can refer to it without depending on
217## architecture-specific naming.
186218define Package/gforth/install
187    $(INSTALL_DIR) $(1)/usr/bin
188    $(INSTALL_DIR) $(1)/usr/lib/gforth
189    $(INSTALL_DIR) $(1)/$(FS_INSTALL_DIR)
190    $(INSTALL_DIR) $(1)/usr/share/gforth/site-forth
191    $(INSTALL_BIN) $(PKG_BUILD_DIR)/gforth-fast $(1)/usr/bin/gforth-fast-bin
192    $(INSTALL_BIN) $(PKG_BUILD_DIR)/gforth $(1)/usr/bin/gforth-bin
193    $(INSTALL_BIN) files/gforth $(1)/usr/bin/gforth
194    $(INSTALL_BIN) files/gforth $(1)/usr/bin/gforth-fast
195    $(INSTALL_DATA) $(PKG_BUILD_DIR)/kernl32l.fi $(1)/$(FS_INSTALL_DIR)
196    $(INSTALL_DATA) $(PKG_BUILD_DIR)/siteinit.fs $(1)/usr/share/gforth/site-forth
197    $(call pkg_install_files,$(FORTH_SRC),$(PKG_BUILD_DIR),$(1)/$(FS_INSTALL_DIR))
219    $(INSTALL_DIR) $(1)/$(GFORTH_BIN_DIR)
220    $(INSTALL_DIR) $(1)/$(GFORTH_SHARE_DIR)
221    $(INSTALL_DIR) $(1)/$(GFORTH_LIB_DIR)
222    $(INSTALL_DIR) $(1)/$(GFORTH_SHARE_DIR)/../site-forth
223    $(INSTALL_DATA) $(PKG_BUILD_DIR)/$$$$(cat $(PKG_BUILD_DIR)/kernel_fi) $(1)/$(GFORTH_SHARE_DIR)/kernel.fi
224    $(INSTALL_BIN) $(PKG_BUILD_DIR)/gforth-ditc $(1)/$(GFORTH_LIB_DIR)/
225    $(INSTALL_DATA) $(PKG_BUILD_DIR)/siteinit.fs $(1)/$(GFORTH_SHARE_DIR)/../site-forth/
226    $(call pkg_install_bin,$(GFORTH_BIN),$(PKG_BUILD_DIR),$(1)/$(GFORTH_BIN_DIR))
227    $(call pkg_install_files,$(GFORTH_SRC),$(PKG_BUILD_DIR),$(1)/$(GFORTH_SHARE_DIR))
228endef
229
230FORTHKFLAGS= --die-on-signal -i kernel.fi
231
232## Directly after installation load the source once and generate a
233## corresponding interpreter image. GForth needs that for quick startup.
234define Package/gforth/postinst
235#! /bin/sh
236echo "Creating GForth interpreter image..."
237export GFORTH="$(GFORTH_BIN_DIR)/gforth $(FORTHSIZES) $(FORTHKFLAGS) $(STARTUP)"
238gforthmi $(GFORTH_LIB_DIR)/gforth.fi $(FORTHSIZES) $(FORTHKFLAGS) $(STARTUP)
239endef
240
241define Package/gforth/prerm
242#! /bin/sh
243rm -f $(GFORTH_LIB_DIR)/gforth.fi
198244endef
199245
200246$(eval $(call HostBuild))
gforth/files/gforth
1#! /bin/sh
2# Can't cross-build gforth.fi image file. Instead load sources on startup.
3exec $0-bin -m 1M -i kernl32l.fi \
4     exboot.fs startup.fs arch/mips/asm.fs arch/mips/disasm.fs "$@"

Archive Download the corresponding diff file



interactive