tazwok view chroot-scripts/cook-toolchain @ rev 473

cook-toolchain: define stuff var
author Antoine Bodin <gokhlayeh@slitaz.org>
date Sat Apr 02 14:51:52 2011 +0200 (2011-04-02)
parents 3739ea8e2175
children 789cd6566f3a 70c7cb6c0956
line source
1 #!/bin/bash
2 #
3 # An attempt to cook a new toolchain from scratch.
5 # Important settings and variables.
6 source /usr/lib/slitaz/libtaz
7 source /etc/slitaz/tazwok.conf
9 # Report progress on webserver.
10 log_step="$LOCAL_REPOSITORY/log/step"
11 run_on_exit="$run_on_exit
12 rm -f $LOCAL_REPOSITORY/log/step
13 rm -f $LOCAL_REPOSITORY/log/package"
15 source_lib report
16 report start
18 report step "Cooking temporary toolchain"
19 report open-bloc
21 report step "Configuring repositories"
22 # Incoming packages as the only source for packages.
23 rm -r /var/lib/tazpkg/undigest
24 tazpkg setup-mirror $SLITAZ_DIR/${undigest:-$SLITAZ_VERSION}/packages-incoming
25 tazpkg recharge
27 report step "Refreshing SliTaz tools"
28 report open-bloc
29 # These four packages will be needed later.
30 for p in libtaz tazwok slitaz-base-files tazpkg; do
31 tazwok cook $p
32 done
33 report close-bloc
35 report step "Setting up environnement"
36 set +h
37 umask 022
38 PS1='\u:\w\$ '
39 LANG=POSIX
40 LC_ALL=POSIX
42 # Set BUILD_HOST to something like $ARCH-tmp-linux-gnu to enable
43 # the temporary toolchain.
44 BUILD_HOST=$(echo $BUILD_HOST | sed 's/\(.*\)-\(.*\)-linux-gnu/\1-tmp-linux-gnu/')
46 PATH=/tools/bin:/tools/usr/bin:/tools/sbin:/tools/usr/sbin:/bin:/usr/bin:/sbin:/usr/sbin
47 CONFIG_SITE="/etc/config.site.tmptoolchain"
48 echo 'prefix=/tools' > /etc/config.site.tmptoolchain
50 export LANG LC_ALL PATH PS1 MAKEFLAGS CONFIG_SITE
51 unset CC CXX CPP CFLAGS CXXFLAGS LD_LIBRARY_PATH LD_PRELOAD DESTDIR
53 LOCAL_REPOSITORY=$SLITAZ_DIR/$SLITAZ_VERSION
54 [ "$undigest" ] && LOCAL_REPOSITORY=$SLITAZ_DIR/$undigest
55 WOK=$LOCAL_REPOSITORY/wok
57 # Create the dir for the temporary toolchain and link in root of host
58 # system.
59 rm -rf /tools
60 mkdir /tools
62 report end-step
64 # Use some tweaked code from tazwok.
65 prepare_package()
66 {
67 tazwok clean $PACKAGE
68 tazwok get-src $PACKAGE
69 unset SOURCE VERSION EXTRAVERSION CATEGORY SHORT_DESC \
70 MAINTAINER WEB_SITE WGET_URL DEPENDS BUILD_DEPENDS WANTED
71 . $WOK/$PACKAGE/receipt
72 src=$WOK/$PACKAGE/$PACKAGE-$VERSION
73 stuff=$WOK/$PACKAGE/stuff
74 [ "$WANTED" ] && wanted_stuff=$WOK/$WANTED/stuff
75 cd $WOK/$PACKAGE
76 }
78 # Binutils and gcc need to be compiled twice.
79 for PACKAGE in binutils gcc; do
80 rm $LOCAL_REPOSITORY/log/tmp-toolchain-$PACKAGE-firstpass.html 2>/dev/null
81 report sublog $LOCAL_REPOSITORY/log/tmp-toolchain-$PACKAGE-firstpass.html
82 echo "tmp-toolchain-$PACKAGE-firstpass" > $LOCAL_REPOSITORY/log/package
83 report step "Compiling $PACKAGE, first pass"
84 report open-bloc
85 prepare_package
86 report step "Running compilation rules"
87 precook_tmp_toolchain
88 report end-step || exit 1
89 report close-bloc
90 report end-sublog
91 done
93 # Compile temporary toolchain using the $TOOLCHAIN variable.
94 for PACKAGE in $SLITAZ_TOOLCHAIN; do
95 rm $LOCAL_REPOSITORY/log/tmp-toolchain-$PACKAGE.html 2>/dev/null
96 report sublog $LOCAL_REPOSITORY/log/tmp-toolchain-$PACKAGE.html
97 echo "tmp-toolchain-$PACKAGE" > $LOCAL_REPOSITORY/log/package
98 report step "Compiling $PACKAGE"
99 report open-bloc
100 prepare_package
101 report step "Running compilation rules"
103 # Use compile_rules if there's no function cook_tmp_toolchain in
104 # the receipt. Works well if both functions are the same, as
105 # cook-toolchain uses its own config.site to set different default
106 # paths.
107 if grep -q ^cook_tmp_toolchain\(\)$ $WOK/$PACKAGE/receipt; then
108 cook_tmp_toolchain
109 else
110 compile_rules
111 fi
113 report end-step || exit 1
114 report close-bloc
115 report end-sublog
116 done
118 # Now we erase previous chroot tools and switch to temporary
119 # toolchain.
121 report step "Setting up temporary toolchain environnment"
123 PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin:/tools/usr/bin:/tools/sbin:/tools/usr/sbin
124 export PATH
126 # Ajout manuel de libtaz et tazwok dans ce chroot.
127 cp -a /etc/slitaz/tazpkg.conf /tmp/tazpkg.conf
128 mkdir -p /tmp/backup/var/lib/tazpkg
129 sed 's/^AUTO_INSTALL_DEPS="yes"/AUTO_INSTALL_DEPS="no"/' -i \
130 /etc/slitaz/tazpkg.conf
131 BASE_PKGS="tazpkg tazwok slitaz-base-files libtaz"
132 for i in $BASE_PKGS; do
133 echo N | tazpkg get-install $i --root=/tmp/backup --forced
134 done
135 mkdir -p /tmp/backup/var/log/slitaz /tmp/backup/etc/slitaz
136 if [ -d /var/log/slitaz ]; then
137 cp -a /var/log/slitaz/* /tmp/backup/var/log/slitaz
138 fi
139 cp -a /var/lib/tazpkg/* /tmp/backup/var/lib/tazpkg
140 cp -a /etc/slitaz/* /tmp/backup/etc/slitaz
141 cp -a /tmp/tazpkg.conf /tmp/backup/etc/slitaz
142 cp -a /etc/resolv.conf /tmp/backup/etc
144 # Switch to temp toolchain tools entirely.
145 rm -r /bin /etc /lib /sbin /usr /var
146 cp -a /tmp/backup/* /
147 rm -r /tmp/backup
149 case $ARCH in
150 x86_64) ln -sv lib /lib64 && ln -sv lib /usr/lib64 ;;
151 esac
153 mkdir -p /bin /usr/bin /usr/lib
154 # Doing a loop so we don't get {bash,cat,echo,pwd,stty} softlink
155 BASIC_APPS="bash cat echo pwd stty"
156 for i in $BASIC_APPS; do
157 ln -s /tools/bin/$i /bin/$i
158 done
159 BASIC_LIBS="libgcc_s.so libgcc_s.so.1 libstdc++.so libstdc++.so.6"
160 for i in $BASIC_LIBS; do
161 ln -sf /tools/lib/$i /usr/lib/$i
162 done
164 ln -s /tools/bin/perl /usr/bin
165 ln -s /tools/bin/gettext.sh /usr/bin
166 ln -s /tools/bin/busybox /bin/sh
168 report end-step
170 # Finally, cook final* version of the toolchain packages.
171 # * : recook toolchain against itself minus linux-api-headers
172 # glibc binutils & gcc can be a good idea to make things
173 # more robust & stable; in some cases it solves dependency
174 # loops.
176 # Get toolchain cooklist.
177 tazwok gen-cooklist ${undigest:+--undigest=$undigest} > /tmp/toolchain.list
179 # Next cook packages one by one.
180 # Cooking the list doesn't work because sh won't take care
181 # of the presence of new executables even if they're first in
182 # $PATH.
184 cat /tmp/toolchain.list | while read PACKAGE; do
185 tazwok cook $PACKAGE || exit 1
186 done