Root/gforth/Makefile

Source at commit d50d5ae0f3ff3ba07dc50d723eb1399035bb4429 created 1 year 9 months ago.
By David Kühling, switch to newer upstream snapshot with improved MIPS support.
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=20100807
20PKG_VERSION=0.7.0-$(PKG_SNAPSHOT_DATE)
21PKG_RELEASE:=4
22
23
24PKG_BUILD_DEPENDS:= gforth/host libltdl/host
25PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
26PKG_FIXUP:=libtool
27
28PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
29PKG_SOURCE_URL:=\
30    http://user.cs.tu-berlin.de/~dvdkhlng/ \
31    http://mosquito.dyndns.tv/~spock/
32#PKG_SOURCE_URL:= file://~/forth/gforth/
33PKG_MD5SUM:=fb1d0dee4836dab57fd3eadbd5fc1922
34
35# Alternate download #1 via CVS: this doesn't work, as CVS is missing the
36# kernel.fi images needed for boot-strapping :(
37# PKG_SOURCE_PROTO:=cvs
38# PKG_SOURCE_VERSION="-D$(PKG_SNAPSHOT_DATE) 23:59"
39# PKG_SOURCE_URL=:pserver:anonymous@c1.complang.tuwien.ac.at:/nfs/unsafe/cvs-repository/src-master
40# PKG_SOURCE_SUBDIR:=gforth
41# PKG_SOURCE:=gforth-$(PKG_SNAPSHOT_DATE).tar.gz
42
43include $(INCLUDE_DIR)/host-build.mk
44include $(INCLUDE_DIR)/package.mk
45
46define Package/gforth
47  SECTION:=lang
48  CATEGORY:=Languages
49  TITLE:=GForth
50  DEPENDS:= +libltdl
51  URL:=http://www.gnu.org/software/gforth/
52endef
53
54define Package/gforth/description
55  Gforth is a fast and portable implementation of the ANS Forth
56  language.
57endef
58
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
65## The host-GForth uses -ltdl to link against the staging dir version of
66## libltdl. However, when the host-GForth runs, it won't find that library,
67## as no library path is encoded into the ltdl dependency (why?). So here we
68## override LD_LIBRARY_PATH for all the build steps that might run the
69## host-GForth.
70
71define Host/Configure
72    export LD_LIBRARY_PATH=$(STAGING_DIR_HOST)/lib; \
73    $(call Host/Configure/Default)
74endef
75
76define Host/Compile
77    export LD_LIBRARY_PATH=$(STAGING_DIR_HOST)/lib; \
78    $(call Host/Compile/Default)
79endef
80
81define Host/Install
82    export LD_LIBRARY_PATH=$(STAGING_DIR_HOST)/lib; \
83    $(call Host/Install/Default)
84endef
85
86## Configuration of the target gforth
87FORTHSIZES=--dictionary-size=1M \
88    --data-stack-size=16k \
89    --fp-stack-size=16k \
90    --return-stack-size=16k \
91    --locals-stack-size=16k
92
93CONFIGURE_VARS += FORTHSIZES="$(FORTHSIZES)"
94
95CROSS_PREFORTH = $(PKG_BUILD_DIR)/preforth
96
97## Here we call configure, then patch the cross-GForth source tree to replace
98## the 'preforth' script with a script that calls our host-compiled GForth.
99## We also extract the name of the GForth kernel image used for the target
100## architecture, and the source files used by GForth for implementing the
101## assembler/disassembler for the target architecture.
102define Build/Configure
103    $(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
108    echo "#!/bin/sh" > $(CROSS_PREFORTH)
109    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)
111    chmod a+x $(PKG_BUILD_DIR)/preforth
112endef
113
114## Compilation is pretty manual to only build the parts we need. By default
115## the GForth Makefile attempts to auto-tune by recursively calling itself for
116## compilation, then running the GForth binary through unit-tests. This won't
117## work with a cross-compile environment.
118##
119## Todo: we currently always build the -ll-reg version of the engine. On
120## 64-bit architectures this might not work? Damn it, why is the check for
121## 'long long' in the Gforth Makefile, not the configure script?
122## Todo: develop a clean upstream patch to configure/Makefile
123define Build/Compile
124    $(MAKE) -C $(PKG_BUILD_DIR) kernel/version.fs gforth-ditc \
125        engine/prim-fast.i engine/prim_lab-fast.i engine/prim_names-fast.i \
126        engine/prim_superend-fast.i engine/profile-fast.i \
127        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
134endef
135
136##
137## define lists of GForth's sources to package for loading in the target system
138##
139
140GFORTH_FI_SRC = \
141    assert.fs \
142    backtrac.fs \
143    blocked.fb \
144    blocks.fs \
145    bufio.fs \
146    code.fs \
147    debug.fs \
148    debugs.fs \
149    dis-gdb.fs \
150    ekey.fs \
151    envos.fs \
152    savesys.fs \
153    environ.fs \
154    errors.fs \
155    exboot.fs \
156    except.fs \
157    extend.fs \
158    float.fs \
159    glocals.fs \
160    hash.fs \
161    history.fs \
162    intcomp.fs \
163    mkdir.fs \
164    libcc.fs \
165    locals.fs \
166    look.fs \
167    mkdir.fs \
168    prelude.fs \
169    quotes.fs \
170    search.fs \
171    see.fs \
172    see-ext.fs \
173    simp-see.fs \
174    source.fs \
175    startup.fs \
176    struct.fs \
177    struct0x.fs \
178    stuff.fs \
179    tasker.fs \
180    termsize.fs \
181    utf-8.fs \
182    vt100.fs \
183    vt100key.fs \
184    wordinfo.fs \
185    arch/386/asm.fs arch/386/disasm.fs \
186    arch/amd64/asm.fs arch/amd64/disasm.fs \
187    arch/alpha/asm.fs arch/alpha/disasm.fs arch/alpha/testasm.fs\
188    arch/arm/asm.fs arch/arm/disasm.fs \
189    arch/arm/testdisasm.fs arch/arm/testdisasm.out arch/arm/Makefile \
190    arch/mips/asm.fs arch/mips/disasm.fs arch/mips/insts.fs \
191    arch/mips/testasm.fs arch/mips/testdisasm.fs \
192    arch/power/asm.fs arch/power/disasm.fs arch/power/inst.fs
193
194LIBCC_SRC = cstr.fs unix/socket.fs
195LIBCC_DIST_SRC = libffi.fs fflib.fs $(LIBCC_SRC)
196
197# todo: strip down (really?)
198GFORTH_SRC = $(GFORTH_FI_SRC) $(LIBCC_DIST_SRC) \
199    ans-report.fs ansi.fs answords.fs \
200    colorize.fs comp-i.fs complex.fs \
201    depth-changes.fs dosekey.fs doskey.fs ds2texi.fs \
202    envos.dos envos.os2 etags.fs fft.fs filedump.fs fi2c.fs \
203    fsl-util.4th glosgen.fs gray.fs httpd.fs install-tags.fs \
204    make-app.fs doc/makedoc.fs locate.fs more.fs onebench.fs \
205    other.fs prims2x.fs prims2x0.6.2.fs proxy.fs random.fs \
206    regexp.fs sokoban.fs string.fs table.fs tags.fs \
207    tt.fs \
208    unbuffer.fs wordsets.fs xwords.fs \
209    test/tester.fs test/ttester.fs \
210    test/coretest.fs test/postpone.fs test/dbltest.fs \
211    test/string.fs test/float.fs test/search.fs test/gforth.fs \
212    test/other.fs test/signals.fs test/checkans.fs \
213    test/primtest.fs test/coreext.fs test/deferred.fs \
214    test/coremore.fs test/gforth-nofast.fs test/libcc.fs \
215    test/macros.fs \
216    compat/strcomp.fs \
217    bubble.fs siev.fs matrix.fs fib.fs \
218    oof.fs oofsampl.fs objects.fs objexamp.fs mini-oof.fs moof-exm.fs \
219    moofglos.fs fixpath.fs \
220    add.fs lib.fs oldlib.fs sieve.fs \
221    endtry-iferror.fs recover-endtry.fs
222
223GFORTH_BIN = gforth gforth-fast gforthmi
224
225GFORTH_SHARE_DIR = /usr/share/gforth/$(PKG_VERSION)
226GFORTH_LIB_DIR = /usr/lib/gforth/$(PKG_VERSION)
227GFORTH_BIN_DIR = /usr/bin
228
229## Select files for package. Note how we rename the GForth kernel image to
230## 'kernel.fi' here, so that 'postinst' can refer to it without depending on
231## architecture-specific naming.
232define Package/gforth/install
233    $(INSTALL_DIR) $(1)/$(GFORTH_BIN_DIR)
234    $(INSTALL_DIR) $(1)/$(GFORTH_SHARE_DIR)
235    $(INSTALL_DIR) $(1)/$(GFORTH_LIB_DIR)
236    $(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
238    $(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))
242endef
243
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.
254define Package/gforth/postinst
255#! /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)
259endef
260
261define Package/gforth/prerm
262#! /bin/sh
263rm -f $(GFORTH_LIB_DIR)/gforth.fi
264endef
265
266$(eval $(call HostBuild))
267$(eval $(call BuildPackage,gforth))
268
269# The following comments configure the Emacs editor. Just ignore them.
270# Local Variables:
271# compile-command: "make -C ~/h/src/qi/openwrt-xburst package/gforth/compile -j2 V=99"
272# End:
273

Archive Download this file



interactive