Root/gforth/Makefile

Source at commit 1b3135c created 8 years 11 months ago.
By Xiangfu Liu, new package: SDL-widgets: a GUI toolkit on top of the SDL libraries
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    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
70
71define Host/Configure
72    $(call Host/Configure/Default)
73endef
74
75## On the host, we only compile and install minimum number of gforth
76## components
77define Host/Compile
78    export LD_LIBRARY_PATH=$(STAGING_DIR_HOST)/lib; \
79    $(call Host/Compile/Default, gforth gforth.fi)
80endef
81
82define Host/Install
83    export LD_LIBRARY_PATH=$(STAGING_DIR_HOST)/lib; \
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/
88endef
89
90## Configuration of the target gforth (see also gforth-update-image.in!)
91FORTHSIZES=--dictionary-size=1M \
92    --data-stack-size=16k \
93    --fp-stack-size=16k \
94    --return-stack-size=16k \
95    --locals-stack-size=16k
96
97CONFIGURE_VARS += FORTHSIZES="$(FORTHSIZES)"
98PKG_BUILD_LIBCC_DIR = $(PKG_BUILD_DIR)/lib/gforth/$(PKG_VERSION)/libcc-named/
99CROSS_PREFORTH = $(PKG_BUILD_DIR)/preforth
100LIBCC_BUILD_SRC = cstr.fs unix/socket.fs
101MAKE_VARS += libccdir=$(GFORTH_LIBCC_DIR)
102
103## Here we call configure, then patch the cross-GForth source tree to replace
104## the 'preforth' script with a script that calls our host-compiled GForth.
105## We also extract the name of the GForth kernel image used for the target
106## architecture, and the source files used by GForth for implementing the
107## assembler/disassembler for the target architecture.
108define Build/Configure
109    $(call Build/Configure/Default,)
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
114    echo "#!/bin/sh" > $(CROSS_PREFORTH).in
115    echo "export LD_LIBRARY_PATH=$(STAGING_DIR_HOST)/lib;" >> $(CROSS_PREFORTH).in
116    echo '$(STAGING_DIR_HOST)/bin/gforth -i $(STAGING_DIR_HOST)/lib/gforth.fi "$$$$@"' >> $(CROSS_PREFORTH).in
117    chmod a+x $(PKG_BUILD_DIR)/preforth.in
118    cp $(CROSS_PREFORTH).in $(CROSS_PREFORTH)
119endef
120
121## Forth code snippet used for pre-compiling Gforth's libcc based C-interface
122## wrappers on the host, so they can be used on the target. Use $(call) to
123## substitute $(1) with a list of Gforth's interface definition files (such as
124## 'cstr.fs' etc).
125define GforthLibccCompile
126   s" $(PKG_BUILD_LIBCC_DIR)" libcc-named-dir-v 2! \
127   libcc-path clear-path \
128   libcc-named-dir libcc-path also-path \
129   :noname 2drop s" $(GFORTH_LIBCC_DIR)" ; is replace-rpath \
130   : end-c-library try end-c-library endtry-iferror then ; \
131   $(1:%=include $(PKG_BUILD_DIR)/%) \
132   bye
133endef
134
135## Compilation is pretty manual to only build the parts we need. By default
136## the GForth Makefile attempts to auto-tune by recursively calling itself for
137## compilation, then running the GForth binary through unit-tests. This won't
138## work with a cross-compile environment.
139##
140## Todo: we currently always build the -ll-reg version of the engine. On
141## 64-bit architectures this might not work? Damn it, why is the check for
142## 'long long' in the Gforth Makefile, not the configure script?
143## Todo: develop a clean upstream patch to configure/Makefile
144define Build/Compile
145    $(call Build/Compile/Default,kernel/version.fs gforth-ditc \
146        engine/prim-fast.i engine/prim_lab-fast.i engine/prim_names-fast.i \
147        engine/prim_superend-fast.i engine/profile-fast.i \
148        engine/prim_num-fast.i engine/prim_grp-fast.i \
149        engine/costs-fast.i engine/super2-fast.i)
150    $(call Build/Compile/Default, -C $(PKG_BUILD_DIR)/engine \
151        gforth-fast-ll-reg gforth-ll-reg \
152        OPT=-ll-reg OPTDEFINES="-DFORCE_LL -DFORCE_REG" OPTOBJECTS=)
153
154    cp $(PKG_BUILD_DIR)/engine/gforth-ll-reg \
155        $(PKG_BUILD_DIR)/gforth
156    cp $(PKG_BUILD_DIR)/engine/gforth-fast-ll-reg \
157        $(PKG_BUILD_DIR)/gforth-fast
158
159    rm -rf $(PKG_BUILD_DIR)/lib/gforth/$(PKG_VERSION)/libcc-named/
160    export includedir=$(PKG_BUILD_DIR)/include; \
161    $(PKG_BUILD_DIR)/preforth $(PKG_BUILD_DIR)/envos.fs \
162        $(PKG_BUILD_DIR)/libcc.fs \
163         -e '$(call GforthLibccCompile,$(LIBCC_BUILD_SRC))'
164endef
165
166##
167## define lists of GForth's sources to package for loading in the target system
168##
169
170GFORTH_FI_SRC = \
171    assert.fs \
172    backtrac.fs \
173    blocked.fb \
174    blocks.fs \
175    bufio.fs \
176    code.fs \
177    debug.fs \
178    debugs.fs \
179    dis-gdb.fs \
180    ekey.fs \
181    envos.fs \
182    savesys.fs \
183    environ.fs \
184    errors.fs \
185    exboot.fs \
186    except.fs \
187    extend.fs \
188    float.fs \
189    glocals.fs \
190    hash.fs \
191    history.fs \
192    intcomp.fs \
193    mkdir.fs \
194    libcc.fs \
195    locals.fs \
196    look.fs \
197    mkdir.fs \
198    prelude.fs \
199    quotes.fs \
200    search.fs \
201    see.fs \
202    see-ext.fs \
203    simp-see.fs \
204    source.fs \
205    startup.fs \
206    struct.fs \
207    struct0x.fs \
208    stuff.fs \
209    tasker.fs \
210    termsize.fs \
211    utf-8.fs \
212    vt100.fs \
213    vt100key.fs \
214    wordinfo.fs \
215    arch/386/asm.fs arch/386/disasm.fs \
216    arch/amd64/asm.fs arch/amd64/disasm.fs \
217    arch/alpha/asm.fs arch/alpha/disasm.fs arch/alpha/testasm.fs\
218    arch/arm/asm.fs arch/arm/disasm.fs \
219    arch/arm/testdisasm.fs arch/arm/testdisasm.out arch/arm/Makefile \
220    arch/mips/asm.fs arch/mips/disasm.fs arch/mips/insts.fs \
221    arch/mips/testasm.fs arch/mips/testdisasm.fs \
222    arch/power/asm.fs arch/power/disasm.fs arch/power/inst.fs
223
224LIBCC_SRC = cstr.fs unix/socket.fs
225LIBCC_DIST_SRC = libffi.fs fflib.fs $(LIBCC_SRC)
226
227# todo: strip down (really?)
228GFORTH_SRC = $(GFORTH_FI_SRC) $(LIBCC_DIST_SRC) \
229    ans-report.fs ansi.fs answords.fs \
230    colorize.fs comp-i.fs complex.fs \
231    depth-changes.fs dosekey.fs doskey.fs ds2texi.fs \
232    envos.dos envos.os2 etags.fs fft.fs filedump.fs fi2c.fs \
233    fsl-util.4th glosgen.fs gray.fs httpd.fs install-tags.fs \
234    make-app.fs doc/makedoc.fs locate.fs more.fs onebench.fs \
235    other.fs prims2x.fs prims2x0.6.2.fs proxy.fs random.fs \
236    regexp.fs sokoban.fs string.fs table.fs tags.fs \
237    tt.fs \
238    unbuffer.fs wordsets.fs xwords.fs \
239    test/tester.fs test/ttester.fs \
240    test/coretest.fs test/postpone.fs test/dbltest.fs \
241    test/string.fs test/float.fs test/search.fs test/gforth.fs \
242    test/other.fs test/signals.fs test/checkans.fs \
243    test/primtest.fs test/coreext.fs test/deferred.fs \
244    test/coremore.fs test/gforth-nofast.fs test/libcc.fs \
245    test/macros.fs \
246    compat/strcomp.fs \
247    bubble.fs siev.fs matrix.fs fib.fs \
248    oof.fs oofsampl.fs objects.fs objexamp.fs mini-oof.fs moof-exm.fs \
249    moofglos.fs fixpath.fs \
250    add.fs lib.fs oldlib.fs sieve.fs \
251    endtry-iferror.fs recover-endtry.fs
252
253GFORTH_SHARE_DIR = /usr/share/gforth/$(PKG_VERSION)
254GFORTH_LIB_DIR = /usr/lib/gforth/$(PKG_VERSION)
255GFORTH_LIBCC_DIR = $(GFORTH_LIB_DIR)/libcc-named
256GFORTH_BIN_DIR = /usr/bin
257GFORTH_WRAPPED_BIN = gforth gforth-fast
258
259## Select files for package. Note how we rename the GForth kernel image to
260## 'kernel.fi' here, so that 'postinst' can refer to it without depending on
261## architecture-specific naming.
262define Package/gforth/install
263        # create directories
264    $(INSTALL_DIR) $(1)/$(GFORTH_BIN_DIR)
265    $(INSTALL_DIR) $(1)/$(GFORTH_SHARE_DIR)
266    $(INSTALL_DIR) $(1)/$(GFORTH_LIB_DIR)
267    $(INSTALL_DIR) $(1)/$(GFORTH_LIBCC_DIR)
268    $(INSTALL_DIR) $(1)/$(GFORTH_SHARE_DIR)/../site-forth
269
270        # install low-level gforth binaries (for image generation)
271    $(INSTALL_BIN) $(PKG_BUILD_DIR)/gforth-ditc $(1)/$(GFORTH_LIB_DIR)/
272    $(INSTALL_BIN) $(PKG_BUILD_DIR)/gforthmi $(1)/$(GFORTH_BIN_DIR)/
273
274        # Install (empty) site-init script
275    $(INSTALL_DATA) $(PKG_BUILD_DIR)/siteinit.fs \
276        $(1)/$(GFORTH_SHARE_DIR)/../site-forth/
277
278        # install the correct Gforth kernel image
279    echo "$(INSTALL_DATA) $(PKG_BUILD_DIR)/@kernel_fi@ $(1)/$(GFORTH_SHARE_DIR)/" > $(PKG_BUILD_DIR)/install-kernel.sh.in
280    cd $(PKG_BUILD_DIR) && ./config.status --file install-kernel.sh
281    . $(PKG_BUILD_DIR)/install-kernel.sh
282
283        # install updating script and wrap gforth interpreter binaries so that
284        # image is generated on first attempt to run the interpreter.
285    $(call pkg_install_bin, \
286        gforth-wrapper gforth-update-image, \
287        $(PKG_BUILD_DIR),$(1)/$(GFORTH_BIN_DIR))
288    for i in $(GFORTH_WRAPPED_BIN); do \
289      ln -sf gforth-wrapper $(1)/$(GFORTH_BIN_DIR)/$$$$i; \
290      $(INSTALL_BIN) $(PKG_BUILD_DIR)/$$$$i \
291        $(1)/$(GFORTH_BIN_DIR)/$$$$i.real; \
292    done
293
294        # install Gforth sources (for generating gforth.fi)
295    $(call pkg_install_files, \
296        $(GFORTH_SRC), \
297        $(PKG_BUILD_DIR), \
298        $(1)/$(GFORTH_SHARE_DIR))
299
300        # install pre-generated C-interface wrappers (libcc)
301    -for i in $(LIBCC_BUILD_SRC); do \
302          which libtool; \
303      ls -l $(PKG_BUILD_LIBCC_DIR)/.libs; \
304      libtool --mode=install $(INSTALL_DATA) \
305        $(PKG_BUILD_LIBCC_DIR)/`basename $$$$i .fs`.la \
306        $(1)/$(GFORTH_LIBCC_DIR)/; \
307        ls -l $(1)/$(GFORTH_LIBCC_DIR)/; \
308    done
309# -libtool --finish $(1)/$(GFORTH_LIBCC_DIR)
310    -rm -f $(1)/$(GFORTH_LIBCC_DIR)/*.a
311endef
312
313## Directly after installation generate updated interpreter image from
314## installed source code.
315define Package/gforth/postinst
316#! /bin/sh
317if [ -z "$$IPKG_OFFLINE_ROOT" ]; then
318    # only attempt to update image on target, never on host
319    $(GFORTH_BIN_DIR)/gforth-update-image
320fi
321endef
322
323define Package/gforth/prerm
324#! /bin/sh
325if [ -z "$$IPKG_OFFLINE_ROOT" ]; then
326    rm -f $(GFORTH_LIB_DIR)/gforth.fi
327fi
328endef
329
330$(eval $(call HostBuild))
331$(eval $(call BuildPackage,gforth))
332
333# The following comments configure the Emacs editor. Just ignore them.
334# Local Variables:
335# compile-command: "make -C ~/h/src/qi/openwrt-xburst package/gforth/compile -j2 V=99"
336# End:
337

Archive Download this file



interactive