annotate build.sh @ 984:9840847885e8

Add export_if_blank and make lots of build paths overrideable.
author Rob Landley <rob@landley.net>
date Wed, 24 Feb 2010 10:08:38 -0600
parents fc134a13357e
children bbcafba8a594
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
96
137ba51ee993 Delete output directories on re-run, teach build to log and build multiple
Rob Landley <rob@landley.net>
parents: 93
diff changeset
1 #!/bin/bash
137ba51ee993 Delete output directories on re-run, teach build to log and build multiple
Rob Landley <rob@landley.net>
parents: 93
diff changeset
2
888
626288dd5cf3 Lots of comments.
Rob Landley <rob@landley.net>
parents: 873
diff changeset
3 # Run all the steps needed to build a system image from scratch.
626288dd5cf3 Lots of comments.
Rob Landley <rob@landley.net>
parents: 873
diff changeset
4
114
304fd441e6a4 Re-teach build.sh to build more than one architecture in sequence.
Rob Landley <rob@landley.net>
parents: 108
diff changeset
5 # If run with no arguments, list architectures.
108
b66d638a3844 Build User Mode Linux and have that do the ext2 packaging (for now, anyway).
Rob Landley <rob@landley.net>
parents: 105
diff changeset
6
781
d8c780ed3686 Simplify build.sh to take exactly one argument. (Otherwise use buildall.sh.)
Rob Landley <rob@landley.net>
parents: 744
diff changeset
7 if [ $# -ne 1 ]
114
304fd441e6a4 Re-teach build.sh to build more than one architecture in sequence.
Rob Landley <rob@landley.net>
parents: 108
diff changeset
8 then
781
d8c780ed3686 Simplify build.sh to take exactly one argument. (Otherwise use buildall.sh.)
Rob Landley <rob@landley.net>
parents: 744
diff changeset
9 echo "Usage: $0 ARCH"
744
759adf5a0fe9 Refactor so include.sh mostly just sets environment variables. Move read_arch_dir to function and call it explicitly (no more need for $NO_ARCH). Make blank_tempdir a function, called explicitly by stages when needed, with some sanity checks. Insert prerequisite tests to later stages so they can detect failure early and provide an explicit erro rmessage, and have those tests happen before blanking $WORK dir, to preserve debugging info. Make buildall.sh depend on prerequisite tests rather than trying to avoid calling later stages (and thus do flow control from asynchronous context). Add FAIL_QUIET option so buildall.sh doesn't spam the log with the new prerequisite error messages.
Rob Landley <rob@landley.net>
parents: 719
diff changeset
10 . sources/include.sh
759adf5a0fe9 Refactor so include.sh mostly just sets environment variables. Move read_arch_dir to function and call it explicitly (no more need for $NO_ARCH). Make blank_tempdir a function, called explicitly by stages when needed, with some sanity checks. Insert prerequisite tests to later stages so they can detect failure early and provide an explicit erro rmessage, and have those tests happen before blanking $WORK dir, to preserve debugging info. Make buildall.sh depend on prerequisite tests rather than trying to avoid calling later stages (and thus do flow control from asynchronous context). Add FAIL_QUIET option so buildall.sh doesn't spam the log with the new prerequisite error messages.
Rob Landley <rob@landley.net>
parents: 719
diff changeset
11 read_arch_dir
114
304fd441e6a4 Re-teach build.sh to build more than one architecture in sequence.
Rob Landley <rob@landley.net>
parents: 108
diff changeset
12 fi
941
7dd3fb4dd333 Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents: 915
diff changeset
13 ARCH="$1"
108
b66d638a3844 Build User Mode Linux and have that do the ext2 packaging (for now, anyway).
Rob Landley <rob@landley.net>
parents: 105
diff changeset
14
984
9840847885e8 Add export_if_blank and make lots of build paths overrideable.
Rob Landley <rob@landley.net>
parents: 944
diff changeset
15 [ -z "$BUILD" ] && BUILD="build"
9840847885e8 Add export_if_blank and make lots of build paths overrideable.
Rob Landley <rob@landley.net>
parents: 944
diff changeset
16
941
7dd3fb4dd333 Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents: 915
diff changeset
17 # A function to skip stages that have already been done (because the
7dd3fb4dd333 Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents: 915
diff changeset
18 # tarball they create is already there).
7dd3fb4dd333 Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents: 915
diff changeset
19
786
8b5ea56e7507 Teach build.sh not to rebuild static compilers if they're already there.
Rob Landley <rob@landley.net>
parents: 785
diff changeset
20 not_already()
8b5ea56e7507 Teach build.sh not to rebuild static compilers if they're already there.
Rob Landley <rob@landley.net>
parents: 785
diff changeset
21 {
984
9840847885e8 Add export_if_blank and make lots of build paths overrideable.
Rob Landley <rob@landley.net>
parents: 944
diff changeset
22 if [ -f "$BUILD/$1-$ARCH.tar.bz2" ]
786
8b5ea56e7507 Teach build.sh not to rebuild static compilers if they're already there.
Rob Landley <rob@landley.net>
parents: 785
diff changeset
23 then
8b5ea56e7507 Teach build.sh not to rebuild static compilers if they're already there.
Rob Landley <rob@landley.net>
parents: 785
diff changeset
24 echo "=== Skipping $1-$ARCH (already there)"
8b5ea56e7507 Teach build.sh not to rebuild static compilers if they're already there.
Rob Landley <rob@landley.net>
parents: 785
diff changeset
25 return 1
8b5ea56e7507 Teach build.sh not to rebuild static compilers if they're already there.
Rob Landley <rob@landley.net>
parents: 785
diff changeset
26 fi
8b5ea56e7507 Teach build.sh not to rebuild static compilers if they're already there.
Rob Landley <rob@landley.net>
parents: 785
diff changeset
27
8b5ea56e7507 Teach build.sh not to rebuild static compilers if they're already there.
Rob Landley <rob@landley.net>
parents: 785
diff changeset
28 return 0
8b5ea56e7507 Teach build.sh not to rebuild static compilers if they're already there.
Rob Landley <rob@landley.net>
parents: 785
diff changeset
29 }
8b5ea56e7507 Teach build.sh not to rebuild static compilers if they're already there.
Rob Landley <rob@landley.net>
parents: 785
diff changeset
30
944
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
31 # Download source code and build host tools.
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
32
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
33 time ./download.sh || exit 1
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
34
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
35 # host-tools populates one directory with every command the build needs,
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
36 # so we can ditch the old $PATH afterwards.
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
37
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
38 time ./host-tools.sh || exit 1
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
39
941
7dd3fb4dd333 Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents: 915
diff changeset
40 # Do we need to build the simple cross compiler?
781
d8c780ed3686 Simplify build.sh to take exactly one argument. (Otherwise use buildall.sh.)
Rob Landley <rob@landley.net>
parents: 744
diff changeset
41
941
7dd3fb4dd333 Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents: 915
diff changeset
42 # This version has no thread support, no libgcc_s.so, doesn't include
7dd3fb4dd333 Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents: 915
diff changeset
43 # uClibc++, and is dynamically linked against the host's shared libraries.
786
8b5ea56e7507 Teach build.sh not to rebuild static compilers if they're already there.
Rob Landley <rob@landley.net>
parents: 785
diff changeset
44
944
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
45 if not_already simple-cross-compiler
781
d8c780ed3686 Simplify build.sh to take exactly one argument. (Otherwise use buildall.sh.)
Rob Landley <rob@landley.net>
parents: 744
diff changeset
46 then
d8c780ed3686 Simplify build.sh to take exactly one argument. (Otherwise use buildall.sh.)
Rob Landley <rob@landley.net>
parents: 744
diff changeset
47 # If we need to build cross compiler, assume root filesystem is stale.
d8c780ed3686 Simplify build.sh to take exactly one argument. (Otherwise use buildall.sh.)
Rob Landley <rob@landley.net>
parents: 744
diff changeset
48
984
9840847885e8 Add export_if_blank and make lots of build paths overrideable.
Rob Landley <rob@landley.net>
parents: 944
diff changeset
49 rm -rf "$BUILD/root-filesystem-$ARCH.tar.bz2"
944
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
50 time ./simple-cross-compiler.sh "$ARCH" || exit 1
781
d8c780ed3686 Simplify build.sh to take exactly one argument. (Otherwise use buildall.sh.)
Rob Landley <rob@landley.net>
parents: 744
diff changeset
51 fi
d8c780ed3686 Simplify build.sh to take exactly one argument. (Otherwise use buildall.sh.)
Rob Landley <rob@landley.net>
parents: 744
diff changeset
52
786
8b5ea56e7507 Teach build.sh not to rebuild static compilers if they're already there.
Rob Landley <rob@landley.net>
parents: 785
diff changeset
53 # Optionally, we can build a statically linked compiler via canadian cross.
784
037488e9889d New build.sh that actually uses the new infrastructure, if STATIC_CROSS_COMPILER_HOST or BUILD_STATIC_NATIVE_COMPILER are set.
Rob Landley <rob@landley.net>
parents: 781
diff changeset
54
037488e9889d New build.sh that actually uses the new infrastructure, if STATIC_CROSS_COMPILER_HOST or BUILD_STATIC_NATIVE_COMPILER are set.
Rob Landley <rob@landley.net>
parents: 781
diff changeset
55 # We don't autodetect the host because i686 is more portable (running on
037488e9889d New build.sh that actually uses the new infrastructure, if STATIC_CROSS_COMPILER_HOST or BUILD_STATIC_NATIVE_COMPILER are set.
Rob Landley <rob@landley.net>
parents: 781
diff changeset
56 # both 64 and 32 bit hosts), but x86_64 is (slightly) faster on a 64 bit host.
037488e9889d New build.sh that actually uses the new infrastructure, if STATIC_CROSS_COMPILER_HOST or BUILD_STATIC_NATIVE_COMPILER are set.
Rob Landley <rob@landley.net>
parents: 781
diff changeset
57
944
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
58 if [ ! -z "$STATIC_CC_HOST" ] && not_already cross-compiler
784
037488e9889d New build.sh that actually uses the new infrastructure, if STATIC_CROSS_COMPILER_HOST or BUILD_STATIC_NATIVE_COMPILER are set.
Rob Landley <rob@landley.net>
parents: 781
diff changeset
59 then
037488e9889d New build.sh that actually uses the new infrastructure, if STATIC_CROSS_COMPILER_HOST or BUILD_STATIC_NATIVE_COMPILER are set.
Rob Landley <rob@landley.net>
parents: 781
diff changeset
60
037488e9889d New build.sh that actually uses the new infrastructure, if STATIC_CROSS_COMPILER_HOST or BUILD_STATIC_NATIVE_COMPILER are set.
Rob Landley <rob@landley.net>
parents: 781
diff changeset
61 # These are statically linked against uClibc on the host (for portability),
037488e9889d New build.sh that actually uses the new infrastructure, if STATIC_CROSS_COMPILER_HOST or BUILD_STATIC_NATIVE_COMPILER are set.
Rob Landley <rob@landley.net>
parents: 781
diff changeset
62 # built --with-shared, and have uClibc++ installed.
037488e9889d New build.sh that actually uses the new infrastructure, if STATIC_CROSS_COMPILER_HOST or BUILD_STATIC_NATIVE_COMPILER are set.
Rob Landley <rob@landley.net>
parents: 781
diff changeset
63
037488e9889d New build.sh that actually uses the new infrastructure, if STATIC_CROSS_COMPILER_HOST or BUILD_STATIC_NATIVE_COMPILER are set.
Rob Landley <rob@landley.net>
parents: 781
diff changeset
64 # To build each of these we need two existing cross compilers: one for
037488e9889d New build.sh that actually uses the new infrastructure, if STATIC_CROSS_COMPILER_HOST or BUILD_STATIC_NATIVE_COMPILER are set.
Rob Landley <rob@landley.net>
parents: 781
diff changeset
65 # the host (to build the executables) and one for the target (to build
037488e9889d New build.sh that actually uses the new infrastructure, if STATIC_CROSS_COMPILER_HOST or BUILD_STATIC_NATIVE_COMPILER are set.
Rob Landley <rob@landley.net>
parents: 781
diff changeset
66 # the libraries).
037488e9889d New build.sh that actually uses the new infrastructure, if STATIC_CROSS_COMPILER_HOST or BUILD_STATIC_NATIVE_COMPILER are set.
Rob Landley <rob@landley.net>
parents: 781
diff changeset
67
944
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
68 BUILD_STATIC=1 FROM_ARCH="$STATIC_CC_HOST" STAGE_NAME=cross-compiler \
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
69 ./native-compiler.sh "$ARCH" || exit 1
784
037488e9889d New build.sh that actually uses the new infrastructure, if STATIC_CROSS_COMPILER_HOST or BUILD_STATIC_NATIVE_COMPILER are set.
Rob Landley <rob@landley.net>
parents: 781
diff changeset
70 fi
037488e9889d New build.sh that actually uses the new infrastructure, if STATIC_CROSS_COMPILER_HOST or BUILD_STATIC_NATIVE_COMPILER are set.
Rob Landley <rob@landley.net>
parents: 781
diff changeset
71
944
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
72 # Build a native compiler. It's statically linked by default so it can be
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
73 # run on an arbitrary host system.
784
037488e9889d New build.sh that actually uses the new infrastructure, if STATIC_CROSS_COMPILER_HOST or BUILD_STATIC_NATIVE_COMPILER are set.
Rob Landley <rob@landley.net>
parents: 781
diff changeset
74
944
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
75 # If this compiler exists, root-filesystem will pick it up and incorpoate it.
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
76
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
77 if not_already native-compiler && [ -z "$NO_NATIVE_COMPILER" ]
784
037488e9889d New build.sh that actually uses the new infrastructure, if STATIC_CROSS_COMPILER_HOST or BUILD_STATIC_NATIVE_COMPILER are set.
Rob Landley <rob@landley.net>
parents: 781
diff changeset
78 then
984
9840847885e8 Add export_if_blank and make lots of build paths overrideable.
Rob Landley <rob@landley.net>
parents: 944
diff changeset
79 rm -rf "$BUILD/root-filesystem-$ARCH.tar.bz2"
784
037488e9889d New build.sh that actually uses the new infrastructure, if STATIC_CROSS_COMPILER_HOST or BUILD_STATIC_NATIVE_COMPILER are set.
Rob Landley <rob@landley.net>
parents: 781
diff changeset
80
944
fc134a13357e Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents: 941
diff changeset
81 BUILD_STATIC={$BUILD_STATIC:-1} ./native-compiler.sh "$ARCH" || exit 1
784
037488e9889d New build.sh that actually uses the new infrastructure, if STATIC_CROSS_COMPILER_HOST or BUILD_STATIC_NATIVE_COMPILER are set.
Rob Landley <rob@landley.net>
parents: 781
diff changeset
82 fi
037488e9889d New build.sh that actually uses the new infrastructure, if STATIC_CROSS_COMPILER_HOST or BUILD_STATIC_NATIVE_COMPILER are set.
Rob Landley <rob@landley.net>
parents: 781
diff changeset
83
781
d8c780ed3686 Simplify build.sh to take exactly one argument. (Otherwise use buildall.sh.)
Rob Landley <rob@landley.net>
parents: 744
diff changeset
84 # Do we need to build the root filesystem?
539
85979aa53fde Teach build.sh not to rerun build stages we already have the result of.
Rob Landley <rob@landley.net>
parents: 503
diff changeset
85
786
8b5ea56e7507 Teach build.sh not to rebuild static compilers if they're already there.
Rob Landley <rob@landley.net>
parents: 785
diff changeset
86 if not_already root-filesystem
781
d8c780ed3686 Simplify build.sh to take exactly one argument. (Otherwise use buildall.sh.)
Rob Landley <rob@landley.net>
parents: 744
diff changeset
87 then
786
8b5ea56e7507 Teach build.sh not to rebuild static compilers if they're already there.
Rob Landley <rob@landley.net>
parents: 785
diff changeset
88
781
d8c780ed3686 Simplify build.sh to take exactly one argument. (Otherwise use buildall.sh.)
Rob Landley <rob@landley.net>
parents: 744
diff changeset
89 # If we need to build root filesystem, assume system image is stale.
539
85979aa53fde Teach build.sh not to rerun build stages we already have the result of.
Rob Landley <rob@landley.net>
parents: 503
diff changeset
90
984
9840847885e8 Add export_if_blank and make lots of build paths overrideable.
Rob Landley <rob@landley.net>
parents: 944
diff changeset
91 rm -rf "$BUILD/system-image-$ARCH.tar.bz2"
786
8b5ea56e7507 Teach build.sh not to rebuild static compilers if they're already there.
Rob Landley <rob@landley.net>
parents: 785
diff changeset
92 time ./root-filesystem.sh "$ARCH" || exit 1
781
d8c780ed3686 Simplify build.sh to take exactly one argument. (Otherwise use buildall.sh.)
Rob Landley <rob@landley.net>
parents: 744
diff changeset
93 fi
d8c780ed3686 Simplify build.sh to take exactly one argument. (Otherwise use buildall.sh.)
Rob Landley <rob@landley.net>
parents: 744
diff changeset
94
786
8b5ea56e7507 Teach build.sh not to rebuild static compilers if they're already there.
Rob Landley <rob@landley.net>
parents: 785
diff changeset
95 if not_already system-image
781
d8c780ed3686 Simplify build.sh to take exactly one argument. (Otherwise use buildall.sh.)
Rob Landley <rob@landley.net>
parents: 744
diff changeset
96 then
d8c780ed3686 Simplify build.sh to take exactly one argument. (Otherwise use buildall.sh.)
Rob Landley <rob@landley.net>
parents: 744
diff changeset
97 time ./system-image.sh $1 || exit 1
d8c780ed3686 Simplify build.sh to take exactly one argument. (Otherwise use buildall.sh.)
Rob Landley <rob@landley.net>
parents: 744
diff changeset
98 fi
786
8b5ea56e7507 Teach build.sh not to rebuild static compilers if they're already there.
Rob Landley <rob@landley.net>
parents: 785
diff changeset
99