OpenWrt packages
Sign in or create your account | Project List | Help
OpenWrt packages Commit Details
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 | ||
---|---|---|
16 | 16 | include $(TOPDIR)/rules.mk |
17 | 17 | |
18 | 18 | PKG_NAME:=gforth |
19 | PKG_SNAPSHOT_DATE=2010913 | |
19 | PKG_SNAPSHOT_DATE=20100918 | |
20 | 20 | PKG_VERSION=0.7.0-$(PKG_SNAPSHOT_DATE) |
21 | PKG_RELEASE:=4 | |
21 | PKG_RELEASE:=1 | |
22 | 22 | |
23 | ||
24 | PKG_BUILD_DEPENDS:= gforth/host libltdl/host | |
23 | PKG_BUILD_DEPENDS:= gforth/host libltdl/host libtool/host libffi | |
25 | 24 | PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) |
26 | 25 | PKG_FIXUP:=libtool |
27 | 26 | |
... | ... | |
30 | 29 | http://user.cs.tu-berlin.de/~dvdkhlng/ \ |
31 | 30 | http://mosquito.dyndns.tv/~spock/ |
32 | 31 | #PKG_SOURCE_URL:= file://~/forth/gforth/ |
33 | PKG_MD5SUM:=4b52f42aac9c78121dedeca7aa998b37 | |
32 | PKG_MD5SUM:=f912b58c2434a9e1df7d4f8db75636da | |
34 | 33 | |
35 | 34 | # Alternate download #1 via CVS: this doesn't work, as CVS is missing the |
36 | 35 | # kernel.fi images needed for boot-strapping :( |
... | ... | |
56 | 55 | language. |
57 | 56 | endef |
58 | 57 | |
59 | HOST_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 | |
63 | EXTRA_CFLAGS += -O2 | |
64 | ||
65 | 58 | ## The host-GForth uses -ltdl to link against the staging dir version of |
66 | 59 | ## libltdl. However, when the host-GForth runs, it won't find that library, |
67 | 60 | ## as no library path is encoded into the ltdl dependency (why?). So here we |
68 | 61 | ## override LD_LIBRARY_PATH for all the build steps that might run the |
69 | 62 | ## host-GForth. |
63 | HOST_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 | |
69 | EXTRA_CFLAGS += -O2 | |
70 | 70 | |
71 | 71 | define Host/Configure |
72 | export LD_LIBRARY_PATH=$(STAGING_DIR_HOST)/lib; \ | |
73 | 72 | $(call Host/Configure/Default) |
74 | 73 | endef |
75 | 74 | |
75 | ## On the host, we only compile and install minimum number of gforth | |
76 | ## components | |
76 | 77 | define Host/Compile |
77 | 78 | export LD_LIBRARY_PATH=$(STAGING_DIR_HOST)/lib; \ |
78 | $(call Host/Compile/Default) | |
79 | $(call Host/Compile/Default, gforth gforth.fi) | |
79 | 80 | endef |
80 | 81 | |
81 | 82 | define Host/Install |
82 | 83 | 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/ | |
84 | 88 | endef |
85 | 89 | |
86 | ## Configuration of the target gforth | |
90 | ## Configuration of the target gforth (see also gforth-update-image.in!) | |
87 | 91 | FORTHSIZES=--dictionary-size=1M \ |
88 | 92 | --data-stack-size=16k \ |
89 | 93 | --fp-stack-size=16k \ |
... | ... | |
91 | 95 | --locals-stack-size=16k |
92 | 96 | |
93 | 97 | CONFIGURE_VARS += FORTHSIZES="$(FORTHSIZES)" |
94 | ||
98 | PKG_BUILD_LIBCC_DIR = $(PKG_BUILD_DIR)/lib/gforth/$(PKG_VERSION)/libcc-named/ | |
95 | 99 | CROSS_PREFORTH = $(PKG_BUILD_DIR)/preforth |
100 | LIBCC_BUILD_SRC = cstr.fs unix/socket.fs | |
101 | MAKE_VARS += libccdir=$(GFORTH_LIBCC_DIR) | |
96 | 102 | |
97 | 103 | ## Here we call configure, then patch the cross-GForth source tree to replace |
98 | 104 | ## the 'preforth' script with a script that calls our host-compiled GForth. |
... | ... | |
101 | 107 | ## assembler/disassembler for the target architecture. |
102 | 108 | define Build/Configure |
103 | 109 | $(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 | |
108 | 114 | echo "#!/bin/sh" > $(CROSS_PREFORTH) |
109 | 115 | 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) | |
111 | 117 | chmod a+x $(PKG_BUILD_DIR)/preforth |
112 | 118 | endef |
113 | 119 | |
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). | |
124 | define 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 | |
132 | endef | |
133 | ||
114 | 134 | ## Compilation is pretty manual to only build the parts we need. By default |
115 | 135 | ## the GForth Makefile attempts to auto-tune by recursively calling itself for |
116 | 136 | ## compilation, then running the GForth binary through unit-tests. This won't |
... | ... | |
121 | 141 | ## 'long long' in the Gforth Makefile, not the configure script? |
122 | 142 | ## Todo: develop a clean upstream patch to configure/Makefile |
123 | 143 | define Build/Compile |
124 | $(MAKE) -C $(PKG_BUILD_DIR) kernel/version.fs gforth-ditc \ | |
144 | $(call Build/Compile/Default,kernel/version.fs gforth-ditc \ | |
125 | 145 | engine/prim-fast.i engine/prim_lab-fast.i engine/prim_names-fast.i \ |
126 | 146 | engine/prim_superend-fast.i engine/profile-fast.i \ |
127 | 147 | 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))' | |
134 | 163 | endef |
135 | 164 | |
136 | 165 | ## |
... | ... | |
220 | 249 | add.fs lib.fs oldlib.fs sieve.fs \ |
221 | 250 | endtry-iferror.fs recover-endtry.fs |
222 | 251 | |
223 | GFORTH_BIN = gforth gforth-fast gforthmi | |
224 | ||
225 | 252 | GFORTH_SHARE_DIR = /usr/share/gforth/$(PKG_VERSION) |
226 | 253 | GFORTH_LIB_DIR = /usr/lib/gforth/$(PKG_VERSION) |
254 | GFORTH_LIBCC_DIR = $(GFORTH_LIB_DIR)/libcc-named | |
227 | 255 | GFORTH_BIN_DIR = /usr/bin |
256 | GFORTH_WRAPPED_BIN = gforth gforth-fast | |
228 | 257 | |
229 | 258 | ## Select files for package. Note how we rename the GForth kernel image to |
230 | 259 | ## 'kernel.fi' here, so that 'postinst' can refer to it without depending on |
231 | 260 | ## architecture-specific naming. |
232 | 261 | define Package/gforth/install |
262 | # create directories | |
233 | 263 | $(INSTALL_DIR) $(1)/$(GFORTH_BIN_DIR) |
234 | 264 | $(INSTALL_DIR) $(1)/$(GFORTH_SHARE_DIR) |
235 | 265 | $(INSTALL_DIR) $(1)/$(GFORTH_LIB_DIR) |
266 | $(INSTALL_DIR) $(1)/$(GFORTH_LIBCC_DIR) | |
236 | 267 | $(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) | |
238 | 270 | $(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 | |
242 | 307 | endef |
243 | 308 | |
244 | FORTHKFLAGS= --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. | |
250 | STARTUP = 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. | |
254 | 311 | define Package/gforth/postinst |
255 | 312 | #! /bin/sh |
256 | echo "Creating GForth interpreter image..." | |
257 | export GFORTH="$(GFORTH_BIN_DIR)/gforth $(FORTHSIZES) $(FORTHKFLAGS) $(STARTUP)" | |
258 | gforthmi $(GFORTH_LIB_DIR)/gforth.fi $(FORTHSIZES) $(FORTHKFLAGS) $(STARTUP) | |
313 | $(GFORTH_BIN_DIR)/gforth-update-image | |
259 | 314 | endef |
260 | 315 | |
261 | 316 | define 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 | |
12 | FORTHSIZES="--dictionary-size=1M \ | |
13 | --data-stack-size=16k \ | |
14 | --fp-stack-size=15872 \ | |
15 | --return-stack-size=15360 \ | |
16 | --locals-stack-size=14848" | |
17 | ||
18 | STARTUP="exboot.fs startup.fs @asm_fs@ @disasm_fs@" | |
19 | ||
20 | FORTHKFLAGS="--die-on-signal -i @kernel_fi@" | |
21 | ||
22 | GFORTH_SHARE_DIR=/usr/share/gforth/@PACKAGE_VERSION@ | |
23 | GFORTH_LIB_DIR=/usr/lib/gforth/@PACKAGE_VERSION@ | |
24 | GFORTH_BIN_DIR=/usr/bin | |
25 | ||
26 | GFORTH_FI=${GFORTH_LIB_DIR}/gforth.fi | |
27 | ||
28 | echo "Creating Gforth interpreter image..." | |
29 | ||
30 | mkdir -p $GFORTH_LIB_DIR | |
31 | ||
32 | check_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 | ||
42 | if ! 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? | |
49 | EOF | |
50 | exec false | |
51 | fi | |
52 | ||
53 | export libccdir=${GFORTH_LIB_DIR}/libcc-named | |
54 | export GFORTH="/usr/bin/gforth.real ${FORTHSIZES} ${FORTHKFLAGS} ${STARTUP}" | |
55 | gforthmi ${GFORTH_FI}.new ${FORTHSIZES} ${FORTHKFLAGS} ${STARTUP} && | |
56 | mv -f ${GFORTH_FI}.new ${GFORTH_FI} | |
57 | exit $? | |
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 | # | |
10 | dirname=$(dirname "$0") | |
11 | binary=$dirname/$(basename "$0").real | |
12 | ||
13 | GFORTH_LIB_DIR=/usr/lib/gforth/@PACKAGE_VERSION@ | |
14 | GFORTH_FI=$GFORTH_LIB_DIR/gforth.fi | |
15 | ||
16 | # try to (re)generate the gforth.fi image file | |
17 | do_update(){ | |
18 | $dirname/gforth-update-image &> /dev/null | |
19 | status=$? | |
20 | [ $status = 0 ] && return 0 | |
21 | ||
22 | cat<<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@ | |
38 | EOF | |
39 | ||
40 | exec false | |
41 | } | |
42 | ||
43 | if ! [ -f "$GFORTH_FI" ]; then | |
44 | do_update | |
45 | fi | |
46 | ||
47 | # if everything is ok, we'll come here and run the actual Gforth executable | |
48 | # (gforth.real, gforth-fast.real etc.) | |
49 | exec "$binary" "$@" | |
50 |