Root/gforth/Makefile

Source at commit 5f81a8dec32cc1f3d450b02cb32fc92e91c04610 created 13 years 7 days ago.
By David Kühling, gforth: bump version number (this version already distributed via release?)
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:=4
22
23PKG_BUILD_DEPENDS:= gforth/host libltdl/host libtool/host 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://user.cs.tu-berlin.de/~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)
115    echo "export LD_LIBRARY_PATH=$(STAGING_DIR_HOST)/lib;" >> $(CROSS_PREFORTH)
116    echo '$(STAGING_DIR_HOST)/bin/gforth -i $(STAGING_DIR_HOST)/lib/gforth.fi "$$$$@"' >> $(CROSS_PREFORTH)
117    chmod a+x $(PKG_BUILD_DIR)/preforth
118endef
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).
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
134## Compilation is pretty manual to only build the parts we need. By default
135## the GForth Makefile attempts to auto-tune by recursively calling itself for
136## compilation, then running the GForth binary through unit-tests. This won't
137## work with a cross-compile environment.
138##
139## Todo: we currently always build the -ll-reg version of the engine. On
140## 64-bit architectures this might not work? Damn it, why is the check for
141## 'long long' in the Gforth Makefile, not the configure script?
142## Todo: develop a clean upstream patch to configure/Makefile
143define Build/Compile
144    $(call Build/Compile/Default,kernel/version.fs gforth-ditc \
145        engine/prim-fast.i engine/prim_lab-fast.i engine/prim_names-fast.i \
146        engine/prim_superend-fast.i engine/profile-fast.i \
147        engine/prim_num-fast.i engine/prim_grp-fast.i \
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))'
163endef
164
165##
166## define lists of GForth's sources to package for loading in the target system
167##
168
169GFORTH_FI_SRC = \
170    assert.fs \
171    backtrac.fs \
172    blocked.fb \
173    blocks.fs \
174    bufio.fs \
175    code.fs \
176    debug.fs \
177    debugs.fs \
178    dis-gdb.fs \
179    ekey.fs \
180    envos.fs \
181    savesys.fs \
182    environ.fs \
183    errors.fs \
184    exboot.fs \
185    except.fs \
186    extend.fs \
187    float.fs \
188    glocals.fs \
189    hash.fs \
190    history.fs \
191    intcomp.fs \
192    mkdir.fs \
193    libcc.fs \
194    locals.fs \
195    look.fs \
196    mkdir.fs \
197    prelude.fs \
198    quotes.fs \
199    search.fs \
200    see.fs \
201    see-ext.fs \
202    simp-see.fs \
203    source.fs \
204    startup.fs \
205    struct.fs \
206    struct0x.fs \
207    stuff.fs \
208    tasker.fs \
209    termsize.fs \
210    utf-8.fs \
211    vt100.fs \
212    vt100key.fs \
213    wordinfo.fs \
214    arch/386/asm.fs arch/386/disasm.fs \
215    arch/amd64/asm.fs arch/amd64/disasm.fs \
216    arch/alpha/asm.fs arch/alpha/disasm.fs arch/alpha/testasm.fs\
217    arch/arm/asm.fs arch/arm/disasm.fs \
218    arch/arm/testdisasm.fs arch/arm/testdisasm.out arch/arm/Makefile \
219    arch/mips/asm.fs arch/mips/disasm.fs arch/mips/insts.fs \
220    arch/mips/testasm.fs arch/mips/testdisasm.fs \
221    arch/power/asm.fs arch/power/disasm.fs arch/power/inst.fs
222
223LIBCC_SRC = cstr.fs unix/socket.fs
224LIBCC_DIST_SRC = libffi.fs fflib.fs $(LIBCC_SRC)
225
226# todo: strip down (really?)
227GFORTH_SRC = $(GFORTH_FI_SRC) $(LIBCC_DIST_SRC) \
228    ans-report.fs ansi.fs answords.fs \
229    colorize.fs comp-i.fs complex.fs \
230    depth-changes.fs dosekey.fs doskey.fs ds2texi.fs \
231    envos.dos envos.os2 etags.fs fft.fs filedump.fs fi2c.fs \
232    fsl-util.4th glosgen.fs gray.fs httpd.fs install-tags.fs \
233    make-app.fs doc/makedoc.fs locate.fs more.fs onebench.fs \
234    other.fs prims2x.fs prims2x0.6.2.fs proxy.fs random.fs \
235    regexp.fs sokoban.fs string.fs table.fs tags.fs \
236    tt.fs \
237    unbuffer.fs wordsets.fs xwords.fs \
238    test/tester.fs test/ttester.fs \
239    test/coretest.fs test/postpone.fs test/dbltest.fs \
240    test/string.fs test/float.fs test/search.fs test/gforth.fs \
241    test/other.fs test/signals.fs test/checkans.fs \
242    test/primtest.fs test/coreext.fs test/deferred.fs \
243    test/coremore.fs test/gforth-nofast.fs test/libcc.fs \
244    test/macros.fs \
245    compat/strcomp.fs \
246    bubble.fs siev.fs matrix.fs fib.fs \
247    oof.fs oofsampl.fs objects.fs objexamp.fs mini-oof.fs moof-exm.fs \
248    moofglos.fs fixpath.fs \
249    add.fs lib.fs oldlib.fs sieve.fs \
250    endtry-iferror.fs recover-endtry.fs
251
252GFORTH_SHARE_DIR = /usr/share/gforth/$(PKG_VERSION)
253GFORTH_LIB_DIR = /usr/lib/gforth/$(PKG_VERSION)
254GFORTH_LIBCC_DIR = $(GFORTH_LIB_DIR)/libcc-named
255GFORTH_BIN_DIR = /usr/bin
256GFORTH_WRAPPED_BIN = gforth gforth-fast
257
258## Select files for package. Note how we rename the GForth kernel image to
259## 'kernel.fi' here, so that 'postinst' can refer to it without depending on
260## architecture-specific naming.
261define Package/gforth/install
262        # create directories
263    $(INSTALL_DIR) $(1)/$(GFORTH_BIN_DIR)
264    $(INSTALL_DIR) $(1)/$(GFORTH_SHARE_DIR)
265    $(INSTALL_DIR) $(1)/$(GFORTH_LIB_DIR)
266    $(INSTALL_DIR) $(1)/$(GFORTH_LIBCC_DIR)
267    $(INSTALL_DIR) $(1)/$(GFORTH_SHARE_DIR)/../site-forth
268
269        # install low-level gforth binaries (for image generation)
270    $(INSTALL_BIN) $(PKG_BUILD_DIR)/gforth-ditc $(1)/$(GFORTH_LIB_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    cd $(PKG_BUILD_DIR) && ./config.status --file 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          which libtool; \
302      ls -l $(PKG_BUILD_LIBCC_DIR)/.libs; \
303      libtool --mode=install $(INSTALL_DATA) \
304        $(PKG_BUILD_LIBCC_DIR)/`basename $$$$i .fs`.la \
305        $(1)/$(GFORTH_LIBCC_DIR)/; \
306        ls -l $(1)/$(GFORTH_LIBCC_DIR)/; \
307    done
308# -libtool --finish $(1)/$(GFORTH_LIBCC_DIR)
309    -rm -f $(1)/$(GFORTH_LIBCC_DIR)/*.a
310endef
311
312## Directly after installation generate updated interpreter image from
313## installed source code.
314define Package/gforth/postinst
315#! /bin/sh
316if [ -z "$$IPKG_OFFLINE_ROOT" ]; then
317    # only attempt to update image on target, never on host
318    $(GFORTH_BIN_DIR)/gforth-update-image
319fi
320endef
321
322define Package/gforth/prerm
323#! /bin/sh
324if [ -z "$$IPKG_OFFLINE_ROOT" ]; then
325    rm -f $(GFORTH_LIB_DIR)/gforth.fi
326fi
327endef
328
329$(eval $(call HostBuild))
330$(eval $(call BuildPackage,gforth))
331
332# The following comments configure the Emacs editor. Just ignore them.
333# Local Variables:
334# compile-command: "make -C ~/h/src/qi/openwrt-xburst package/gforth/compile -j2 V=99"
335# End:
336

Archive Download this file



interactive