4 # Copyright (c) 2013 Vojtech Horky
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
11 # - Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # - Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
16 # - The name of the author may not be used to endorse or promote products
17 # derived from this software without specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 # Calling harbour functions:
32 # These functions are always called in a subshell to "guard" them a little
33 # bit (variables set by the harbour, cd into package directory).
35 # Notice on usage of set -o errexit (set -e)
36 # We want to use that option for the harbour scripts to get rid of the
37 # "|| return 1" at the end of each line.
38 # Obvious solution is to wrap the call like this:
39 # ( set -o errexit; build ) || { hsct_error "..."; return 1; }
40 # This doesn't work because the whole subshell is then part of a ||
41 # operand and thus the set -e is ignored (even if it is a subshell).
42 # See https://groups.google.com/d/msg/gnu.bash.bug/NCK_0GmIv2M/y6RQF1AWUQkJ
43 # Thus, we need to use the following template to get past this:
44 # ( set -o errexit; build; exit $? );
45 # [ $? -eq 0 ] || { hsct_error "..."; return 1; }
47 # Also notice that we never ever call exit from the top-most shell when
48 # leaving after an error. That is to prevent terminating user shell when
49 # this script is sourced ("env" command). It complicates the error handling
50 # a bit but it is more reliable than trying to guess whether we are running
51 # in a subshell or not.
54 HSCT_HOME
=`which -- "$0" 2>/dev/null`
55 # Maybe, we are running Bash
56 [ -z "$HSCT_HOME" ] && HSCT_HOME
=`which -- "$BASH_SOURCE" 2>/dev/null`
57 HSCT_HOME
=`dirname -- "$HSCT_HOME"`
58 HSCT_HSCT
="$HSCT_HOME/hsct.sh"
60 HSCT_SOURCES_DIR
=`pwd`/sources
61 HSCT_BUILD_DIR
=`pwd`/build
62 HSCT_INCLUDE_DIR
=`pwd`/include
63 HSCT_LIB_DIR
=`pwd`/libs
64 HSCT_DIST_DIR
="`pwd`/dist/"
65 HSCT_ARCHIVE_DIR
="`pwd`/archives/"
66 HSCT_DISABLED_CFLAGS
="-Werror -Werror-implicit-function-declaration"
67 HSCT_CACHE_DIR
=`pwd`/helenos
70 # Does not exit the whole script.
73 echo " $1 action [package]"
74 echo " Action can be one of following:"
75 echo " clean Clean built directory."
76 echo " build Build given package."
77 echo " package Save installable files to allow cleaning."
78 echo " install Install to uspace/dist of HelenOS."
79 echo " archive Create tarball instead of installing."
80 echo " $1 update [rebuild]"
81 echo " Update the cached headers and libraries."
82 echo " If 'rebuild' is specified, HelenOS is forcefully rebuild and"
83 echo " cache is updated afterwards."
84 echo " $1 init /path/to/HelenOS [profile] [build]"
85 echo " Initialize current directory as coastline build directory".
86 echo " Full path has to be provided to the HelenOS source tree."
87 echo " If profile is specified, prepare for that configuration."
88 echo " If 'build' is given, forcefully rebuild to specified profile."
90 echo " Display this help and exit."
93 # Print high-level information message.
98 # Print lower-level information message (additional info after hsct_info).
103 # Print information message from HARBOUR script.
108 # Print high-level error message.
110 echo "[hsct]:" "Error:" "$@" >&2
113 # Print additional details to the error message.
115 echo "[hsct]:" " -> " "$@" >&2
118 # Run a command but print it first.
124 # Run comman from HARBOUR script and print it as well.
129 # Tells whether HelenOS in $HSCT_HELENOS_ROOT is configured.
130 hsct_is_helenos_configured
() {
131 [ -e "$HSCT_HELENOS_ROOT/Makefile.config" ]
135 # hsct_get_config CONFIG_FILE variable
137 grep '^[ \t]*'"$2" "$1" \
140 |
sed -e 's/^[ \t]*//' -e 's/[ \t]*$//'
143 # Fetch all the specified files in the HARBOUR
145 mkdir
-p "$HSCT_SOURCES_DIR"
146 hsct_info
"Fetching sources..."
147 for _url
in $shipsources; do
148 _filename
=`basename "$_url"`
149 if [ "$_filename" = "$_url" ]; then
152 if ! [ -r "$HSCT_SOURCES_DIR/$_filename" ]; then
153 hsct_info2
"Fetching $_filename..."
154 if ! wget
"$_url" -O "$HSCT_SOURCES_DIR/$_filename"; then
155 rm -f "$HSCT_SOURCES_DIR/$_filename"
156 hsct_error
"Failed to fetch $_url."
166 # get_var_from_makefile CC Makefile.common
167 hsct_get_var_from_makefile
() {
168 # echo "make -C `dirname "$2"` -f - -s __armagedon_" >&2
175 echo "CONFIG_DEBUG=n"
176 echo include
`basename "$2"`
177 echo "CONFIG_DEBUG=n"
179 echo "__armagedon__:"
182 ) |
make -C `dirname "$2"` -f - -s __armagedon__
185 # Retrieve variable from uspace/ Makefile.
186 hsct_get_var_from_uspace
() {
188 hsct_get_var_from_makefile
"$1" "$HSCT_HELENOS_ROOT/uspace/Makefile.common" "USPACE_PREFIX=$HSCT_HELENOS_ROOT/uspace"
190 hsct_get_var_from_makefile
"$1" "$HSCT_HELENOS_ROOT/uspace/$2" "USPACE_PREFIX=$HSCT_HELENOS_ROOT/uspace" "$3" "$4"
194 # Cache and export a variable.
197 hsct_cache_variable
() {
203 echo -n "export $1=\"";
204 echo -n "$2" |
sed -e 's#"#\\"#g' -e 's#\\#\\\\#g'
206 ) >>"$HSCT_CACHE_DIR/env.sh"
209 # Update the cache - copy headers, libraries etc to this directory.
210 # Does not check that update is possible!
211 hsct_cache_update
() {
212 hsct_info
"Caching headers, libraries and compile flags"
214 mkdir
-p "$HSCT_CACHE_DIR"
218 echo "# This is automatically generated file."
219 echo "# All changes will be LOST upon next invocation of hsct.sh"
221 ) >"$HSCT_CACHE_DIR/env.sh"
222 chmod +x
"$HSCT_CACHE_DIR/env.sh"
226 # Start with binaries
229 hsct_cache_variable HSCT_CC
`hsct_get_var_from_uspace CC`
230 hsct_cache_variable HSCT_AS
`hsct_get_var_from_uspace AS`
231 hsct_cache_variable HSCT_LD
`hsct_get_var_from_uspace LD`
232 hsct_cache_variable HSCT_AR
`hsct_get_var_from_uspace AR`
233 hsct_cache_variable HSCT_STRIP
`hsct_get_var_from_uspace STRIP`
234 hsct_cache_variable HSCT_OBJCOPY
`hsct_get_var_from_uspace OBJCOPY`
235 hsct_cache_variable HSCT_OBJDUMP
`hsct_get_var_from_uspace OBJDUMP`
236 # HelenOS do not use ranlib or nm but some applications require it
237 hsct_cache_variable HSCT_RANLIB
`echo "$HSCT_AR" | sed 's/-ar$/-ranlib/'`
238 hsct_cache_variable HSCT_NM
`echo "$HSCT_AR" | sed 's/-ar$/-nm/'`
243 hsct_cache_variable HSTC_HELENOS_ROOT
"$HSCT_HELENOS_ROOT"
244 hsct_cache_variable HSCT_INCLUDE_DIR
"$HSCT_INCLUDE_DIR"
245 hsct_cache_variable HSCT_LIB_DIR
"$HSCT_LIB_DIR"
246 hsct_cache_variable HSCT_MISC_DIR
"$HSCT_MISC_DIR"
247 hsct_cache_variable HSCT_APPS_DIR
"$HSCT_APPS_DIR"
248 hsct_cache_variable HSCT_CACHE_DIR
"$HSCT_CACHE_DIR"
249 hsct_cache_variable HSCT_CACHE_INCLUDE
"$HSCT_CACHE_DIR/include"
250 hsct_cache_variable HSCT_CACHE_LIB
"$HSCT_CACHE_DIR/lib/other"
253 # Get architecture, convert to target
255 hsct_cache_variable HSCT_UARCH
`hsct_get_var_from_uspace UARCH`
259 HSCT_GNU_TARGET
="amd64-linux-gnu"
260 HSCT_HELENOS_TARGET
="amd64-helenos"
263 HSCT_GNU_TARGET
="arm-linux-gnueabi"
264 HSCT_HELENOS_TARGET
="arm-helenos-gnueabi"
267 HSCT_GNU_TARGET
="i686-pc-linux-gnu"
268 HSCT_HELENOS_TARGET
="i686-pc-helenos"
271 HSCT_GNU_TARGET
="ia64-pc-linux-gnu"
272 HSCT_HELENOS_TARGET
="ia64-pc-helenos"
275 HSCT_GNU_TARGET
="mipsel-linux-gnu"
276 HSCT_HELENOS_TARGET
="mipsel-helenos"
279 HSCT_GNU_TARGET
="mips-linux-gnu"
280 HSCT_HELENOS_TARGET
="mips-helenos"
283 HSCT_GNU_TARGET
="mips64el-linux-gnu"
284 HSCT_HELENOS_TARGET
="mips64el-helenos"
287 HSCT_GNU_TARGET
="ppc-linux-gnu"
288 HSCT_HELENOS_TARGET
="ppc-helenos"
291 HSCT_GNU_TARGET
="ppc64-linux-gnu"
292 HSCT_HELENOS_TARGET
="ppc64-helenos"
295 HSCT_GNU_TARGET
="sparc64-linux-gnu"
296 HSCT_HELENOS_TARGET
="sparc64-helenos"
299 hsct_error
'Unsupported architecture: $(UARCH) =' "'$HSCT_UARCH'."
303 hsct_cache_variable HSCT_GNU_TARGET
"$HSCT_GNU_TARGET"
304 hsct_cache_variable HSCT_HELENOS_TARGET
"$HSCT_HELENOS_TARGET"
305 case `hsct_get_var_from_uspace COMPILER` in
307 hsct_cache_variable HSCT_TARGET
"$HSCT_HELENOS_TARGET"
310 hsct_cache_variable HSCT_TARGET
"$HSCT_GNU_TARGET"
316 # Copy the files and update the flags accordingly
318 mkdir
-p "$HSCT_CACHE_INCLUDE"
319 mkdir
-p "$HSCT_CACHE_DIR/lib"
320 mkdir
-p "$HSCT_CACHE_LIB"
323 hsct_info2
"Copying linker script and startup object file"
324 _LINKER_SCRIPT
=`hsct_get_var_from_uspace LINKER_SCRIPT`
327 _STARTUP_OBJECT
=`sed -n 's#.*STARTUP(\([^)]*\)).*#\1#p' <"$_LINKER_SCRIPT" 2>/dev/null`
328 cp "$_STARTUP_OBJECT" "$HSCT_CACHE_DIR/lib/entry.o" ||
return 1
329 sed "s#$_STARTUP_OBJECT#$HSCT_CACHE_DIR/lib/entry.o#" \
330 <"$_LINKER_SCRIPT" >"$HSCT_CACHE_DIR/link.ld"
332 if [ $?
-ne 0 ]; then
333 hsct_error
"Failed preparing linker script."
337 _LINKER_SCRIPT
="$HSCT_CACHE_DIR/link.ld"
340 hsct_info2
"Copying libraries"
342 "$HSTC_HELENOS_ROOT/uspace/lib/c/libc.a" \
343 "$HSTC_HELENOS_ROOT/uspace/lib/softint/libsoftint.a" \
344 "$HSTC_HELENOS_ROOT/uspace/lib/softfloat/libsoftfloat.a" \
345 "$HSTC_HELENOS_ROOT/uspace/lib/posix/libc4posix.a" \
346 "$HSTC_HELENOS_ROOT/uspace/lib/posix/libposixaslibc.a" \
347 "$HSCT_CACHE_DIR/lib/"
348 if [ $?
-ne 0 ]; then
349 hsct_error
"Failed copying libraries to cache."
354 hsct_info2
"Copying headers"
357 cp -L -R "$HSTC_HELENOS_ROOT/uspace/lib/posix/include/posix/" "$HSCT_CACHE_DIR/include/"
358 mkdir
-p "$HSCT_CACHE_DIR/include/libc"
359 cp -L -R "$HSTC_HELENOS_ROOT/uspace/lib/c/include/"* "$HSCT_CACHE_DIR/include/libc"
360 cp -L -R "$HSTC_HELENOS_ROOT/abi/include/abi/" "$HSCT_CACHE_DIR/include/"
361 cp -L -R "$HSTC_HELENOS_ROOT/uspace/lib/c/arch/$HSCT_UARCH/include/libarch/" "$HSCT_CACHE_DIR/include/"
363 if [ $?
-ne 0 ]; then
364 hsct_error
"Failed copying headers to cache."
368 hsct_info2
"Fixing includes in libc headers"
369 find "$HSCT_CACHE_DIR/include/libc" "$HSCT_CACHE_DIR/include/libarch" -name '*.h' -exec sed \
370 -e 's:#include <:#include <libc/:' \
371 -e 's:#include <libc/libarch/:#include <libarch/:' \
372 -e 's:#include <libc/abi/:#include <abi/:' \
373 -e 's:#include <libc/libc/:#include <libc/:' \
376 # Remember the configuration
377 hsct_info2
"Saving config files"
380 cp "$HSTC_HELENOS_ROOT/config.h" "$HSCT_CACHE_INCLUDE/system_config.h"
381 cp "$HSTC_HELENOS_ROOT/Makefile.config" "$HSCT_CACHE_DIR/Makefile.config"
383 if [ $?
-ne 0 ]; then
384 hsct_error
"Failed saving config files."
388 # Extra libraries and headers
389 hsct_info2
"Copying extra headers and libraries"
393 cp -L "$HSTC_HELENOS_ROOT/uspace/lib/clui/libclui.a" "$HSCT_CACHE_LIB"
394 mkdir
-p "$HSCT_CACHE_INCLUDE/libclui/"
395 cp -L "$HSTC_HELENOS_ROOT/uspace/lib/clui/tinput.h" "$HSCT_CACHE_INCLUDE/libclui/"
397 if [ $?
-ne 0 ]; then
398 hsct_error
"Failed copying extra headers and libraries to cache."
405 hsct_info2
"Fixing compiler flags"
408 _CFLAGS
=`hsct_get_var_from_uspace CFLAGS`
409 _LDFLAGS
=`hsct_get_var_from_uspace LFLAGS`
412 #_CFLAGS=`echo "$_CFLAGS" | sed 's#-imacros[ \t]*\([^ \t]*/config.h\)#-imacros '"$HSCT_CACHE_DIR"'/include/system_config.h#'`
413 _CFLAGS_OLD
="$_CFLAGS"
416 for _flag
in $_CFLAGS_OLD; do
418 case "$_next_kind" in
423 if echo "$_flag" |
grep -q '/config.h$'; then
424 _flag
="$HSCT_CACHE_DIR/include/system_config.h"
432 for _disabled_flag
in $HSCT_DISABLED_CFLAGS; do
433 if [ "$_disabled_flag" = "$_flag" ]; then
439 if [ "$_flag" = "-L" ]; then
443 if [ "$_flag" = "-I" ]; then
447 if [ "$_flag" = "-imacros" ]; then
450 if echo "$_flag" |
grep -q '^-[IL]'; then
454 if ! $_disabled; then
455 _CFLAGS
="$_CFLAGS $_flag"
460 _LDFLAGS_OLD
="$_LDFLAGS"
462 for _flag
in $_LDFLAGS_OLD; do
464 # Get rid of library paths, the files are stored locally
465 if echo "$_flag" |
grep -q '^-[L]'; then
468 if ! $_disabled; then
469 _LDFLAGS
="$_LDFLAGS $_flag"
473 # Add paths to cached headers and libraries
474 _LDFLAGS
="$_LDFLAGS -L$HSCT_CACHE_DIR/lib -n -T $_LINKER_SCRIPT"
475 _CFLAGS
="$_CFLAGS -I$HSCT_CACHE_DIR/include/posix -I$HSCT_CACHE_DIR/include/"
477 # Actually used libraries
478 # The --whole-archive is used to allow correct linking of static libraries
479 # (otherwise, the ordering is crucial and we usally cannot change that in the
480 # application Makefiles).
481 _BASE_LIBS
=`hsct_get_var_from_uspace BASE_LIBS | sed 's#[ \t]\+#\n#g' | sed 's#.*/lib\(.*\).a$#\1#' | paste '-sd '`
485 _USE_SOFTFLOAT
="-lsoftfloat"
492 _USE_SOFTFLOAT
="-lsoftfloat"
495 _USE_SOFTFLOAT
="-lsoftfloat"
500 _POSIX_LINK_LFLAGS
="--whole-archive --start-group -lposixaslibc -lsoftint $_USE_SOFTFLOAT --end-group --no-whole-archive -lc4posix"
502 _LDFLAGS
="$_LDFLAGS $_POSIX_LINK_LFLAGS"
504 # The LDFLAGS might be used through CC, thus prefixing with -Wl is required
506 for _flag
in $_LDFLAGS; do
507 _LDFLAGS_FOR_CC
="$_LDFLAGS_FOR_CC -Wl,$_flag"
510 hsct_cache_variable HSCT_LDFLAGS
"$_LDFLAGS"
511 hsct_cache_variable HSCT_LDFLAGS_FOR_CC
"$_LDFLAGS_FOR_CC"
512 hsct_cache_variable HSCT_CFLAGS
"$_CFLAGS"
515 # Source the env.sh if present otherwise exit with failure.
517 if ! [ -e "$HSCT_CACHE_DIR/env.sh" ]; then
518 hsct_error
"Cache is not initialized. Maybe HelenOS is not configured?"
522 source "$HSCT_CACHE_DIR/env.sh"
524 if [ "$shipfunnels" -gt "$HSCT_PARALLELISM" ] 2>/dev
/null
; then
525 shipfunnels
="$HSCT_PARALLELISM"
526 elif [ "$shipfunnels" -le "$HSCT_PARALLELISM" ] 2>/dev
/null
; then
527 if [ "$shipfunnels" -le "0" ]; then
528 shipfunnels
="$HSCT_PARALLELISM"
535 # Remove the build directory of given package.
537 hsct_info
"Cleaning build directory..."
538 rm -rf "$HSCT_BUILD_DIR/$shipname/"*
541 # Decide whether it is possible to update the cache.
542 hsct_can_update_cache
() {
543 # If HelenOS is configured, we want to update the cache.
544 # However, if architecture is specified only if the current
545 # configuration is the same.
546 _arch
=`hsct_get_config "$HSCT_CONFIG" arch`
547 if [ -z "$_arch" ]; then
548 # Building for any architecture. We update the cache if
549 # HelenOS is configured.
550 hsct_is_helenos_configured
553 # Update the cache only if HelenOS is configured and the
554 # architecture matches
555 if hsct_is_helenos_configured
; then
556 _uarch
=`hsct_get_var_from_uspace UARCH`
557 [ "$_uarch" = "$_arch" ]
567 mkdir
-p "$HSCT_BUILD_DIR/$shipname"
568 if [ -e "$HSCT_BUILD_DIR/${shipname}.built" ]; then
569 hsct_info
"No need to build $shipname."
573 if hsct_can_update_cache
; then
574 if ! hsct_cache_update
; then
579 # Check for prerequisities
580 for tug
in $shiptugs; do
581 if ! [ -e "$HSCT_BUILD_DIR/${tug}.packaged" ]; then
582 hsct_info
"Need to build $tug first."
583 hsct_info2
"Running $HSCT_HSCT package $tug"
585 $HSCT_HSCT package
$tug
588 hsct_info2
"Back from building $tug."
592 hsct_prepare_env ||
return 1
594 hsct_fetch ||
return 1
596 for _url
in $shipsources; do
597 _filename
=`basename "$_url"`
598 if [ "$_filename" = "$_url" ]; then
599 _origin
="$HSCT_HOME/$shipname/$_filename"
601 _origin
="$HSCT_SOURCES_DIR/$_filename"
603 ln -sf "$_origin" "$HSCT_BUILD_DIR/$shipname/$_filename"
607 cd "$HSCT_BUILD_DIR/$shipname/"
608 hsct_info
"Building..."
613 if [ $?
-ne 0 ]; then
614 hsct_error
"Build failed!"
617 touch "$HSCT_BUILD_DIR/${shipname}.built"
621 # Pseudo-installation - copy from build directory to "my" directory, copy libraries
623 mkdir
-p "$HSCT_INCLUDE_DIR" ||
{ hsct_error
"Failed to create include directory."; return 1; }
624 mkdir
-p "$HSCT_LIB_DIR" ||
{ hsct_error
"Failed to create library directory."; return 1; }
625 mkdir
-p "$HSCT_MY_DIR" ||
{ hsct_error
"Failed to create package directory."; return 1; }
627 if [ -e "$HSCT_BUILD_DIR/${shipname}.packaged" ]; then
628 hsct_info
"No need to package $shipname."
632 hsct_build ||
return 1
634 hsct_prepare_env ||
return 1
637 cd "$HSCT_BUILD_DIR/$shipname/"
638 hsct_info
"Packaging..."
643 if [ $?
-ne 0 ]; then
644 hsct_error
"Packaging failed!"
647 touch "$HSCT_BUILD_DIR/${shipname}.packaged"
651 # Install the package to HelenOS source tree (to uspace/overlay).
653 hsct_package ||
return 1
655 if ! hsct_can_update_cache
; then
656 hsct_error
"Installation cannot be performed."
657 hsct_error2
"HelenOS is not configured for the proper architecture."
661 hsct_info
"Installing..."
662 if ls "$HSCT_MY_DIR"/* &>/dev
/null
; then
663 cp -v -r -L "$HSCT_MY_DIR"/* "$HSCT_OVERLAY" ||
return 1
664 hsct_info2
"Do not forget to rebuild the image."
666 hsct_info2
"Note: nothing to install."
671 # Create tarball to allow redistribution of the build packages
673 hsct_package ||
return 1
675 hsct_info
"Creating the tarball..."
676 mkdir
-p "$HSCT_ARCHIVE_DIR"
679 cd "$HSCT_DIST_DIR/$shipname"
680 tar cJf
"$HSCT_ARCHIVE_DIR/$shipname.tar.xz" .
682 if [ $?
-ne 0 ]; then
683 hsct_error
"Archiving failed!"
691 # Initialize current directory for coastline building.
693 if [ -e "$HSCT_CONFIG" ]; then
694 hsct_error
"Directory is already initialized ($HSCT_CONFIG exists)."
698 hsct_info
"Initializing this build directory."
699 _root_dir
=`( cd "$1"; pwd ) 2>/dev/null`
700 if ! [ -e "$_root_dir/HelenOS.config" ]; then
701 hsct_error
"$1 does not look like a valid HelenOS directory.";
705 # If no architecture is specified, we would read it from
707 _uarch
=`hsct_get_var_from_uspace UARCH`
708 _machine
=`hsct_get_var_from_uspace MACHINE`
710 if [ -z "$_uarch" ]; then
711 hsct_error
"HelenOS is not configured and you haven't specified the architecture";
715 if [ "$3" = "build" ]; then
719 hsct_info2
"Cleaning previous configuration in $PWD."
720 make distclean
>/dev
/null
2>&1
721 hsct_info2
"Configuring for $2."
722 make Makefile.config
"PROFILE=$2" HANDS_OFF
=y
>/dev
/null
723 hsct_info2
"Building (may take a while)."
726 if [ $?
-ne 0 ]; then
727 hsct_error
"Failed to automatically configure HelenOS for $2."
730 _uarch
=`echo "$2" | cut '-d/' -f 1`
731 _machine
=`echo "$2" | cut '-d/' -f 2`
733 if [ "$_uarch" != "$2" ]; then
734 hsct_error
"HelenOS is configured for different architecture (maybe add 'build' parameter?)"
739 hsct_info2
"Generating the configuration file."
740 cat >$HSCT_CONFIG <<EOF_CONFIG
750 # Update the cache manually.
752 if [ "$1" = "rebuild" ]; then
753 hsct_info
"Rebuilding HelenOS to match local configuration"
756 cd "$HSCT_HELENOS_ROOT"
757 hsct_info2
"Cleaning previous configuration in $PWD."
758 make distclean
>/dev
/null
2>&1
759 hsct_info2
"Configuring for $HSCT_HELENOS_PROFILE."
760 make Makefile.config \
761 "PROFILE=$HSCT_HELENOS_PROFILE" HANDS_OFF
=y \
762 2>&1 >/dev
/null |
sed '/^Fetching current.*ok$/d'
763 hsct_info2
"Overriding configuration with the stored one."
764 cp "$HSCT_CACHE_DIR/Makefile.config" Makefile.config
765 cp "$HSCT_CACHE_DIR/include/system_config.h" config.h
766 hsct_info2
"Building (may take a while)."
769 if [ $?
-ne 0 ]; then
770 hsct_error
"Failed to automatically rebuild HelenOS."
774 if ! hsct_can_update_cache
; then
783 alias leave_script_ok
='return 0 2>/dev/null || exit 0'
784 alias leave_script_err
='return 1 2>/dev/null || exit 1'
786 HSCT_CONFIG
=hsct.conf
789 if [ "$1" = "init" ]; then
790 HSCT_HELENOS_ROOT
="$2"
792 if ! [ -e "$HSCT_CONFIG" ]; then
793 hsct_error
"Configuration file $HSCT_CONFIG missing."
796 HSCT_HELENOS_ROOT
=`hsct_get_config "$HSCT_CONFIG" root`
797 HSCT_HELENOS_ARCH
=`hsct_get_config "$HSCT_CONFIG" arch`
798 HSCT_HELENOS_MACHINE
=`hsct_get_config "$HSCT_CONFIG" machine`
799 HSCT_PARALLELISM
=`hsct_get_config "$HSCT_CONFIG" parallel`
801 if [ -z "$HSCT_HELENOS_ARCH" ]; then
802 hsct_error
"I don't know for which architecture you want to build."
806 if [ -z "$HSCT_HELENOS_MACHINE" ]; then
807 HSCT_HELENOS_PROFILE
="$HSCT_HELENOS_ARCH"
809 HSCT_HELENOS_PROFILE
="$HSCT_HELENOS_ARCH/$HSCT_HELENOS_MACHINE"
812 if ! [ "$HSCT_PARALLELISM" -ge 0 ] 2>/dev
/null
; then
817 if [ -z "$HSCT_HELENOS_ROOT" ]; then
818 hsct_error
"I don't know where is the HelenOS source root."
827 clean|build|package|
install|archive
)
828 HSCT_HARBOUR_NAME
="$2"
829 if [ -z "$HSCT_HARBOUR_NAME" ]; then
835 hsct_init
"$2" "$3" "$4"
849 if ! [ -d "$HSCT_HOME/$HSCT_HARBOUR_NAME" ]; then
850 hsct_error
"Unknown package $1"
854 if ! [ -r "$HSCT_HOME/$HSCT_HARBOUR_NAME/HARBOUR" ]; then
855 hsct_error
"HARBOUR file missing." >&2
859 HSCT_OVERLAY
="$HSCT_HELENOS_ROOT/uspace/overlay"
860 HSCT_MY_DIR
="$HSCT_DIST_DIR/$HSCT_HARBOUR_NAME"
862 source "$HSCT_HOME/$HSCT_HARBOUR_NAME/HARBOUR"
881 hsct_error
"Internal error, we shall not get to this point!"
886 if [ $?
-eq 0 ]; then