1 HelenOS coastline: build POSIX applications for HelenOS
2 =======================================================
4 This repository contains scripts that should simplify porting POSIX
5 applications to run in `HelenOS <http://www.helenos.org>`_.
6 The motivation for this mini-project is that porting GNU/POSIX applications
7 to HelenOS is mostly about setting correctly the CFLAGS when running
8 ``./configure`` and then copying the generated executables somewhere to
10 The idea is that this procedure would be recorded in a form of a simple shell
11 script, called harbour (because it is a port).
12 The wrapper script ``hsct.sh`` then takes care of downloading the necessary
13 sources and running the user-defined commands from respective ``HARBOUR`` file.
15 The whole idea is highly inspired by
16 `makepkg <https://wiki.archlinux.org/index.php/Makepkg>`_.
19 **WARNING**: some information here is obsoleted.
20 I will try to update it as soon as possible.
24 First, clone this repository somewhere on your disk.
25 The examples below would assume ``~/helenos/coast``.
27 Next, prepare the directory where the actual building of the POSIX
28 applications would happen.
29 It is recommended to do this outside HelenOS source tree and outside of the
31 ``~/helenos/coast-builds/ia32`` is a good choice if you plan to build for
32 ``ia32`` configuration.
34 The script currently supports only static libraries (to be more precise, I
35 never tried to build any shared library with it) and thus you need to build
37 Some of the prepared packages depends on some changes in ``libposix`` that
38 are not yet in mainline, thus it is recommended to build against
39 `lp:~vojtech-horky/helenos/gcc-port <https://code.launchpad.net/~vojtech-horky/helenos/gcc-port>`_.
41 ``~/helenos/gcc-port`` might be a good location where to make the
43 Once you checkout the branch, configure it for ``ia32`` and build it.
46 make PROFILE=ia32 HANDS_OFF=y
50 After the build is complete, it is possible to actually compile and build
51 some of the ported software.
52 But before that, a ``hsct.conf`` has to be prepared in
53 ``~/helenos/coast-builds/ia32`` that contains the following line (path
54 to the actual HelenOS root)::
56 root = /home/username/helenos/gcc-port
58 Then, change directory to ``~/helenos/coast-builds/ia32`` and execute the
59 following command to build `zlib <http://www.zlib.net/>`_::
61 ~/helenos/coast/hsct.sh build zlib
63 If all is well, zlib sources shall be fetched, zlib shall be configured
65 Inside directory ``build/zlib/zlib-1.2.7`` shall reside the compiled library.
69 ~/helenos/coast/hsct.sh package zlib
71 would copy the compiled library and some example applications outside of
72 the build tree to allow removing the build directory if you are low on free
77 ~/helenos/coast/hsct.sh install zlib
79 would copy zlib to HelenOS source tree so that you can actually try it live.
80 After booting HelenOS, ``minigzip`` shall be available in ``/coast/zlib``.
82 If you often compile for different architectures, you may want to use the
83 ``arch`` option in ``hsct.conf`` (it is recommended to use it anyway).
84 It contains the short architecture name (such as ``ia32`` or ``mips32``)::
88 and it is checked against currently selected architecture inside your HelenOS
89 source tree prior building.
90 This ensures that you do not mix different architecture accidentally.
91 Empty or missing value means that no check is done at all.
96 Writing your own HARBOUR files
97 ------------------------------
98 The ``HARBOUR`` file is actually a shell script fragment.
99 The coastline script ``hsct.sh`` expects to find some variables and functions
101 These variables declare URLs of the source tarballs or versions while the
102 functions actually build (or install) the application/library/whatever.
104 Each ``HARBOUR`` is supposed to be in a separate directory.
105 This directory is placed together with the ``hsct.sh`` script.
107 The commands in individual functions are expected to use special
108 variables prepared by the wrapper script that would contain information
109 about selected compiler (i.e. full path to GCC) or flags for the compiler
111 These variables are prefixed with ``HSCT_`` followed by the name commonly
112 used in ``Makefile``\s or in ``configure`` scripts
113 (e.g. ``HSCT_CC`` contains path to the C compiler).
115 However, usually it is not possible to write the ``HARBOUR`` file directly:
116 for example various arguments to ``./configure`` scripts have to be tried
117 or extra ``CFLAGS`` might be necessary.
119 For testing, you can use the ``helenos/env.sh`` script and source it.
120 This script sets all the variables that you can use in the HARBOUR script.
122 Follows a shortened list of variables available.
124 - ``$HSCT_CC``: C compiler to use.
125 - ``$HSCT_CFLAGS``: C flags to use.
126 - ``$HSCT_LD``: linker to use.
127 - ``$HSCT_LDFLAGS``: linker flags
128 - ``$HSCT_LDFLAGS_FOR_CC``: linker flags preceded by ``-Wl,``.
129 This is extremely useful when linker is not called explicitly and compiler
130 is used for linking as well.
131 Some of the flags would be recognized during the compilation phase so
132 marking them as linker-specific effectively hides them.
133 - ``$HSCT_GNU_TARGET``: Target for which the application is being built.
134 Typically this is the value for the ``--target`` option of the ``configure``
137 Following variables are useful when the application is successfully built
138 and you want to copy some of the created files elsewhere.
139 E.g. to the HelenOS source tree so they could become part of the generated
142 - ``$HSCT_INCLUDE_DIR``: Points to directory for header files.
143 - ``$HSCT_LIB_DIR``: Points to directory for libraries.
144 - ``$HSCT_MISC_DIR``: Points to directory for any other stuff.
145 It is recommended to create a subdirectory ``$HSCT_MISC_DIR/application-name``
146 for these extra files).
148 For example, the ``./configure`` script for `libgmp <http://gmplib.org/>`_
149 uses the following variables::
153 --host="$HSCT_GNU_TARGET" \
155 CFLAGS="$HSCT_CFLAGS $HSCT_LDFLAGS_FOR_CC <more flags>" \
158 Once you know the command sequence that leads to a successful built you
159 should record this sequence into the ``HARBOUR`` file.
160 The easiest way is to take an existing one and just change it for the
161 particular application.
163 The variable ``shipname`` declares the package (application or library)
164 name and shall be the same as the directory the ``HARBOUR`` is part of.
166 The variable ``shipsources`` contains space separated list of tarballs
167 or other files that needs to be downloaded.
168 Obviously, you can use ``$shipname`` inside as shell does the expansion.
169 To simplify updating of the packages, it is a good practice to have
170 variable ``$shipversion`` containing the application version and use this
171 variable inside ``$shipsources``.
172 If you need to reference a local file (a patch for example),
173 just write a bare name there.
174 The files are downloaded with ``wget`` so make sure the protocol used
175 and the path format is supported by this tool.
177 The variable ``shiptugs`` declares packages this one depends on
178 (the twisted fun is here that tugs are required for the ship to actually
180 That is a string with space separated list of other ships.
182 For building is used a ``build()`` function.
183 The function is expected to complete the following tasks:
185 - unpack the tarballs
186 - configure the application or somehow prepare it for building
189 Look into existing files how does this process typically looks like.
191 If you want to print an informative message to the screen, it is recommended
192 to use ``msg()`` function as it would make the message more visible.
194 To simplify debugging it is recommended to run commands prefixed with
195 function named ``run``.
196 That way the actual command is first printed to the screen and then
199 Once the application is built it is necessary to copy its files to a more
200 permanent storage (to allow clean-up of the build directory) and finally copy
201 the files to the HelenOS source tree.
203 The function ``package()`` copies the files outside of the build directory
204 and it typically consists of similar commands
205 (this one is taken from ``zlib``)::
208 # shipname is "zlib" here
209 cd "${shipname}-${shipversion}"
211 # Pretend we are actually installing
212 run make install "DESTDIR=$PWD/PKG"
214 # Copy the headers and static library
215 run cp PKG/usr/local/include/zlib.h PKG/usr/local/include/zconf.h "$HSCT_INCLUDE_DIR/"
216 run cp PKG/usr/local/lib/libz.a "$HSCT_LIB_DIR/"
219 The ``dist()`` function is used to copy these files to the HelenOS source
221 You have following two variables to simplify the path specification:
223 - ``$HSCT_DIST``: points to ``uspace/dist`` inside the source tree.
224 - ``$HSCT_DIST2``: points to ``uspace/dist/coast/$shipname``.
225 However, you first need to create this directory.
227 Typically, the ``dist()`` function looks like this::
230 run mkdir -p "$HSCT_DIST2"
231 run cp "$HSCT_MISC_DIR/${shipname}/"* "$HSCT_DIST2"
234 Finally, there is ``undist()`` function that removes the files from the
236 Typical implementation is very simple::
239 run rm -rf "$HSCT_DIST2"