~ chicken-core (master) /manual/Deployment
Trap1[[tags: manual]]
2[[toc:]]
3
4
5== Deployment
6
7CHICKEN generates fully native binaries that can be distributed like
8normal C/C++ programs. There are various methods of deployment,
9depending on platform, linkage, external dependencies and whether
10the application should be built from sources or precompiled and
11whether the CHICKEN runtime-libraries are expected on the destination
12system or if the application should be completely self-contained.
13
14There are several options for distributing software written in CHICKEN for
15use on other machines or by other people:
16
17* Distribute source code, which requires that the target system has a compatible version of CHICKEN installed
18* Distribute C files generated from Scheme source code and compile them to binaries on the target system - this also requires a matching CHICKEN installation on the target
19* Distribute compiled binaries, either statically linked or built in such a way that all required extensions and libraries are included in the distribution
20
21The rest of this chapter addresses the third option, for which several options exist,
22depending on your needs and how self-contained you want your deployed
23binary to be.
24
25The simplest form of deployment is the single executable. The runtime
26library ({{libchicken.so}}, {{libchicken.dylib}} or {{libchicken.dll}}) is required for these
27programs to run, unless you link your application statically:
28
29 % csc myprogram.scm
30 % ldd myprogram # on linux
31 linux-gate.so.1 => (0xb805c000)
32 libchicken.so.9 => /home/felix/chicken/core/lib/libchicken.so.9 (0xb7c22000)
33 libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb7bec000)
34 libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb7be7000)
35 libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7a84000)
36 /lib/ld-linux.so.2 (0xb805d000)
37 % ls -l myprogram
38 -rwxr-xr-x 1 felix felix 34839 2010-02-22 20:19 x
39
40=== Static linking
41
42Linking your application statically will include the runtime library in the executable:
43
44 % csc -static myprogram.scm
45 % ldd myprogram
46 linux-gate.so.1 => (0xb805c000)
47 libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb7bec000)
48 libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb7be7000)
49 libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7a84000)
50 /lib/ld-linux.so.2 (0xb805d000)
51
52[[Extensions]] are transparently linked in statically, if you provide the {{-static}}
53option to {{csc}}, provided the extension is avaiable as a static object file
54(this applies to most extensions by default).
55
56=== Shipping the runtime library
57
58An alternate way of distributing compiled code is to ship the runtime library
59{{libchicken.so}} together with the executable, possibly including any extensions
60that you use. To make this work, any runtime linker paths compiled into
61binary objects need to be deleted or changed by using a tool like {{chrpath(1)}}
62or {{patchelf(1)}}, to a value that indicates that
63the library lookup should start in the same location as the main program.
64(e.g. {{$ORIGIN}} on Linux). Don't forget to copy any extensions from the
65extension repository ({{$PREFIX/lib/chicken/$BINARYVERSION}}).
66
67Alternatively start your program through a separate
68script that sets {{LD_LIBRARY_PATH}} (or {{DYLD_LIBRARY_PATH}} on
69MacOS X).
70For more details, consult
71the documentation of the operating system that you use to build your
72deployed binaries.
73
74A directory containing all binaries is fully "portable" in the sense that it will run directly
75from an USB-stick or any other removable media. At runtime the program can find
76out its location by invoking the {{repository-path}} procedure, which will return
77the full pathname in which the application is located.
78
79Should the program depend on more libraries which are not available by
80default on the intended target systems, and which you would like to
81include in your application, you will have to track them down yourself
82and place them in the application directory.
83
84=== Distributing compiled C files
85
86It is possible to create distributions of Scheme projects that
87have been compiled to C. The runtime system of CHICKEN consists of only
88two handcoded C files ({{runtime.c}} and {{chicken.h}}), plus the files
89{{chicken-config.h}} and {{buildtag.h}}, which are generated by the
90build process. All other modules of the runtime system and the extension
91libraries are just compiled Scheme code. The following example shows a
92minimal application, which should run without changes on most operating
93systems, like Windows, Linux or FreeBSD (note however that static
94binaries are not supported on Mac OS X).
95
96Take the following "Hello World" program:
97
98<enscript highlight=scheme>
99; hello.scm
100
101(print "Hello, world!")
102</enscript>
103
104 % csc -t hello.scm -optimize-level 3 -output-file hello.c
105
106Compiled to C, we get {{hello.c}}. We need the files {{chicken.h}},
107{{chicken-config.h}}, {{buildtag.h}} and {{runtime.c}}, which contain
108the basic runtime system, plus the library files {{build-version.c}},
109{{chicken-syntax.c}}, {{eval.c}}, {{expand.c}}, {{internal.c}},
110{{library.c}} and {{modules.c}}, which contain the same functionality as
111the library that is linked into plain CHICKEN-compiled applications:
112
113 % cd /tmp
114 % echo '(print "Hello World.")' > hello.scm
115 % csc -t hello.scm
116 % cp $CHICKEN_BUILD/build-version.c .
117 % cp $CHICKEN_BUILD/chicken-syntax.c .
118 % cp $CHICKEN_BUILD/eval.c .
119 % cp $CHICKEN_BUILD/expand.c .
120 % cp $CHICKEN_BUILD/internal.c .
121 % cp $CHICKEN_BUILD/library.c .
122 % cp $CHICKEN_BUILD/modules.c .
123 % cp $CHICKEN_BUILD/runtime.c .
124 % cp $CHICKEN_BUILD/utf.c .
125 % cp $CHICKEN_BUILD/chicken.h .
126 % cp $CHICKEN_BUILD/chicken-config.h .
127 % cp $CHICKEN_BUILD/buildtag.h .
128 % gcc -Os -fomit-frame-pointer -DHAVE_CHICKEN_CONFIG_H hello.c \
129 build-version.c chicken-syntax.c eval.c expand.c internal.c \
130 library.c modules.c runtime.c \
131 -o hello -lm
132
133Once we have all the files together, we can create a tarball:
134
135 % tar czf hello.tar.gz hello.c build-version.c chicken-syntax.c eval.c \
136 expand.c internal.c library.c modules.c runtime.c utf.c chicken.h \
137 chicken-config.h buildtag.h
138
139This is naturally rather simplistic. Things like enabling dynamic
140loading and selecting supported features of the host system would need
141more configuration- and build-time support. All this can be addressed
142using more elaborate build-scripts, makefiles or by using
143autoconf/automake.
144
145The {{chicken-config.h}} file may contain incorrect settings for your
146deployment target. Especially when the architecture is different. In
147that case you will have to adjust the values as needed.
148
149For more information, study the CHICKEN source code and/or ask on the CHICKEN
150mailing lists to understand the implications and difficulties of this deployment
151method in more detail.
152
153=== Platform specific notes
154
155==== Windows
156
157Deployment is fully supported on Windows. Since Windows looks up
158dynamic link libraries in the programs original location by default,
159adding third-party libraries to the application directory is no
160problem. The freely available [[http://dependencywalker.com|Dependency
161Walker]] tool is helpful to find out what DLLs your application
162depends on.
163
164==== MacOS X
165
166The {{otool(1)}} program will show you dynamic libraries that your
167application requires. {{DYLD_LIBRARY_PATH}}
168can be set to override runtime linker paths and {{install_name_tool(1)}}
169is available to patch runtime linker paths directly. All of these tools
170require the Xcode command-line tools too be installed.
171
172
173---
174Previous: [[Units and linking model]]
175
176Next: [[Cross development]]