Quellen-Update
[ipfire-2.x.git] / make.sh
1 #!/bin/bash
2 #
3 ############################################################################
4 #                                                                          #
5 # This file is part of the IPCop Firewall.                                 #
6 #                                                                          #
7 # IPCop is free software; you can redistribute it and/or modify            #
8 # it under the terms of the GNU General Public License as published by     #
9 # the Free Software Foundation; either version 2 of the License, or        #
10 # (at your option) any later version.                                      #
11 #                                                                          #
12 # IPCop is distributed in the hope that it will be useful,                 #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of           #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            #
15 # GNU General Public License for more details.                             #
16 #                                                                          #
17 # You should have received a copy of the GNU General Public License        #
18 # along with IPCop; if not, write to the Free Software                     #
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA #
20 #                                                                          #
21 # Copyright (C) 2001 Mark Wormgoor <mark@wormgoor.com>.                    #
22 #                                                                          #
23 # (c) 2001 Eric S. Johansson <esj@harvee.billerica.ma.us> Check for Bash   #
24 # (c) 2002 Thorsten Fischer <frosch@cs.tu-berlin.de> MD5Sum checking       #
25 #                                                                          #
26 ############################################################################
27 #
28 # $Id: make.sh,v 1.129.2.145 2006/02/01 07:04:09 gespinasse Exp $
29 #
30
31   NAME="IPFire"                                 # Software name
32   SNAME="ipfire"                                        # Short name
33   VERSION="1.4"                         # Version number
34   PREVIOUSTAG=IPCOP_v1_4_10_FINAL
35   SLOGAN="We save your network"         # Software slogan
36   CONFIG_ROOT=/var/ipfire                       # Configuration rootdir
37   NICE=10
38   MAX_RETRIES=3                                 # prefetch/check loop
39   KVER=`grep --max-count=1 VER lfs/linux | awk '{ print $3 }'`
40   MACHINE=`uname -m`
41
42   # Debian specific settings
43   if [ ! -e /etc/debian_version ]; then
44         FULLPATH=`which $0`
45   else
46         if [ -x /usr/bin/realpath ]; then
47                 FULLPATH=`/usr/bin/realpath $0`
48         else
49                 echo "ERROR: Need to do apt-get install realpath"
50                 exit 1
51         fi
52   fi
53
54
55   PWD=`pwd`
56   BASENAME=`basename $0`
57   BASEDIR=`echo $FULLPATH | sed "s/\/$BASENAME//g"`
58   LOGFILE=$BASEDIR/log/_build.preparation.log
59   export BASEDIR LOGFILE
60   DIR_CHK=$BASEDIR/cache/check
61   mkdir $BASEDIR/log/ 2>/dev/null
62
63   if [ 'x86_64' = $MACHINE -o 'i686' = $MACHINE -o 'i586' = $MACHINE -o 'i486' = $MACHINE -o 'i386' = $MACHINE ]; then
64         echo "`date -u '+%b %e %T'`: Machine is ix86 (or equivalent)" | tee -a $LOGFILE
65         MACHINE=i386
66         BUILDTARGET=i386-pc-linux-gnu
67         CFLAGS="-O2 -mcpu=i386 -march=i386 -pipe -fomit-frame-pointer"
68         CXXFLAGS="-O2 -mcpu=i386 -march=i386 -pipe -fomit-frame-pointer"
69   elif [ 'alpha' = $MACHINE ]; then
70         echo "`date -u '+%b %e %T'`: Machine is Alpha AXP" | tee -a $LOGFILE
71         BUILDTARGET=alpha-unknown-linux-gnu
72         CFLAGS="-O2 -mcpu=ev4 -mieee -pipe"
73         CXXFLAGS="-O2 -mcpu=ev4 -mieee -pipe"
74   else
75         echo "`date -u '+%b %e %T'`: Can't determine your architecture - $MACHINE" | tee -a $LOGFILE
76         exit 1
77   fi
78
79 # Define immediately
80 stdumount() {
81         umount $BASEDIR/build/dev/pts           2>/dev/null;
82         umount $BASEDIR/build/proc              2>/dev/null;
83         umount $BASEDIR/build/install/mnt       2>/dev/null;
84         umount $BASEDIR/build/usr/src/cache     2>/dev/null;
85         umount $BASEDIR/build/usr/src/ccache    2>/dev/null;
86         umount $BASEDIR/build/usr/src/config    2>/dev/null;
87         umount $BASEDIR/build/usr/src/doc       2>/dev/null;
88         umount $BASEDIR/build/usr/src/html      2>/dev/null;
89         umount $BASEDIR/build/usr/src/langs     2>/dev/null;
90         umount $BASEDIR/build/usr/src/lfs       2>/dev/null;
91         umount $BASEDIR/build/usr/src/log       2>/dev/null;
92         umount $BASEDIR/build/usr/src/src       2>/dev/null;
93 }
94
95 exiterror() {
96         stdumount
97         for i in `seq 0 7`; do
98             if ( losetup /dev/loop${i} 2>/dev/null | grep -q "/install/images" ); then
99                 losetup -d /dev/loop${i} 2>/dev/null
100             fi;
101         done
102         echo "ERROR: $*"
103         echo "       Check $LOGFILE for errors if applicable"
104         exit 1
105 }
106
107 entershell() {
108         if [ ! -e $BASEDIR/build/usr/src/lfs/ ]; then
109                 exiterror "No such file or directory: $BASEDIR/build/usr/src/lfs/"
110         fi
111         echo "Entering to a shell inside LFS chroot, go out with exit"
112         chroot $LFS /tools/bin/env -i HOME=/root TERM=$TERM PS1='\u:\w\$ ' \
113                 PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
114                 VERSION=$VERSION CONFIG_ROOT=$CONFIG_ROOT \
115                 NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \
116                 CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" \
117                 CCACHE_DIR=/usr/src/ccache \
118                 CCACHE_HASHDIR=1 \
119                 KVER=$KVER \
120                 BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \
121                 KGCC="ccache /usr/bin/gcc" \
122                 /tools/bin/bash
123         if [ $? -ne 0 ]; then
124                         exiterror "chroot error"
125         else
126                 stdumount
127         fi
128 }
129
130 prepareenv() {
131     ############################################################################
132     #                                                                          #
133     # Are we running the right shell?                                          #
134     #                                                                          #
135     ############################################################################
136     if [ ! "$BASH" ]; then
137         exiterror "BASH environment variable is not set.  You're probably running the wrong shell."
138     fi
139
140     if [ -z "${BASH_VERSION}" ]; then
141         exiterror "Not running BASH shell."
142     fi
143
144
145     ############################################################################
146     #                                                                          #
147     # Trap on emergency exit                                                   #
148     #                                                                          #
149     ############################################################################
150     trap "exiterror 'Build process interrupted'" SIGINT SIGTERM SIGKILL SIGSTOP SIGQUIT
151
152
153     ############################################################################
154     #                                                                          #
155     # Resetting our nice level                                                 #
156     #                                                                          #
157     ############################################################################
158     echo "`date -u '+%b %e %T'`: Resetting our nice level to $NICE" | tee -a $LOGFILE
159     renice $NICE $$ > /dev/null
160     if [ `nice` != "$NICE" ]; then
161         exiterror "Failed to set correct nice level"
162     fi
163
164     ############################################################################
165     #                                                                          #
166     # Checking if running as root user                                         #
167     #                                                                          #
168     ############################################################################
169     echo "`date -u '+%b %e %T'`: Checking if we're running as root user" | tee -a $LOGFILE
170     if [ `id -u` != 0 ]; then
171         exiterror "Not building as root"
172     fi
173
174
175     ############################################################################
176     #                                                                          #
177     # Checking for necessary temporary space                                   #
178     #                                                                          #
179     ############################################################################
180     echo "`date -u '+%b %e %T'`: Checking for necessary space on disk $BASE_DEV" | tee -a $LOGFILE
181     BASE_DEV=`df -P -k $BASEDIR | tail -n 1 | awk '{ print $1 }'`
182     BASE_ASPACE=`df -P -k $BASEDIR | tail -n 1 | awk '{ print $4 }'`
183     if (( 2202000 > $BASE_ASPACE )); then
184         BASE_USPACE=`du -skx $BASEDIR | awk '{print $1}'`
185         if (( 2202000 - $BASE_USPACE > $BASE_ASPACE )); then
186                 exiterror "Not enough temporary space available, need at least 2.1GB on $BASE_DEV"
187         fi
188     fi
189
190     ############################################################################
191     #                                                                          #
192     # Building Linux From Scratch system                                       #
193     #                                                                          #
194     ############################################################################
195     echo "`date -u '+%b %e %T'`: Building Linux From Scratch system" | tee -a $LOGFILE
196
197     # Set umask
198     umask 022
199
200     # Set LFS Directory
201     LFS=$BASEDIR/build
202
203     # Check /tools symlink
204     if [ -h /tools ]; then
205         rm -f /tools
206     fi
207     if [ ! -a /tools ]; then
208         ln -s $BASEDIR/build/tools /
209     fi
210     if [ ! -h /tools ]; then
211         exiterror "Could not create /tools symbolic link."
212     fi
213
214     # Setup environment
215     set +h
216     LC_ALL=POSIX
217     export LFS LC_ALL CFLAGS CXXFLAGS
218     unset CC CXX CPP LD_LIBRARY_PATH LD_PRELOAD
219
220     # Make some extra directories
221     mkdir -p $BASEDIR/build/{tools,etc,usr/src} 2>/dev/null
222     mkdir -p $BASEDIR/{cache,ccache} 2>/dev/null
223     mkdir -p $BASEDIR/build/dev/pts $BASEDIR/build/proc $BASEDIR/build/usr/src/{cache,config,doc,html,langs,lfs,log,src,ccache}
224
225     # Make all sources and proc available under lfs build
226     mount --bind /dev/pts        $BASEDIR/build/dev/pts
227     mount --bind /proc           $BASEDIR/build/proc
228     mount --bind $BASEDIR/cache  $BASEDIR/build/usr/src/cache
229     mount --bind $BASEDIR/ccache $BASEDIR/build/usr/src/ccache
230     mount --bind $BASEDIR/config $BASEDIR/build/usr/src/config
231     mount --bind $BASEDIR/doc    $BASEDIR/build/usr/src/doc
232     mount --bind $BASEDIR/html   $BASEDIR/build/usr/src/html
233     mount --bind $BASEDIR/langs  $BASEDIR/build/usr/src/langs
234     mount --bind $BASEDIR/lfs    $BASEDIR/build/usr/src/lfs
235     mount --bind $BASEDIR/log    $BASEDIR/build/usr/src/log
236     mount --bind $BASEDIR/src    $BASEDIR/build/usr/src/src
237
238     # Run LFS static binary creation scripts one by one
239     export CCACHE_DIR=$BASEDIR/ccache
240     export CCACHE_HASHDIR=1
241
242     # Remove pre-install list of installed files in case user erase some files before rebuild
243     rm -f $BASEDIR/build/usr/src/lsalr 2>/dev/null
244 }
245
246
247 ############################################################################
248 #                                                                          #
249 # Necessary shell functions                                                #
250 #                                                                          #
251 ############################################################################
252 lfsmake1() {
253         if [ -f $BASEDIR/lfs/$1 ]; then
254                 echo "`date -u '+%b %e %T'`: Building $*" | tee -a $LOGFILE
255                 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MESSAGE="$1\t " download  >> $LOGFILE 2>&1
256                 if [ $? -ne 0 ]; then
257                         exiterror "Download error in $1"
258                 fi
259                 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MESSAGE="$1\t md5sum" md5  >> $LOGFILE 2>&1
260                 if [ $? -ne 0 ]; then
261                         exiterror "md5sum error in $1, check file in cache or signature"
262                 fi
263                 cd $BASEDIR/lfs && make -f $*   BUILDTARGET=$BUILDTARGET \
264                                                 MACHINE=$MACHINE \
265                                                 LFS_BASEDIR=$BASEDIR \
266                                                 ROOT=$LFS \
267                                                 KVER=$KVER \
268                                                 install >> $LOGFILE 2>&1
269                 if [ $? -ne 0 ]; then
270                         exiterror "Building $*";
271                 fi
272         else
273                 exiterror "No such file or directory: $BASEDIR/$1"
274         fi
275         return 0
276 }
277
278 lfsmake2() {
279         if [ -f $BASEDIR/build/usr/src/lfs/$1 ]; then
280                 echo "`date -u '+%b %e %T'`: Building $*" | tee -a $LOGFILE
281                 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MESSAGE="$1\t " download  >> $LOGFILE 2>&1
282                 if [ $? -ne 0 ]; then
283                         exiterror "Download error in $1"
284                 fi
285                 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MESSAGE="$1\t md5sum" md5  >> $LOGFILE 2>&1
286                 if [ $? -ne 0 ]; then
287                         exiterror "md5sum error in $1, check file in cache or signature"
288                 fi
289                 chroot $LFS /tools/bin/env -i   HOME=/root \
290                                                 TERM=$TERM PS1='\u:\w\$ ' \
291                                                 PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
292                                                 VERSION=$VERSION \
293                                                 CONFIG_ROOT=$CONFIG_ROOT \
294                                                 NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \
295                                                 CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" \
296                                                 CCACHE_DIR=/usr/src/ccache CCACHE_HASHDIR=1 \
297                                                 KVER=$KVER \
298                                                 BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \
299                     /tools/bin/bash -x -c "cd /usr/src/lfs && \
300                     make -f $* LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1
301                 if [ $? -ne 0 ]; then
302                         exiterror "Building $*"
303                 fi
304         else
305                 exiterror "No such file or directory: $BASEDIR/build/usr/src/lfs/$1"
306         fi
307         return 0
308 }
309
310 ipcopmake() {
311         if [ -f $BASEDIR/build/usr/src/lfs/$1 ]; then
312                 echo "`date -u '+%b %e %T'`: Building $*" | tee -a $LOGFILE
313                 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MESSAGE="$1\t " download  >> $LOGFILE 2>&1
314                 if [ $? -ne 0 ]; then
315                         exiterror "Download error in $1"
316                 fi
317                 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MESSAGE="$1\t md5sum" md5  >> $LOGFILE 2>&1
318                 if [ $? -ne 0 ]; then
319                         exiterror "md5sum error in $1, check file in cache or signature"
320                 fi
321                 chroot $LFS /tools/bin/env -i   HOME=/root \
322                                                 TERM=$TERM PS1='\u:\w\$ ' \
323                                                 PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin \
324                                                 VERSION=$VERSION \
325                                                 CONFIG_ROOT=$CONFIG_ROOT \
326                                                 NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \
327                                                 CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" \
328                                                 CCACHE_DIR=/usr/src/ccache CCACHE_HASHDIR=1 \
329                                                 KVER=$KVER \
330                                                 BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \
331                     /bin/bash -x -c "cd /usr/src/lfs && \
332                     make -f $* LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1
333                 if [ $? -ne 0 ]; then
334                         exiterror "Building $*"
335                 fi
336         else
337                 exiterror "No such file or directory: $BASEDIR/build/usr/src/lfs/$1"
338         fi
339         return 0
340 }
341
342
343 installmake() {
344         if [ -f $BASEDIR/build/usr/src/lfs/$1 ]; then
345                 echo "`date -u '+%b %e %T'`: Building $*" | tee -a $LOGFILE
346                 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MESSAGE="$1\t " download  >> $LOGFILE 2>&1
347                 if [ $? -ne 0 ]; then
348                         exiterror "Download error in $1"
349                 fi
350                 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR MESSAGE="$1\t md5sum" md5  >> $LOGFILE 2>&1
351                 if [ $? -ne 0 ]; then
352                         exiterror "md5sum error in $1, check file in cache or signature"
353                 fi
354                 chroot $LFS /tools/bin/env -i   HOME=/root \
355                                                 TERM=$TERM PS1='\u:\w\$ ' \
356                                                 PATH=/usr/local/bin:/opt/$MACHINE-uClibc/usr/bin:/bin:/usr/bin:/sbin:/usr/sbin \
357                                                 VERSION=$VERSION \
358                                                 CONFIG_ROOT=$CONFIG_ROOT \
359                                                 LFS_PASS="install" \
360                                                 NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \
361                                                 CFLAGS="-Os" CXXFLAGS="-Os" \
362                                                 CCACHE_DIR=/usr/src/ccache CCACHE_HASHDIR=1 \
363                                                 KVER=$KVER \
364                                                 BUILDTARGET="$BUILDTARGET" MACHINE="$MACHINE" \
365                     /bin/bash -x -c "cd /usr/src/lfs && \
366                     make -f $* LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1
367                 if [ $? -ne 0 ]; then
368                         exiterror "Building $*"
369                 fi
370         else
371                 exiterror "No such file or directory: $BASEDIR/build/usr/src/lfs/$1"
372         fi
373         return 0
374 }
375
376 buildtoolchain() {
377     LOGFILE="$BASEDIR/log/_build.toolchain.log"
378     export LOGFILE
379     echo -ne "`date -u '+%b %e %T'`: Stage1 toolchain build \n" | tee -a $LOGFILE
380     # Build sed now, as we use some extensions
381     ORG_PATH=$PATH
382     NATIVEGCC=`gcc --version | grep GCC | awk {'print $3'}`
383     export NATIVEGCC GCCmajor=${NATIVEGCC:0:1} GCCminor=${NATIVEGCC:2:1} GCCrelease=${NATIVEGCC:4:1}
384     lfsmake1 ccache
385     lfsmake1 sed        LFS_PASS=1
386     lfsmake1 m4         LFS_PASS=1
387     lfsmake1 bison      LFS_PASS=1
388     lfsmake1 flex       LFS_PASS=1
389     lfsmake1 binutils   LFS_PASS=1
390     lfsmake1 gcc        LFS_PASS=1
391     export PATH=$BASEDIR/build/usr/local/bin:$BASEDIR/build/tools/bin:$PATH
392     
393     lfsmake1 linux
394     lfsmake1 tcl
395     lfsmake1 expect
396     lfsmake1 glibc
397     lfsmake1 dejagnu
398     lfsmake1 gcc        LFS_PASS=2
399     lfsmake1 binutils   LFS_PASS=2
400     lfsmake1 gawk
401     lfsmake1 coreutils
402     lfsmake1 bzip2
403     lfsmake1 gzip
404     lfsmake1 diffutils
405     lfsmake1 findutils
406     lfsmake1 make
407     lfsmake1 grep
408     lfsmake1 sed        LFS_PASS=2
409     lfsmake1 m4         LFS_PASS=2
410     lfsmake1 bison      LFS_PASS=2
411     lfsmake1 flex       LFS_PASS=2
412     lfsmake1 gettext
413     lfsmake1 ncurses
414     lfsmake1 patch
415     lfsmake1 tar
416     lfsmake1 texinfo
417     lfsmake1 bash
418     lfsmake1 util-linux
419     lfsmake1 perl
420     export PATH=$ORG_PATH
421 }
422
423 buildbase() {
424     LOGFILE="$BASEDIR/log/_build.base.log"
425     export LOGFILE
426     echo -ne "`date -u '+%b %e %T'`: Stage2 linux base build \n" | tee -a $LOGFILE
427     # Run LFS dynamic binary creation scripts one by one
428     lfsmake2 stage2
429     lfsmake2 makedev
430     lfsmake2 linux
431     lfsmake2 man-pages
432     lfsmake2 glibc
433     lfsmake2 binutils
434     lfsmake2 gcc
435     lfsmake2 coreutils
436     lfsmake2 zlib
437     lfsmake2 mktemp
438     lfsmake2 iana-etc
439     lfsmake2 findutils
440     lfsmake2 gawk
441     lfsmake2 ncurses
442     lfsmake2 vim
443     lfsmake2 m4
444     lfsmake2 bison
445     lfsmake2 less
446     lfsmake2 groff
447     lfsmake2 sed
448     lfsmake2 flex
449     lfsmake2 gettext
450     lfsmake2 net-tools
451     lfsmake2 inetutils
452     lfsmake2 perl
453     lfsmake2 texinfo
454     lfsmake2 autoconf
455     lfsmake2 automake
456     lfsmake2 bash
457     lfsmake2 file
458     lfsmake2 libtool
459     lfsmake2 bzip2
460     lfsmake2 diffutils
461     lfsmake2 ed
462     lfsmake2 kbd
463     lfsmake2 e2fsprogs
464     lfsmake2 grep
465     if [ 'i386' = $MACHINE ]; then 
466         lfsmake2 grub
467     elif [ 'alpha' = $MACHINE ]; then 
468         lfsmake2 aboot
469     fi
470     lfsmake2 gzip
471     lfsmake2 man
472     lfsmake2 make
473     lfsmake2 modutils
474     lfsmake2 patch
475     lfsmake2 procinfo
476     lfsmake2 procps
477     lfsmake2 psmisc
478     lfsmake2 shadow
479     lfsmake2 sysklogd
480     lfsmake2 sysvinit
481     lfsmake2 tar
482     lfsmake2 util-linux
483 }
484
485 buildipcop() {
486   # Run IPCop make scripts one by one
487   LOGFILE="$BASEDIR/log/_build.ipcop.log"
488   export LOGFILE
489   echo -ne "`date -u '+%b %e %T'`: Stage3 $NAME build \n" | tee -a $LOGFILE
490
491   # Build these first as some of the kernel packages below rely on 
492   # these for some of their client program functionality 
493   ipcopmake configroot
494   ipcopmake dhcp
495   ipcopmake dhcpcd
496   ipcopmake libusb
497   ipcopmake libpcap
498   ipcopmake linux-atm
499   ipcopmake ppp
500   ipcopmake rp-pppoe
501   ipcopmake unzip
502   # Do SMP now
503   if [ 'i386' = $MACHINE ]; then 
504         # abuse the SMP flag, and make an minimal installer kernel first
505         # so that the boot floppy always works.....
506         ipcopmake linux         LFS_PASS=ipcop SMP=installer
507         ipcopmake linux         LFS_PASS=ipcop SMP=1
508         ipcopmake 3cp4218       SMP=1
509         ipcopmake amedyn        SMP=1
510         ipcopmake cxacru        SMP=1
511         ipcopmake eagle         SMP=1
512
513         # These are here because they have i386 only binary libraries
514         # included in the package.
515         ipcopmake cnx_pci       SMP=1
516         ipcopmake fcdsl         SMP=1
517         ipcopmake fcdsl2        SMP=1
518         ipcopmake fcdslsl       SMP=1
519         ipcopmake fcdslusb      SMP=1
520         ipcopmake fcdslslusb    SMP=1
521         ipcopmake pulsar        SMP=1
522         ipcopmake unicorn       SMP=1
523   fi
524
525   ipcopmake linux       LFS_PASS=ipcop
526   ipcopmake 3cp4218     
527   ipcopmake amedyn      
528   ipcopmake cxacru      
529   ipcopmake eciadsl     
530   ipcopmake eagle       
531   ipcopmake speedtouch  
532   if [ 'i386' = $MACHINE ]; then 
533         # These are here because they have i386 only binary libraries
534         # included in the package.
535         ipcopmake cnx_pci       
536         ipcopmake fcdsl         
537         ipcopmake fcdsl2        
538         ipcopmake fcdslsl       
539         ipcopmake fcdslusb      
540         ipcopmake fcdslslusb    
541         ipcopmake pulsar        
542         ipcopmake unicorn       
543   fi
544
545   ipcopmake pcmcia-cs
546   ipcopmake expat
547   ipcopmake gdbm
548   ipcopmake gmp
549   ipcopmake openssl
550   ipcopmake python
551   ipcopmake libnet
552   ipcopmake libpng
553   ipcopmake gd
554   ipcopmake popt
555   ipcopmake slang
556   ipcopmake newt
557   ipcopmake libcap
558   ipcopmake pciutils
559   ipcopmake pcre
560   ipcopmake apache
561   ipcopmake arping
562   ipcopmake beep
563   ipcopmake bind
564   ipcopmake capi4k-utils
565   ipcopmake cdrtools
566   ipcopmake dnsmasq
567   ipcopmake dosfstools
568   ipcopmake ethtool
569   ipcopmake ez-ipupdate
570   ipcopmake fcron
571   ipcopmake GD
572   ipcopmake gnupg
573   ipcopmake hdparm
574   ipcopmake ibod
575   ipcopmake initscripts
576   ipcopmake iptables
577   ipcopmake ipac-ng
578   ipcopmake ipaddr
579   ipcopmake iproute2
580   ipcopmake iptstate
581   ipcopmake iputils
582   ipcopmake isapnptools
583   ipcopmake isdn4k-utils
584   ipcopmake kudzu
585   ipcopmake logrotate
586   ipcopmake logwatch
587   ipcopmake mingetty
588   ipcopmake misc-progs
589   ipcopmake mtools
590   ipcopmake nano
591   ipcopmake nash
592   ipcopmake nasm
593   ipcopmake URI
594   ipcopmake HTML-Tagset
595   ipcopmake HTML-Parser
596   ipcopmake Compress-Zlib
597   ipcopmake Digest
598   ipcopmake Digest-SHA1
599   ipcopmake Digest-HMAC
600   ipcopmake libwww-perl
601   ipcopmake Net-DNS
602   ipcopmake Net-IPv4Addr
603   ipcopmake Net_SSLeay
604   ipcopmake noip_updater
605   ipcopmake ntp
606   ipcopmake oinkmaster
607   ipcopmake openssh
608   ipcopmake openswan
609   ipcopmake pptpclient
610   ipcopmake rrdtool
611   ipcopmake setserial
612   ipcopmake setup
613   ipcopmake snort
614   #ipcopmake speedycgi
615   ipcopmake squid
616   ipcopmake squid-graph
617   ipcopmake tcpdump
618   ipcopmake traceroute
619   ipcopmake vlan
620   ipcopmake wireless
621   ipcopmake libsafe
622   ipcopmake 3c5x9setup
623   ipcopmake stund
624   ipcopmake lpd
625   ipcopmake xampp
626   ipcopmake pam
627 }
628
629 buildinstaller() {
630   # Run installer scripts one by one
631   LOGFILE="$BASEDIR/log/_build.installer.log"
632   export LOGFILE
633   echo -ne "`date -u '+%b %e %T'`: Stage4 installer build \n" | tee -a $LOGFILE
634   if [ 'i386' = $MACHINE ]; then 
635         ipcopmake syslinux
636         ipcopmake as86
637         ipcopmake mbr
638         ipcopmake uClibc
639   fi
640   installmake busybox
641   installmake sysvinit
642   installmake e2fsprogs
643   installmake misc-progs
644   installmake slang
645   installmake util-linux
646   installmake newt
647   installmake pciutils
648   installmake pcmcia-cs
649   installmake kbd
650   installmake installer
651   installmake scsi.img
652   installmake driver.img
653   installmake initrd
654   installmake boot.img
655 }
656
657 buildpackages() {
658   LOGFILE="$BASEDIR/log/_build.packages.log"
659   export LOGFILE
660   echo "... see detailed log in _build.*.log files" >> $LOGFILE
661   echo -ne "`date -u '+%b %e %T'`: Stage5 packages build \n" | tee -a $LOGFILE
662   # Strip files
663   echo "`date -u '+%b %e %T'`: Stripping files" | tee -a $LOGFILE
664   find $LFS/lib $LFS/usr/lib $LFS/usr/share/rrdtool-* $LFS/install ! -type l \( -name '*.so' -o -name '*.so[\.0-9]*' \) \
665         ! -name 'libc.so' ! -name 'libpthread.so' ! -name 'libcrypto.so.0.9.7.sha1' \
666         -exec $LFS/tools/bin/strip --strip-all {} \; >> $LOGFILE 2>&1
667   # add -ls before -exec if you want to verify what files are stripped
668
669   find $LFS/{,s}bin $LFS/usr/{,s}bin $LFS/usr/local/{,s}bin ! -type l \
670         -exec file {} \; | grep " ELF " | cut -f1 -d ':' | xargs $LFS/tools/bin/strip --strip-all >> $LOGFILE 2>&1
671   # there add -v to strip to verify
672
673   if [ 'i386' = $MACHINE ]; then
674         # Create fcdsl packages
675         echo "`date -u '+%b %e %T'`: Building fcdsl tgz" | tee -a $LOGFILE
676         cp $LFS/install/images/fcdsl/license.txt $LFS  >> $LOGFILE 2>&1
677         touch $LFS/var/run/{need-depmod-$KVER,need-depmod-$KVER-smp}
678         cd $LFS && tar cvfz $LFS/install/images/$SNAME-fcdsl-$VERSION.$MACHINE.tgz \
679                 lib/modules/$KVER/misc/fcdsl*.o.gz \
680                 lib/modules/$KVER-smp/misc/fcdsl*.o.gz \
681                 usr/lib/isdn/{fds?base.bin,fd?ubase.frm} \
682                 etc/fcdsl/fcdsl*.conf \
683                 etc/drdsl/{drdsl,drdsl.ini} \
684                 license.txt \
685                 var/run/{need-depmod-$KVER,need-depmod-$KVER-smp} >> $LOGFILE 2>&1
686         rm -f $LFS/license.txt >> $LOGFILE 2>&1
687         cd $BASEDIR
688   fi
689
690   # Create update for this version
691 #  echo "`date -u '+%b %e %T'`: Building update $VERSION tgz" | tee -a $LOGFILE
692 #  tar -cz -C $BASEDIR/build --files-from=$BASEDIR/updates/$VERSION/ROOTFILES.$MACHINE-$VERSION -f $BASEDIR/updates/$VERSION/patch.tar.gz --exclude='#*'; 
693 #  chmod 755 $BASEDIR/updates/$VERSION/setup
694 #  tar -cz -C $BASEDIR/updates/$VERSION -f $LFS/install/images/$SNAME-update-$VERSION.$MACHINE.tgz patch.tar.gz setup information
695 #  rm -f $LFS/var/run/{need-depmod-$KVER,need-depmod-$KVER-smp}
696   
697   # Generating list of packages used
698   echo "`date -u '+%b %e %T'`: Generating packages list from logs" | tee -a $LOGFILE
699   rm -f $BASEDIR/doc/packages-list
700   for i in `ls -1tr $BASEDIR/log/[^_]*`; do
701         if [ "$i" != "$BASEDIR/log/FILES" -a -n $i ]; then
702                 echo "* `basename $i`" >>$BASEDIR/doc/packages-list
703         fi
704   done
705   echo "!!! List of softwares used to build $NAME Version:$VERSION" > $BASEDIR/doc/packages-list.txt
706   grep -v 'configroot$\|img$\|initrd$\|initscripts$\|installer$\|install$\|ipcop$\|setup$\|stage2$\|smp$\|tools$\|tools1$\|tools2$' \
707         $BASEDIR/doc/packages-list | sort >> $BASEDIR/doc/packages-list.txt
708   rm -f $BASEDIR/doc/packages-list
709   # packages-list.txt is ready to be displayed for wiki page IPCopSoftwares
710
711   # Create ISO for CDRom and USB-superfloppy
712   ipcopmake cdrom
713   cp $LFS/install/images/{*.iso,*.tgz} $BASEDIR >> $LOGFILE 2>&1
714
715   # Cleanup
716   stdumount
717   rm -rf $BASEDIR/build/tmp/*
718
719   # Generating total list of files
720   echo "`date -u '+%b %e %T'`: Generating files list from logs" | tee -a $LOGFILE
721   rm -f $BASEDIR/log/FILES
722   for i in `ls -1tr $BASEDIR/log/[^_]*`; do
723         if [ "$i" != "$BASEDIR/log/FILES" -a -n $i ]; then
724                 echo "##" >>$BASEDIR/log/FILES
725                 echo "## `basename $i`" >>$BASEDIR/log/FILES
726                 echo "##" >>$BASEDIR/log/FILES
727                 cat $i | sed "s%^\./%#%" | sort >> $BASEDIR/log/FILES
728         fi
729   done
730
731   cd $PWD
732
733 }
734
735 # See what we're supposed to do
736 case "$1" in 
737 build)
738         BUILDMACHINE=`uname -m`
739         PACKAGE=`ls -v -r $BASEDIR/cache/$SNAME-1.4.*-toolchain-$BUILDMACHINE.tar.gz 2> /dev/null | head -n 1`
740         #only restore on a clean disk
741         if [ ! -f log/perl-*-tools ]; then
742                 if [ ! -n "$PACKAGE" ]; then
743                         echo "`date -u '+%b %e %T'`: Full toolchain compilation" | tee -a $LOGFILE
744                         prepareenv
745                         buildtoolchain
746                 else
747                         PACKAGENAME=${PACKAGE%.tar.gz}
748                         echo "`date -u '+%b %e %T'`: Restore from $PACKAGE" | tee -a $LOGFILE
749                         if [ `md5sum $PACKAGE | awk '{print $1}'` == `cat $PACKAGENAME.md5 | awk '{print $1}'` ]; then
750                                 tar zxf $PACKAGE
751                                 prepareenv
752                         else
753                                 exiterror "$PACKAGENAME md5 did not match, check downloaded package"
754                         fi
755                 fi
756         else
757                 echo "`date -u '+%b %e %T'`: Using installed toolchain" | tee -a $LOGFILE
758                 prepareenv
759         fi
760         buildbase
761         buildipcop
762         buildinstaller
763         buildpackages
764         ;;
765 shell)
766         # enter a shell inside LFS chroot
767         # may be used to changed kernel settings
768         prepareenv
769         entershell
770         ;;
771 changelog)
772         echo "Building doc/Changelog from CVS"
773         # cv2cl script come from http://www.red-bean.com/cvs2cl/
774         if [ ! -s $BASEDIR/doc/CVS/Tag ]; then
775                 BRANCHOPTS=""
776         else
777                 BRANCH=`cat $BASEDIR/doc/CVS/Tag`
778                 BRANCH=${BRANCH:1}
779                 BRANCHOPTS="--follow-only $BRANCH"
780         fi
781         
782         $BASEDIR/tools/cvs2cl.pl --gmt --show-dead $BRANCHOPTS -f $BASEDIR/doc/ChangeLog
783         rm -f $BASEDIR/doc/ChangeLog.bak
784         echo
785         echo "Commit the change now to update CVS"
786         ;;
787 check)
788         echo "Checking sources files availability on the web"
789         if [ ! -d $DIR_CHK ]; then
790                 mkdir -p $DIR_CHK
791         fi
792         FINISHED=0
793         cd $BASEDIR/lfs
794         for c in `seq $MAX_RETRIES`; do
795                 if (( FINISHED==1 )); then
796                         break
797                 fi
798                 FINISHED=1
799                 cd $BASEDIR/lfs
800                 for i in *; do
801                         if [ -f "$i" -a "$i" != "Config" ]; then
802                                 make -s -f $i MACHINE=$MACHINE LFS_BASEDIR=$BASEDIR ROOT=$BASEDIR/build \
803                                         MESSAGE="$i\t ($c/$MAX_RETRIES)" check
804                                 if [ $? -ne 0 ]; then
805                                         echo "Check : wget error in lfs/$i"
806                                         FINISHED=0
807                                 fi
808                         fi
809                 done
810         done
811         cd -
812         ;;
813 checkclean)
814         echo "Erasing sources files availability tags"
815         rm -rf $DIR_CHK/*
816         ;;
817 clean)
818         for i in `mount | grep $BASEDIR | sed 's/^.*loop=\(.*\))/\1/'`; do
819                 $LOSETUP -d $i 2>/dev/null
820         done
821         for i in `mount | grep $BASEDIR | cut -d " " -f 1`; do
822                 umount $i
823         done
824         stdumount
825         for i in `seq 0 7`; do
826             if ( losetup /dev/loop${i} 2>/dev/null | grep -q "/install/images" ); then
827                 umount /dev/loop${i}     2>/dev/null;
828                 losetup -d /dev/loop${i} 2>/dev/null;
829             fi;
830         done
831         rm -rf $BASEDIR/build
832         rm -rf $BASEDIR/cdrom
833         rm -rf $BASEDIR/log
834         rm -f $BASEDIR/updates/$VERSION/patch.tar.gz;
835         if [ -h /tools ]; then
836                 rm -f /tools
837         fi
838         ;;
839 dist)
840         echo "Building source package from CVS, list of changed files, MD5 of release files"
841         if [ ! -s $BASEDIR/doc/CVS/Tag ]; then
842                 BRANCH=""
843                 BRANCHOPTS="-D `date +'%Y-%m-%d'`"
844         else
845                 BRANCH=`cat $BASEDIR/doc/CVS/Tag`
846                 BRANCH=${BRANCH:1}
847                 BRANCHOPTS="-r $BRANCH"
848         fi
849
850         rm -rf $BASEDIR/build/tmp/$SNAME-$VERSION $BASEDIR/doc/release.txt
851         cd $BASEDIR/build/tmp
852         # build sources tgz
853         echo "Export tree $BRANCH $SNAME-$VERSION"
854         cvs -z3 -d `cat $BASEDIR/CVS/Root` export $BRANCHOPTS ipcop
855         if [ $? -eq 0 ]; then
856                 mv ipcop $SNAME-$VERSION
857                 tar cfz $BASEDIR/$SNAME-sources-$VERSION.tgz $SNAME-$VERSION
858                 cd $BASEDIR
859
860                 if [ ! -d $BASEDIR/build/tmp/$PREVIOUSTAG ]; then
861                         # export previous version to be compared with actual, this help to check wich files need to go in update
862                         cd $BASEDIR/build/tmp
863                         echo "Export tree $PREVIOUSTAG"
864                         cvs -z3 -d `cat $BASEDIR/CVS/Root` export -r $PREVIOUSTAG ipcop
865                         mv ipcop $PREVIOUSTAG
866                 fi
867                 if [ -d $BASEDIR/build/tmp/$PREVIOUSTAG -o -d $BASEDIR/build/tmp/$SNAME-$VERSION ]; then
868                         cd $BASEDIR/build/tmp
869                         echo "diff $PREVIOUSTAG <> $BRANCH $SNAME-$VERSION >doc/updated-sources.txt"
870                         diff -rq $PREVIOUSTAG $SNAME-$VERSION > $BASEDIR/doc/updated-sources.txt
871                         mv $BASEDIR/doc/updated-sources.txt $BASEDIR/doc/updated-sources.bak
872                         sed -e "s+Files $PREVIOUSTAG\/++" \
873                                 -e "s+ and .*$++" \
874                                 -e "s+src/rc.d+etc/rc.d+" \
875                                 -e "s+^langs/+var/ipcop/langs/+" \
876                                 -e "s+html/cgi-bin+home/httpd/cgi-bin+" $BASEDIR/doc/updated-sources.bak \
877                                 > $BASEDIR/doc/updated-sources.txt
878                         rm -f $BASEDIR/doc/updated-sources.bak
879                 fi
880         fi
881         ;;
882 newupdate)
883         # create structure for $VERSION update
884         if [ ! -f "updates/$VERSION" ]; then
885                 mkdir -p updates/$VERSION
886                 cd updates/$VERSION
887                 touch information
888                 echo 'etc/issue' > ROOTFILES.alpha-$VERSION
889                 echo 'etc/issue' > ROOTFILES.i386-$VERSION
890                 echo 'patch.tar.gz' > .cvsignore
891                 sed -e "s+^UPGRADEVERSION.*$+UPGRADEVERSION=$VERSION+" $BASEDIR/src/scripts/updatesetup > setup
892                 chmod 755 setup
893                 cd ..
894                 echo "Adding directory $VERSION to cvs"
895                 cvs add $VERSION
896                 echo "Adding files to cvs"
897                 cvs add $VERSION/ROOTFILES.alpha-$VERSION \
898                         $VERSION/ROOTFILES.i386-$VERSION \
899                         $VERSION/information \
900                         $VERSION/setup \
901                         $VERSION/.cvsignore
902         else
903                 echo "update/$VERSION already exist"
904         fi
905         cd -
906         exit 0
907         ;;
908 prefetch)
909         if [ ! -d $BASEDIR/cache ]; then
910                 mkdir $BASEDIR/cache
911         fi
912         mkdir -p $BASEDIR/log
913         echo "`date -u '+%b %e %T'`:Preload all source files" | tee -a $LOGFILE
914         FINISHED=0
915         cd $BASEDIR/lfs
916         for c in `seq $MAX_RETRIES`; do
917                 if (( FINISHED==1 )); then 
918                         break
919                 fi
920                 FINISHED=1
921                 cd $BASEDIR/lfs
922                 for i in *; do
923                         if [ -f "$i" -a "$i" != "Config" ]; then
924                                 make -s -f $i LFS_BASEDIR=$BASEDIR MESSAGE="$i\t ($c/$MAX_RETRIES)" download >> $LOGFILE 2>&1
925                                 if [ $? -ne 0 ]; then
926                                         echo "Prefetch : wget error in lfs/$i"
927                                         FINISHED=0
928                                 else
929                                         if [ $c -eq 1 ]; then
930                                                 echo "Prefetch : lfs/$i files loaded"
931                                         fi
932                                 fi
933                         fi
934                 done
935         done
936         echo "Prefetch : verifying md5sum"
937         ERROR=0
938         for i in *; do
939                 if [ -f "$i" -a "$i" != "Config" ]; then
940                         make -s -f $i LFS_BASEDIR=$BASEDIR MESSAGE="$i\t " md5 >> $LOGFILE 2>&1
941                         if [ $? -ne 0 ]; then
942                                 echo "md5 difference in lfs/$i"
943                                 ERROR=1
944                         fi
945                 fi
946         done
947         if [ $ERROR -eq 0 ]; then
948                 echo "Prefetch : all files md5sum match"
949         fi
950         cd -
951         ;;
952 rootfiles)
953         PREVIOUSVERSION=`echo $PREVIOUSTAG | sed -e 's/IPCOP_v//' -e 's/_FINAL//' -e 's/_/\./g'`
954         # make md5 list of actual build
955         # some packages include a timestamp (kernel/perl/python/vim and more), so md5 vary at each build
956         # anyway, it is sometime usable after a patch or a minor upgrade to know wich files include in update
957         if [ ! -f "$BASEDIR/build/install/cdrom/$SNAME-$VERSION.tgz" ]; then
958                 echo "need cdrom be build to read include files list, use ./make.sh build before."
959         else
960                 tar tzf $BASEDIR/build/install/cdrom/$SNAME-$VERSION.tgz > $BASEDIR/updates/$VERSION/FILES.tmp
961                 cd $BASEDIR/build
962                 rm -f $BASEDIR/updates/$VERSION/FILES-$MACHINE-$VERSION.md5
963                 for line in `cat $BASEDIR/updates/$VERSION/FILES.tmp`; do
964                         if [ -f "$line" -a ! -L "$line" ]; then
965                                 md5sum "$line" >> $BASEDIR/updates/$VERSION/FILES-$MACHINE-$VERSION.md5
966                         fi
967                 done
968                 diff $BASEDIR/updates/$PREVIOUSVERSION/FILES-$MACHINE-$PREVIOUSVERSION.md5 \
969                         $BASEDIR/updates/$VERSION/FILES-$MACHINE-$VERSION.md5 \
970                         > $BASEDIR/updates/$VERSION/FILES-$MACHINE.diff
971                 awk '$1==">" {print $3}' $BASEDIR/updates/$VERSION/FILES-$MACHINE.diff \
972                         > $BASEDIR/updates/$VERSION/ROOTFILES.add.$MACHINE
973                 awk '$1=="<" {print $3}' $BASEDIR/updates/$VERSION/FILES-$MACHINE.diff \
974                         > $BASEDIR/updates/$VERSION/ROOTFILES.remove.$MACHINE.tmp
975                 rm -f $BASEDIR/updates/$VERSION/ROOTFILES.remove.$MACHINE
976                 for line in `cat $BASEDIR/updates/$VERSION/ROOTFILES.remove.$MACHINE.tmp`; do
977                         # a file is only removed when not in add file
978                         if ( ! grep -q "^$line$" $BASEDIR/updates/$VERSION/ROOTFILES.add.$MACHINE ); then
979                                 echo $line >> $BASEDIR/updates/$VERSION/ROOTFILES.remove.$MACHINE
980                         fi
981                 done
982                 rm -f $BASEDIR/updates/$VERSION/{FILES.tmp,FILES-*.diff,ROOTFILES.remove.*.tmp}
983         fi
984         exit 0
985         ;;
986 toolchain)
987         prepareenv
988         buildtoolchain
989         BUILDMACHINE=`uname -m`
990         echo "`date -u '+%b %e %T'`: Create toolchain tar.gz for $BUILDMACHINE" | tee -a $LOGFILE
991         cd $BASEDIR && tar -zc --exclude='log/_build.*.log' -f cache/$SNAME-$VERSION-toolchain-$BUILDMACHINE.tar.gz \
992                 build/{bin,etc,usr/bin,usr/local} \
993                 build/tools/{bin,etc,*-linux-gnu,include,lib,libexec,sbin,share,var} \
994                 log >> $LOGFILE
995         md5sum cache/$SNAME-$VERSION-toolchain-$BUILDMACHINE.tar.gz \
996                 > cache/$SNAME-$VERSION-toolchain-$BUILDMACHINE.md5
997         stdumount
998         ;;
999 gettoolchain)
1000         BUILDMACHINE=`uname -m`
1001         # arbitrary name to be updated in case of new toolchain package upload
1002         PACKAGE=$SNAME-1.4.11-toolchain-$BUILDMACHINE
1003         URL_SFNET=`grep URL_SFNET lfs/Config | awk '{ print $3 }'`
1004         echo "`date -u '+%b %e %T'`: Load toolchain tar.gz for $BUILDMACHINE" | tee -a $LOGFILE
1005         cd $BASEDIR/cache
1006         wget -c $URL_SFNET/ipcop/$PACKAGE.tar.gz $URL_SFNET/ipcop/$PACKAGE.md5
1007         if [ $? -ne 0 ]; then
1008                 echo "`date -u '+%b %e %T'`: error downloading toolchain for $BUILDMACHINE machine" | tee -a $LOGFILE
1009         else
1010                 if [ "`md5sum $PACKAGE.tar.gz | awk '{print $1}'`" = "`cat $PACKAGE.md5 | awk '{print $1}'`" ]; then
1011                         echo "`date -u '+%b %e %T'`: toolchain md5 ok" | tee -a $LOGFILE
1012                 else
1013                         exiterror "$PACKAGE.md5 did not match, check downloaded package"
1014                 fi
1015         fi
1016         ;;
1017 *)
1018         echo "Usage: $0 {build|changelog|check|checkclean|clean|dist|gettoolchain|newupdate|prefetch|rootfiles|shell|toolchain}"
1019         cat doc/make.sh-usage
1020         exit 1
1021         ;;
1022 esac