Create .tar.xz as it is much smaller
[harbours.git] / hsct.sh
blob725f9b811813b2305c6d031e852dc62909bba966
1 #!/bin/sh
4 # Copyright (c) 2013 Vojtech Horky
5 # All rights reserved.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
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
69 # Print short help.
70 # Does not exit the whole script.
71 hsct_usage() {
72 echo "Usage:"
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."
89 echo " $1 help"
90 echo " Display this help and exit."
93 # Print high-level information message.
94 hsct_info() {
95 echo ">>>" "$@" >&2
98 # Print lower-level information message (additional info after hsct_info).
99 hsct_info2() {
100 echo " ->" "$@" >&2
103 # Print information message from HARBOUR script.
104 msg() {
105 hsct_info "$@"
108 # Print high-level error message.
109 hsct_error() {
110 echo "[hsct]:" "Error:" "$@" >&2
113 # Print additional details to the error message.
114 hsct_error2() {
115 echo "[hsct]:" " -> " "$@" >&2
118 # Run a command but print it first.
119 hsct_run_echo() {
120 echo "[hsct]:" "$@"
121 "$@"
124 # Run comman from HARBOUR script and print it as well.
125 run() {
126 hsct_run_echo "$@"
129 # Tells whether HelenOS in $HSCT_HELENOS_ROOT is configured.
130 hsct_is_helenos_configured() {
131 [ -e "$HSCT_HELENOS_ROOT/Makefile.config" ]
132 return $?
135 # hsct_get_config CONFIG_FILE variable
136 hsct_get_config() {
137 grep '^[ \t]*'"$2" "$1" \
138 | tail -n 1 \
139 | cut '-d=' -f 2 \
140 | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//'
143 # Fetch all the specified files in the HARBOUR
144 hsct_fetch() {
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
150 continue
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."
157 return 1
160 # TODO - check MD5
161 done
162 return 0
166 # get_var_from_makefile CC Makefile.common
167 hsct_get_var_from_makefile() {
168 # echo "make -C `dirname "$2"` -f - -s __armagedon_" >&2
170 echo "$3"
171 echo "$4"
172 echo "$5"
173 echo "__genesis__:"
174 echo
175 echo "CONFIG_DEBUG=n"
176 echo include `basename "$2"`
177 echo "CONFIG_DEBUG=n"
178 echo
179 echo "__armagedon__:"
180 echo " echo \$($1)"
181 echo
182 ) | make -C `dirname "$2"` -f - -s __armagedon__
185 # Retrieve variable from uspace/ Makefile.
186 hsct_get_var_from_uspace() {
187 if [ -z "$2" ]; then
188 hsct_get_var_from_makefile "$1" "$HSCT_HELENOS_ROOT/uspace/Makefile.common" "USPACE_PREFIX=$HSCT_HELENOS_ROOT/uspace"
189 else
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.
195 # $1 variable name
196 # $2 value to cache
197 hsct_cache_variable() {
198 export "$1=$2"
200 if [ -n "$3" ]; then
201 echo "#" "$3"
203 echo -n "export $1=\"";
204 echo -n "$2" | sed -e 's#"#\\"#g' -e 's#\\#\\\\#g'
205 echo "\""
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"
216 echo "#!/bin/sh"
217 echo
218 echo "# This is automatically generated file."
219 echo "# All changes will be LOST upon next invocation of hsct.sh"
220 echo
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/'`
241 # Various paths
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`
256 HSCT_TARGET=""
257 case $HSCT_UARCH in
258 "amd64")
259 HSCT_GNU_TARGET="amd64-linux-gnu"
260 HSCT_HELENOS_TARGET="amd64-helenos"
262 "arm32")
263 HSCT_GNU_TARGET="arm-linux-gnueabi"
264 HSCT_HELENOS_TARGET="arm-helenos-gnueabi"
266 "ia32")
267 HSCT_GNU_TARGET="i686-pc-linux-gnu"
268 HSCT_HELENOS_TARGET="i686-pc-helenos"
270 "ia64")
271 HSCT_GNU_TARGET="ia64-pc-linux-gnu"
272 HSCT_HELENOS_TARGET="ia64-pc-helenos"
274 "mips32")
275 HSCT_GNU_TARGET="mipsel-linux-gnu"
276 HSCT_HELENOS_TARGET="mipsel-helenos"
278 "mips32eb")
279 HSCT_GNU_TARGET="mips-linux-gnu"
280 HSCT_HELENOS_TARGET="mips-helenos"
282 "mips64")
283 HSCT_GNU_TARGET="mips64el-linux-gnu"
284 HSCT_HELENOS_TARGET="mips64el-helenos"
286 "ppc32")
287 HSCT_GNU_TARGET="ppc-linux-gnu"
288 HSCT_HELENOS_TARGET="ppc-helenos"
290 "ppc64")
291 HSCT_GNU_TARGET="ppc64-linux-gnu"
292 HSCT_HELENOS_TARGET="ppc64-helenos"
294 "sparc64")
295 HSCT_GNU_TARGET="sparc64-linux-gnu"
296 HSCT_HELENOS_TARGET="sparc64-helenos"
299 hsct_error 'Unsupported architecture: $(UARCH) =' "'$HSCT_UARCH'."
300 return 1
302 esac
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
306 gcc_helenos)
307 hsct_cache_variable HSCT_TARGET "$HSCT_HELENOS_TARGET"
310 hsct_cache_variable HSCT_TARGET "$HSCT_GNU_TARGET"
312 esac
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"
322 # Linker script
323 hsct_info2 "Copying linker script and startup object file"
324 _LINKER_SCRIPT=`hsct_get_var_from_uspace LINKER_SCRIPT`
326 set -o errexit
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."
334 return 1
337 _LINKER_SCRIPT="$HSCT_CACHE_DIR/link.ld"
339 # Libraries
340 hsct_info2 "Copying libraries"
341 cp \
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."
350 return 1
353 # Headers
354 hsct_info2 "Copying headers"
356 set -o errexit
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."
365 return 1
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/:' \
374 -i {} \;
376 # Remember the configuration
377 hsct_info2 "Saving config files"
379 set -o errexit
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."
385 return 1
388 # Extra libraries and headers
389 hsct_info2 "Copying extra headers and libraries"
391 set -o errexit
392 # libclui
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."
399 return 1
403 # Fix the flags
405 hsct_info2 "Fixing compiler flags"
407 # Get the flags
408 _CFLAGS=`hsct_get_var_from_uspace CFLAGS`
409 _LDFLAGS=`hsct_get_var_from_uspace LFLAGS`
411 # CC flags clean-up
412 #_CFLAGS=`echo "$_CFLAGS" | sed 's#-imacros[ \t]*\([^ \t]*/config.h\)#-imacros '"$HSCT_CACHE_DIR"'/include/system_config.h#'`
413 _CFLAGS_OLD="$_CFLAGS"
414 _CFLAGS=""
415 _next_kind="none"
416 for _flag in $_CFLAGS_OLD; do
417 _disabled=false
418 case "$_next_kind" in
419 skip)
420 _disable=true
422 imacro)
423 if echo "$_flag" | grep -q '/config.h$'; then
424 _flag="$HSCT_CACHE_DIR/include/system_config.h"
429 esac
430 _next_kind="none"
432 for _disabled_flag in $HSCT_DISABLED_CFLAGS; do
433 if [ "$_disabled_flag" = "$_flag" ]; then
434 _disabled=true
435 break
437 done
439 if [ "$_flag" = "-L" ]; then
440 _next_kind="skip"
441 _disabled=true
443 if [ "$_flag" = "-I" ]; then
444 _next_kind="skip"
445 _disabled=true
447 if [ "$_flag" = "-imacros" ]; then
448 _next_kind="imacro"
450 if echo "$_flag" | grep -q '^-[IL]'; then
451 _disabled=true
454 if ! $_disabled; then
455 _CFLAGS="$_CFLAGS $_flag"
457 done
459 # LD flags clean-up
460 _LDFLAGS_OLD="$_LDFLAGS"
461 _LDFLAGS=""
462 for _flag in $_LDFLAGS_OLD; do
463 _disabled=false
464 # Get rid of library paths, the files are stored locally
465 if echo "$_flag" | grep -q '^-[L]'; then
466 _disabled=true
468 if ! $_disabled; then
469 _LDFLAGS="$_LDFLAGS $_flag"
471 done
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 '`
482 _USE_SOFTFLOAT=""
483 case $_BASE_LIBS in
484 *softfloat*)
485 _USE_SOFTFLOAT="-lsoftfloat"
489 esac
490 case $HSCT_UARCH in
491 arm32)
492 _USE_SOFTFLOAT="-lsoftfloat"
494 sparc64)
495 _USE_SOFTFLOAT="-lsoftfloat"
499 esac
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
505 _LDFLAGS_FOR_CC=""
506 for _flag in $_LDFLAGS; do
507 _LDFLAGS_FOR_CC="$_LDFLAGS_FOR_CC -Wl,$_flag"
508 done
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.
516 hsct_prepare_env() {
517 if ! [ -e "$HSCT_CACHE_DIR/env.sh" ]; then
518 hsct_error "Cache is not initialized. Maybe HelenOS is not configured?"
519 return 1
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"
530 else
531 shipfunnels="1"
535 # Remove the build directory of given package.
536 hsct_clean() {
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
551 return $?
552 else
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" ]
558 return $?
559 else
560 return 1
565 # Build the package.
566 hsct_build() {
567 mkdir -p "$HSCT_BUILD_DIR/$shipname"
568 if [ -e "$HSCT_BUILD_DIR/${shipname}.built" ]; then
569 hsct_info "No need to build $shipname."
570 return 0
573 if hsct_can_update_cache; then
574 if ! hsct_cache_update; then
575 return 1
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
586 exit $?
587 ) || return 1
588 hsct_info2 "Back from building $tug."
590 done
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"
600 else
601 _origin="$HSCT_SOURCES_DIR/$_filename"
603 ln -sf "$_origin" "$HSCT_BUILD_DIR/$shipname/$_filename"
604 done
607 cd "$HSCT_BUILD_DIR/$shipname/"
608 hsct_info "Building..."
609 set -o errexit
610 build
611 exit $?
613 if [ $? -ne 0 ]; then
614 hsct_error "Build failed!"
615 return 1
617 touch "$HSCT_BUILD_DIR/${shipname}.built"
618 return 0
621 # Pseudo-installation - copy from build directory to "my" directory, copy libraries
622 hsct_package() {
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."
629 return 0;
632 hsct_build || return 1
634 hsct_prepare_env || return 1
637 cd "$HSCT_BUILD_DIR/$shipname/"
638 hsct_info "Packaging..."
639 set -o errexit
640 package
641 exit $?
643 if [ $? -ne 0 ]; then
644 hsct_error "Packaging failed!"
645 return 1
647 touch "$HSCT_BUILD_DIR/${shipname}.packaged"
648 return 0
651 # Install the package to HelenOS source tree (to uspace/overlay).
652 hsct_install() {
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."
658 return 1
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."
665 else
666 hsct_info2 "Note: nothing to install."
668 return 0
671 # Create tarball to allow redistribution of the build packages
672 hsct_archive() {
673 hsct_package || return 1
675 hsct_info "Creating the tarball..."
676 mkdir -p "$HSCT_ARCHIVE_DIR"
678 set -o errexit
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!"
684 return 1
687 return 0
691 # Initialize current directory for coastline building.
692 hsct_init() {
693 if [ -e "$HSCT_CONFIG" ]; then
694 hsct_error "Directory is already initialized ($HSCT_CONFIG exists)."
695 return 1
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.";
702 return 1
705 # If no architecture is specified, we would read it from
706 # Makefile.config
707 _uarch=`hsct_get_var_from_uspace UARCH`
708 _machine=`hsct_get_var_from_uspace MACHINE`
709 if [ -z "$2" ]; then
710 if [ -z "$_uarch" ]; then
711 hsct_error "HelenOS is not configured and you haven't specified the architecture";
712 return 1
715 if [ "$3" = "build" ]; then
717 set -o errexit
718 cd "$_root_dir"
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)."
724 make >/dev/null 2>&1
726 if [ $? -ne 0 ]; then
727 hsct_error "Failed to automatically configure HelenOS for $2."
728 return 1
730 _uarch=`echo "$2" | cut '-d/' -f 1`
731 _machine=`echo "$2" | cut '-d/' -f 2`
732 else
733 if [ "$_uarch" != "$2" ]; then
734 hsct_error "HelenOS is configured for different architecture (maybe add 'build' parameter?)"
735 return 1
739 hsct_info2 "Generating the configuration file."
740 cat >$HSCT_CONFIG <<EOF_CONFIG
741 root = $_root_dir
742 arch = $_uarch
743 machine = $_machine
744 parallel = 1
745 EOF_CONFIG
746 hsct_cache_update
747 return $?
750 # Update the cache manually.
751 hsct_update() {
752 if [ "$1" = "rebuild" ]; then
753 hsct_info "Rebuilding HelenOS to match local configuration"
755 set -o errexit
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)."
767 make >/dev/null 2>&1
769 if [ $? -ne 0 ]; then
770 hsct_error "Failed to automatically rebuild HelenOS."
771 return 1
773 else
774 if ! hsct_can_update_cache; then
775 return 1
779 hsct_cache_update
780 return $?
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"
791 else
792 if ! [ -e "$HSCT_CONFIG" ]; then
793 hsct_error "Configuration file $HSCT_CONFIG missing."
794 leave_script_err
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."
803 leave_script_err
806 if [ -z "$HSCT_HELENOS_MACHINE" ]; then
807 HSCT_HELENOS_PROFILE="$HSCT_HELENOS_ARCH"
808 else
809 HSCT_HELENOS_PROFILE="$HSCT_HELENOS_ARCH/$HSCT_HELENOS_MACHINE"
812 if ! [ "$HSCT_PARALLELISM" -ge 0 ] 2>/dev/null; then
813 HSCT_PARALLELISM="1"
817 if [ -z "$HSCT_HELENOS_ROOT" ]; then
818 hsct_error "I don't know where is the HelenOS source root."
819 leave_script_err
822 case "$1" in
823 help)
824 hsct_usage "$0"
825 leave_script_ok
827 clean|build|package|install|archive)
828 HSCT_HARBOUR_NAME="$2"
829 if [ -z "$HSCT_HARBOUR_NAME" ]; then
830 hsct_usage "$0"
831 leave_script_err
834 init)
835 hsct_init "$2" "$3" "$4"
836 leave_script_ok
838 update)
839 hsct_update "$2"
840 leave_script_ok
843 hsct_usage "$0"
844 leave_script_err
846 esac
849 if ! [ -d "$HSCT_HOME/$HSCT_HARBOUR_NAME" ]; then
850 hsct_error "Unknown package $1"
851 leave_script_err
854 if ! [ -r "$HSCT_HOME/$HSCT_HARBOUR_NAME/HARBOUR" ]; then
855 hsct_error "HARBOUR file missing." >&2
856 leave_script_err
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"
864 case "$1" in
865 clean)
866 hsct_clean
868 build)
869 hsct_build
871 package)
872 hsct_package
874 install)
875 hsct_install
877 archive)
878 hsct_archive
881 hsct_error "Internal error, we shall not get to this point!"
882 leave_script_err
884 esac
886 if [ $? -eq 0 ]; then
887 leave_script_ok
888 else
889 leave_script_err