Merge branch 'master' of ssh://git.ipfire.org/pub/git/ipfire-2.x
[people/teissler/ipfire-2.x.git] / make.sh
1 #!/bin/bash
2 ############################################################################
3 #                                                                          #
4 # This file is part of the IPFire Firewall.                                #
5 #                                                                          #
6 # IPFire is free software; you can redistribute it and/or modify           #
7 # it under the terms of the GNU General Public License as published by     #
8 # the Free Software Foundation; either version 2 of the License, or        #
9 # (at your option) any later version.                                      #
10 #                                                                          #
11 # IPFire is distributed in the hope that it will be useful,                #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of           #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            #
14 # GNU General Public License for more details.                             #
15 #                                                                          #
16 # You should have received a copy of the GNU General Public License        #
17 # along with IPFire; if not, write to the Free Software                    #
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA #
19 #                                                                          #
20 # Copyright (C) 2007-2014 IPFire Team <info@ipfire.org>.                   #
21 #                                                                          #
22 ############################################################################
23 #
24
25 NAME="IPFire"                                                   # Software name
26 SNAME="ipfire"                                                  # Short name
27 VERSION="2.15"                                                  # Version number
28 CORE="77-rc1"                                                   # Core Level (Filename)
29 PAKFIRE_CORE="77"                                               # Core Level (PAKFIRE)
30 GIT_BRANCH=`git rev-parse --abbrev-ref HEAD`                    # Git Branch
31 SLOGAN="www.ipfire.org"                                         # Software slogan
32 CONFIG_ROOT=/var/ipfire                                         # Configuration rootdir
33 NICE=10                                                         # Nice level
34 MAX_RETRIES=1                                                   # prefetch/check loop
35 BUILD_IMAGES=1                                                  # Flash and Xen Downloader
36 KVER=`grep --max-count=1 VER lfs/linux | awk '{ print $3 }'`
37 MACHINE=`uname -m`
38 GIT_TAG=$(git tag | tail -1)                                    # Git Tag
39 GIT_LASTCOMMIT=$(git log | head -n1 | cut -d" " -f2 |head -c8)  # Last commit
40 TOOLCHAINVER=7
41
42 BUILDMACHINE=$MACHINE
43     if [ "$MACHINE" = "x86_64" ]; then
44         BUILDMACHINE="i686";
45     fi
46
47
48 # Debian specific settings
49 if [ ! -e /etc/debian_version ]; then
50         FULLPATH=`which $0`
51 else
52         if [ -x /usr/bin/realpath ]; then
53                 FULLPATH=`/usr/bin/realpath $0`
54         else
55                 echo "ERROR: Need to do apt-get install realpath"
56                 exit 1
57         fi
58 fi
59
60 PWD=`pwd`
61 BASENAME=`basename $0`
62 BASEDIR=`echo $FULLPATH | sed "s/\/$BASENAME//g"`
63 LOGFILE=$BASEDIR/log/_build.preparation.log
64 export BASEDIR LOGFILE
65 DIR_CHK=$BASEDIR/cache/check
66 mkdir $BASEDIR/log/ 2>/dev/null
67
68 # Include funtions
69 . tools/make-functions
70
71 if [ -f .config ]; then
72         . .config
73 fi
74
75 if [ -z $EDITOR ]; then
76         for i in nano emacs vi; do
77                 EDITOR=$(which $i 2>/dev/null)
78                 if ! [ -z $EDITOR ]; then
79                         export EDITOR=$EDITOR
80                         break
81                 fi
82         done
83         [ -z $EDITOR ] && exiterror "You should have installed an editor."
84 fi
85
86 # Prepare string for /etc/system-release.
87 SYSTEM_RELEASE="${NAME} ${VERSION} (${MACHINE})"
88 if [ "$(git status -s | wc -l)" == "0" ]; then
89         GIT_STATUS=""
90 else
91         GIT_STATUS="-dirty"
92 fi
93 case "$GIT_BRANCH" in
94         core*|beta?|rc?)
95                 SYSTEM_RELEASE="${SYSTEM_RELEASE} - $GIT_BRANCH$GIT_STATUS"
96                 ;;
97         *)
98                 SYSTEM_RELEASE="${SYSTEM_RELEASE} - Development Build: $GIT_BRANCH/$GIT_LASTCOMMIT$GIT_STATUS"
99                 ;;
100 esac
101
102 prepareenv() {
103     ############################################################################
104     #                                                                          #
105     # Are we running the right shell?                                          #
106     #                                                                          #
107     ############################################################################
108     if [ ! "$BASH" ]; then
109                         exiterror "BASH environment variable is not set.  You're probably running the wrong shell."
110     fi
111
112     if [ -z "${BASH_VERSION}" ]; then
113                         exiterror "Not running BASH shell."
114     fi
115
116
117     ############################################################################
118     #                                                                          #
119     # Trap on emergency exit                                                   #
120     #                                                                          #
121     ############################################################################
122     trap "exiterror 'Build process interrupted'" SIGINT SIGTERM SIGKILL SIGSTOP SIGQUIT
123
124
125     ############################################################################
126     #                                                                          #
127     # Resetting our nice level                                                 #
128     #                                                                          #
129     ############################################################################
130     echo -ne "Resetting our nice level to $NICE" | tee -a $LOGFILE
131     renice $NICE $$ > /dev/null
132     if [ `nice` != "$NICE" ]; then
133                         beautify message FAIL
134                         exiterror "Failed to set correct nice level"
135     else
136                         beautify message DONE
137     fi
138
139
140     ############################################################################
141     #                                                                          #
142     # Checking if running as root user                                         #
143     #                                                                          #
144     ############################################################################
145     echo -ne "Checking if we're running as root user" | tee -a $LOGFILE
146     if [ `id -u` != 0 ]; then
147                         beautify message FAIL
148                         exiterror "Not building as root"
149     else
150                         beautify message DONE
151     fi
152
153
154     ############################################################################
155     #                                                                          #
156     # Checking for necessary temporary space                                   #
157     #                                                                          #
158     ############################################################################
159     echo -ne "Checking for necessary space on disk $BASE_DEV" | tee -a $LOGFILE
160     BASE_DEV=`df -P -k $BASEDIR | tail -n 1 | awk '{ print $1 }'`
161     BASE_ASPACE=`df -P -k $BASEDIR | tail -n 1 | awk '{ print $4 }'`
162     if (( 2048000 > $BASE_ASPACE )); then
163                         BASE_USPACE=`du -skx $BASEDIR | awk '{print $1}'`
164                         if (( 2048000 - $BASE_USPACE > $BASE_ASPACE )); then
165                                 beautify message FAIL
166                                 exiterror "Not enough temporary space available, need at least 2GB on $BASE_DEV"
167                         fi
168     else
169                         beautify message DONE
170     fi
171
172     ############################################################################
173     #                                                                          #
174     # Building Linux From Scratch system                                       #
175     #                                                                          #
176     ############################################################################
177     # Set umask
178     umask 022
179
180     # Set LFS Directory
181     LFS=$BASEDIR/build
182
183     # Check /tools symlink
184     if [ -h /tools ]; then
185         rm -f /tools
186     fi
187     if [ ! -a /tools ]; then
188                         ln -s $BASEDIR/build/tools /
189     fi
190     if [ ! -h /tools ]; then
191                         exiterror "Could not create /tools symbolic link."
192     fi
193
194     # Setup environment
195     set +h
196     LC_ALL=POSIX
197     if [ -z $MAKETUNING ]; then
198         CPU_COUNT="$(getconf _NPROCESSORS_ONLN 2>/dev/null)"
199         if [ -z "${CPU_COUNT}" ]; then
200                 CPU_COUNT=1
201         fi
202
203         MAKETUNING="-j$(( ${CPU_COUNT} * 2 + 1 ))"
204     fi
205     export LFS LC_ALL CFLAGS CXXFLAGS MAKETUNING
206     unset CC CXX CPP LD_LIBRARY_PATH LD_PRELOAD
207
208     # Make some extra directories
209     mkdir -p $BASEDIR/build/{tools,etc,usr/src} 2>/dev/null
210     mkdir -p $BASEDIR/build/{dev/{shm,pts},proc,sys}
211     mkdir -p $BASEDIR/{cache,ccache} 2>/dev/null
212     mkdir -p $BASEDIR/build/usr/src/{cache,config,doc,html,langs,lfs,log,src,ccache}
213
214     mknod -m 600 $BASEDIR/build/dev/console c 5 1 2>/dev/null
215     mknod -m 666 $BASEDIR/build/dev/null c 1 3 2>/dev/null
216
217     # Make all sources and proc available under lfs build
218     mount --bind /dev            $BASEDIR/build/dev
219     mount --bind /dev/pts        $BASEDIR/build/dev/pts
220     mount --bind /dev/shm        $BASEDIR/build/dev/shm
221     mount --bind /proc           $BASEDIR/build/proc
222     mount --bind /sys            $BASEDIR/build/sys
223     mount --bind $BASEDIR/cache  $BASEDIR/build/usr/src/cache
224     mount --bind $BASEDIR/ccache $BASEDIR/build/usr/src/ccache
225     mount --bind $BASEDIR/config $BASEDIR/build/usr/src/config
226     mount --bind $BASEDIR/doc    $BASEDIR/build/usr/src/doc
227     mount --bind $BASEDIR/html   $BASEDIR/build/usr/src/html
228     mount --bind $BASEDIR/langs  $BASEDIR/build/usr/src/langs
229     mount --bind $BASEDIR/lfs    $BASEDIR/build/usr/src/lfs
230     mount --bind $BASEDIR/log    $BASEDIR/build/usr/src/log
231     mount --bind $BASEDIR/src    $BASEDIR/build/usr/src/src
232
233     # Run LFS static binary creation scripts one by one
234     export CCACHE_DIR=$BASEDIR/ccache
235     export CCACHE_COMPRESS=1
236     export CCACHE_COMPILERCHECK="none"
237
238     # Remove pre-install list of installed files in case user erase some files before rebuild
239     rm -f $BASEDIR/build/usr/src/lsalr 2>/dev/null
240 }
241
242 buildtoolchain() {
243     local error=false
244     case "${MACHINE}:$(uname -m)" in
245         # x86
246         i586:i586|i586:i686|i586:x86_64)
247             # These are working.
248             ;;
249         i586:*)
250             error=true
251             ;;
252
253         # ARM
254         armv5tel:armv5tel|armv5tel:armv5tejl|armv5tel:armv6l|armv5tel:armv7l)
255             # These are working.
256             ;;
257         armv5tel:*)
258             error=true
259             ;;
260     esac
261
262     ${error} && \
263         exiterror "Cannot build ${MACHINE} toolchain on $(uname -m). Please use the download if any."
264
265     local gcc=$(type -p gcc)
266     if [ -z "${gcc}" ]; then
267         exiterror "Could not find GCC. You will need a working build enviroment in order to build the toolchain."
268     fi
269
270     LOGFILE="$BASEDIR/log/_build.toolchain.log"
271     export LOGFILE
272
273     local ORG_PATH=$PATH
274     export PATH="/tools/ccache/bin:/tools/bin:$PATH"
275     lfsmake1 ccache                     PASS=1
276     lfsmake1 binutils                   PASS=1
277     lfsmake1 gcc                        PASS=1
278     lfsmake1 linux                      TOOLS=1 KCFG="-headers"
279     lfsmake1 glibc
280     lfsmake1 cleanup-toolchain          PASS=1
281     lfsmake1 binutils                   PASS=2
282     lfsmake1 gcc                        PASS=2
283     lfsmake1 ccache                     PASS=2
284     lfsmake1 tcl
285     lfsmake1 expect
286     lfsmake1 dejagnu
287     lfsmake1 ncurses
288     lfsmake1 bash
289     lfsmake1 bzip2
290     lfsmake1 coreutils
291     lfsmake1 diffutils
292     lfsmake1 findutils
293     lfsmake1 gawk
294     lfsmake1 gettext
295     lfsmake1 grep
296     lfsmake1 gzip
297     lfsmake1 m4
298     lfsmake1 make
299     lfsmake1 patch
300     lfsmake1 perl
301     lfsmake1 sed
302     lfsmake1 tar
303     lfsmake1 texinfo
304     lfsmake1 xz
305     lfsmake1 fake-environ
306     lfsmake1 cleanup-toolchain          PASS=2
307     export PATH=$ORG_PATH
308 }
309
310 buildbase() {
311     LOGFILE="$BASEDIR/log/_build.base.log"
312     export LOGFILE
313     lfsmake2 stage2
314     lfsmake2 linux                      KCFG="-headers"
315     lfsmake2 man-pages
316     lfsmake2 glibc
317     lfsmake2 tzdata
318     lfsmake2 cleanup-toolchain          PASS=3
319     lfsmake2 zlib
320     lfsmake2 binutils
321     lfsmake2 gmp
322     lfsmake2 gmp-compat
323     lfsmake2 mpfr
324     lfsmake2 file
325     lfsmake2 gcc
326     lfsmake2 sed
327     lfsmake2 berkeley
328     lfsmake2 coreutils
329     lfsmake2 iana-etc
330     lfsmake2 m4
331     lfsmake2 bison
332     lfsmake2 ncurses
333     lfsmake2 procps
334     lfsmake2 libtool
335     lfsmake2 perl
336     lfsmake2 readline
337     lfsmake2 readline-compat
338     lfsmake2 pcre
339     lfsmake2 pcre-compat
340     lfsmake2 autoconf
341     lfsmake2 automake
342     lfsmake2 bash
343     lfsmake2 bzip2
344     lfsmake2 diffutils
345     lfsmake2 e2fsprogs
346     lfsmake2 ed
347     lfsmake2 findutils
348     lfsmake2 flex
349     lfsmake2 gawk
350     lfsmake2 gettext
351     lfsmake2 grep
352     lfsmake2 groff
353     lfsmake2 gperf
354     lfsmake2 gzip
355     lfsmake2 inetutils
356     lfsmake2 iproute2
357     lfsmake2 jwhois
358     lfsmake2 kbd
359     lfsmake2 less
360     lfsmake2 make
361     lfsmake2 man
362     lfsmake2 mktemp
363     lfsmake2 kmod
364     lfsmake2 net-tools
365     lfsmake2 patch
366     lfsmake2 psmisc
367     lfsmake2 shadow
368     lfsmake2 sysklogd
369     lfsmake2 sysvinit
370     lfsmake2 tar
371     lfsmake2 texinfo
372     lfsmake2 util-linux
373     lfsmake2 udev
374     lfsmake2 vim
375     lfsmake2 xz
376     lfsmake2 paxctl
377     lfsmake2 grub
378 }
379
380 buildipfire() {
381   LOGFILE="$BASEDIR/log/_build.ipfire.log"
382   export LOGFILE
383   ipfiremake configroot
384   ipfiremake backup
385   ipfiremake bind
386   ipfiremake dhcp
387   ipfiremake dhcpcd
388   ipfiremake libusb
389   ipfiremake libusbx
390   ipfiremake libpcap
391   ipfiremake ppp
392   ipfiremake pptp
393   ipfiremake unzip
394   ipfiremake which
395   ipfiremake linux-firmware
396   ipfiremake dvb-firmwares
397   ipfiremake zd1211-firmware
398   ipfiremake rpi-firmware
399   ipfiremake bc
400   ipfiremake u-boot
401
402   if [ "${MACHINE_TYPE}" != "arm" ]; then
403
404     # x86-pae (Native and new XEN) kernel build
405     ipfiremake linux                    KCFG="-pae"
406 #    ipfiremake kvm-kmod                        KCFG="-pae"
407 #    ipfiremake v4l-dvb                 KCFG="-pae"
408 #    ipfiremake mISDN                   KCFG="-pae"
409     ipfiremake cryptodev                KCFG="-pae"
410 #    ipfiremake compat-drivers          KCFG="-pae"
411 #    ipfiremake r8169                   KCFG="-pae"
412 #    ipfiremake r8168                   KCFG="-pae"
413 #    ipfiremake r8101                   KCFG="-pae"
414     ipfiremake e1000e                   KCFG="-pae"
415     ipfiremake igb                      KCFG="-pae"
416
417     # x86 kernel build
418     ipfiremake linux                    KCFG=""
419 #    ipfiremake kvm-kmod                        KCFG=""
420 #    ipfiremake v4l-dvb                 KCFG=""
421 #    ipfiremake mISDN                   KCFG=""
422     ipfiremake cryptodev                KCFG=""
423 #    ipfiremake compat-drivers          KCFG=""
424 #    ipfiremake r8169                   KCFG=""
425 #    ipfiremake r8168                   KCFG=""
426 #    ipfiremake r8101                   KCFG=""
427     ipfiremake e1000e                   KCFG=""
428     ipfiremake igb                      KCFG=""
429
430   else
431     # arm-rpi (Raspberry Pi) kernel build
432     ipfiremake linux                    KCFG="-rpi"
433 #    ipfiremake v4l-dvb                 KCFG="-rpi"
434 #    ipfiremake mISDN                   KCFG="-rpi" NOPCI=1
435     ipfiremake cryptodev                KCFG="-rpi"
436 #    ipfiremake compat-drivers          KCFG="-rpi"
437
438     # arm multi platform (Panda, Wandboard ...) kernel build
439     ipfiremake linux                    KCFG="-multi"
440     ipfiremake cryptodev                KCFG="-multi"
441     ipfiremake e1000e                   KCFG="-multi"
442     ipfiremake igb                      KCFG="-multi"
443
444     # arm-kirkwood (Dreamplug, ICY-Box ...) kernel build
445     ipfiremake linux                    KCFG="-kirkwood"
446 #    ipfiremake v4l-dvb                 KCFG="-kirkwood"
447 #    ipfiremake mISDN                   KCFG="-kirkwood"
448     ipfiremake cryptodev                KCFG="-kirkwood"
449 #    ipfiremake compat-drivers          KCFG="-kirkwood"
450 #    ipfiremake r8169                   KCFG="-kirkwood"
451 #    ipfiremake r8168                   KCFG="-kirkwood"
452 #    ipfiremake r8101                   KCFG="-kirkwood"
453 #    ipfiremake e1000e                  KCFG="-kirkwood"
454     ipfiremake igb                      KCFG="-kirkwood"
455
456   fi
457   ipfiremake pkg-config
458   ipfiremake linux-atm
459   ipfiremake cpio
460   ipfiremake dracut
461   ipfiremake expat
462   ipfiremake gdbm
463   ipfiremake pam
464   ipfiremake openssl
465   ipfiremake openssl-compat
466   ipfiremake curl
467   ipfiremake tcl
468   ipfiremake sqlite
469   ipfiremake python
470   ipfiremake fireinfo
471   ipfiremake libnet
472   ipfiremake libnl
473   ipfiremake libidn
474   ipfiremake nasm
475   ipfiremake libjpeg
476   ipfiremake libexif
477   ipfiremake libpng
478   ipfiremake libtiff
479   ipfiremake libart
480   ipfiremake freetype
481   ipfiremake gd
482   ipfiremake popt
483   ipfiremake pcre
484   ipfiremake slang
485   ipfiremake newt
486   ipfiremake attr
487   ipfiremake acl
488   ipfiremake libcap
489   ipfiremake pciutils
490   ipfiremake usbutils
491   ipfiremake libxml2
492   ipfiremake libxslt
493   ipfiremake BerkeleyDB
494   ipfiremake mysql
495   ipfiremake cyrus-sasl
496   ipfiremake openldap
497   ipfiremake apache2
498   ipfiremake php
499   ipfiremake apache2                    PASS=C
500   ipfiremake jquery
501   ipfiremake arping
502   ipfiremake beep
503   ipfiremake dvdrtools
504   ipfiremake dnsmasq
505   ipfiremake dosfstools
506   ipfiremake reiserfsprogs
507   ipfiremake xfsprogs
508   ipfiremake sysfsutils
509   ipfiremake fuse
510   ipfiremake ntfs-3g
511   ipfiremake ethtool
512   ipfiremake ez-ipupdate
513   ipfiremake fcron
514   ipfiremake perl-GD
515   ipfiremake GD-Graph
516   ipfiremake GD-TextUtil
517   ipfiremake gnupg
518   ipfiremake hdparm
519   ipfiremake sdparm
520   ipfiremake mtools
521   ipfiremake initscripts
522   ipfiremake whatmask
523   ipfiremake libmnl
524   ipfiremake iptables
525   ipfiremake conntrack-tools
526   ipfiremake libupnp
527   ipfiremake ipaddr
528   ipfiremake iputils
529   ipfiremake l7-protocols
530   ipfiremake mISDNuser
531   ipfiremake capi4k-utils
532   ipfiremake hwdata
533   ipfiremake logrotate
534   ipfiremake logwatch
535   ipfiremake misc-progs
536   ipfiremake nano
537   ipfiremake URI
538   ipfiremake HTML-Tagset
539   ipfiremake HTML-Parser
540   ipfiremake HTML-Template
541   ipfiremake Compress-Zlib
542   ipfiremake Digest
543   ipfiremake Digest-SHA1
544   ipfiremake Digest-HMAC
545   ipfiremake libwww-perl
546   ipfiremake Net-DNS
547   ipfiremake Net-IPv4Addr
548   ipfiremake Net_SSLeay
549   ipfiremake IO-Stringy
550   ipfiremake IO-Socket-SSL
551   ipfiremake Unix-Syslog
552   ipfiremake Mail-Tools
553   ipfiremake MIME-Tools
554   ipfiremake Net-Server
555   ipfiremake Convert-TNEF
556   ipfiremake Convert-UUlib
557   ipfiremake Archive-Tar
558   ipfiremake Archive-Zip
559   ipfiremake Text-Tabs+Wrap
560   ipfiremake Locale-Country
561   ipfiremake XML-Parser
562   ipfiremake Crypt-PasswdMD5
563   ipfiremake Net-Telnet
564   ipfiremake python-setuptools
565   ipfiremake python-clientform
566   ipfiremake python-mechanize
567   ipfiremake python-feedparser
568   ipfiremake python-rssdler
569   ipfiremake libffi
570   ipfiremake glib
571   ipfiremake GeoIP
572   ipfiremake fwhits
573   ipfiremake noip_updater
574   ipfiremake ntp
575   ipfiremake openssh
576   ipfiremake fontconfig
577   ipfiremake dejavu-fonts-ttf
578   ipfiremake freefont
579   ipfiremake pixman
580   ipfiremake cairo
581   ipfiremake pango
582   ipfiremake rrdtool
583   ipfiremake setserial
584   ipfiremake setup
585   ipfiremake libdnet
586   ipfiremake daq
587   ipfiremake snort
588   ipfiremake oinkmaster
589   ipfiremake squid
590   ipfiremake squidguard
591   ipfiremake calamaris
592   ipfiremake tcpdump
593   ipfiremake traceroute
594   ipfiremake vlan
595   ipfiremake wireless
596   ipfiremake pakfire
597   ipfiremake spandsp
598   ipfiremake lzo
599   ipfiremake openvpn
600   ipfiremake pammysql
601   ipfiremake mpage
602   ipfiremake dbus
603   ipfiremake cups
604   ipfiremake ghostscript
605   ipfiremake foomatic
606   ipfiremake hplip
607   ipfiremake cifs-utils
608   ipfiremake samba
609   ipfiremake sudo
610   ipfiremake mc
611   ipfiremake wget
612   ipfiremake bridge-utils
613   ipfiremake screen
614   ipfiremake smartmontools
615   ipfiremake htop
616   ipfiremake postfix
617   ipfiremake fetchmail
618   ipfiremake cyrus-imapd
619   ipfiremake openmailadmin
620   ipfiremake clamav
621   ipfiremake spamassassin
622   ipfiremake amavisd
623   ipfiremake alsa
624   ipfiremake mpfire
625   ipfiremake guardian
626   ipfiremake libid3tag
627   ipfiremake libmad
628   ipfiremake libogg
629   ipfiremake libvorbis
630   ipfiremake libdvbpsi
631   ipfiremake flac
632   ipfiremake lame
633   ipfiremake sox
634   ipfiremake libshout
635   ipfiremake xvid
636   ipfiremake libmpeg2
637   ipfiremake cmake
638   ipfiremake gnump3d
639   ipfiremake libsigc++
640   ipfiremake libtorrent
641   ipfiremake rtorrent
642   ipfiremake rsync
643   ipfiremake tcpwrapper
644   ipfiremake libevent
645   ipfiremake libevent2
646   ipfiremake portmap
647   ipfiremake nfs
648   ipfiremake nmap
649   ipfiremake ncftp
650   ipfiremake etherwake
651   ipfiremake bwm-ng
652   ipfiremake tripwire
653   ipfiremake sysstat
654   ipfiremake vsftpd
655   ipfiremake strongswan
656   ipfiremake rng-tools
657   ipfiremake lsof
658   ipfiremake br2684ctl
659   ipfiremake pcmciautils
660   ipfiremake lm_sensors
661   ipfiremake liboping
662   ipfiremake collectd
663   ipfiremake teamspeak
664   ipfiremake elinks
665   ipfiremake igmpproxy
666   ipfiremake fbset
667   ipfiremake sdl
668   ipfiremake qemu
669   ipfiremake sane
670   ipfiremake netpbm
671   ipfiremake phpSANE
672   ipfiremake tunctl
673   ipfiremake nagios
674   ipfiremake nagios_nrpe
675   ipfiremake ebtables
676   ipfiremake directfb
677   ipfiremake dfb++
678   ipfiremake faad2
679   ipfiremake ffmpeg
680   ipfiremake vdr
681   ipfiremake vdr_streamdev
682   ipfiremake vdr_vnsiserver3
683   ipfiremake vdr_epgsearch
684   ipfiremake vdr_dvbapi
685   ipfiremake vdr_eepg
686   ipfiremake w_scan
687   ipfiremake icecast
688   ipfiremake icegenerator
689   ipfiremake mpd
690   ipfiremake libmpdclient
691   ipfiremake mpc
692   ipfiremake git
693   ipfiremake squidclamav
694   ipfiremake vnstat
695   ipfiremake vnstati
696   ipfiremake iw
697   ipfiremake wpa_supplicant
698   ipfiremake hostapd
699   ipfiremake pycurl
700   ipfiremake urlgrabber
701   ipfiremake syslinux
702   ipfiremake tftpd
703   ipfiremake cpufrequtils
704   ipfiremake bluetooth
705   ipfiremake gutenprint
706   ipfiremake apcupsd
707   ipfiremake iperf
708   ipfiremake netcat
709   ipfiremake 7zip
710   ipfiremake lynis
711   ipfiremake streamripper
712   ipfiremake sshfs
713   ipfiremake taglib
714   ipfiremake mediatomb
715   ipfiremake sslh
716   ipfiremake perl-gettext
717   ipfiremake perl-Sort-Naturally
718   ipfiremake vdradmin
719   ipfiremake miau
720   ipfiremake netsnmpd
721   ipfiremake perl-DBI
722   ipfiremake perl-DBD-mysql
723   ipfiremake perl-DBD-SQLite
724   ipfiremake perl-File-ReadBackwards
725   ipfiremake cacti
726   ipfiremake icecc
727   ipfiremake openvmtools
728   ipfiremake nagiosql
729   ipfiremake iftop
730   ipfiremake motion
731   ipfiremake joe
732   ipfiremake nut
733   ipfiremake watchdog
734   ipfiremake libpri
735   ipfiremake asterisk
736   ipfiremake lcr
737   ipfiremake usb_modeswitch
738   ipfiremake usb_modeswitch_data
739   ipfiremake zerofree
740   ipfiremake mdadm
741   ipfiremake pound
742   ipfiremake minicom
743   ipfiremake ddrescue
744   ipfiremake imspector
745   ipfiremake miniupnpd
746   ipfiremake client175
747   ipfiremake powertop
748   ipfiremake parted
749   ipfiremake swig
750   ipfiremake python-m2crypto
751   ipfiremake wireless-regdb
752   ipfiremake crda
753   ipfiremake libsolv
754   ipfiremake python-distutils-extra
755   ipfiremake python-lzma
756   ipfiremake python-progressbar
757   ipfiremake python-xattr
758   ipfiremake intltool
759   ipfiremake transmission
760   ipfiremake dpfhack
761   ipfiremake lcd4linux
762   ipfiremake mtr
763   ipfiremake tcpick
764   ipfiremake minidlna
765   ipfiremake acpid
766   ipfiremake fping
767   ipfiremake telnet
768   ipfiremake xinetd
769   ipfiremake libgpg-error
770   ipfiremake libassuan
771   ipfiremake gpgme
772   ipfiremake pygpgme
773   ipfiremake pakfire3
774   ipfiremake stress
775   ipfiremake libstatgrab
776   ipfiremake sarg
777   ipfiremake check_mk_agent
778   ipfiremake libdaemon
779   ipfiremake avahi
780   ipfiremake nginx
781   ipfiremake sendEmail
782   ipfiremake sysbench
783   ipfiremake strace
784   ipfiremake ipfire-netboot
785   ipfiremake lcdproc
786   ipfiremake bitstream
787   ipfiremake multicat
788   ipfiremake keepalived
789   ipfiremake ipvsadm
790   ipfiremake perl-Carp-Clan
791   ipfiremake perl-Date-Calc
792   ipfiremake perl-Date-Manip
793   ipfiremake perl-File-Tail
794   ipfiremake perl-TimeDate
795   ipfiremake swatch
796   ipfiremake tor
797   ipfiremake arm
798   ipfiremake wavemon
799   ipfiremake iptraf-ng
800   ipfiremake iotop
801   ipfiremake stunnel
802 }
803
804 buildinstaller() {
805   # Run installer scripts one by one
806   LOGFILE="$BASEDIR/log/_build.installer.log"
807   export LOGFILE
808   ipfiremake memtest
809   ipfiremake installer
810   installmake strip
811   ipfiremake initrd
812 }
813
814 buildpackages() {
815   LOGFILE="$BASEDIR/log/_build.packages.log"
816   export LOGFILE
817   echo "... see detailed log in _build.*.log files" >> $LOGFILE
818
819   
820   # Generating list of packages used
821   echo -n "Generating packages list from logs" | tee -a $LOGFILE
822   rm -f $BASEDIR/doc/packages-list
823   for i in `ls -1tr $BASEDIR/log/[^_]*`; do
824         if [ "$i" != "$BASEDIR/log/FILES" -a -n $i ]; then
825                 echo "* `basename $i`" >>$BASEDIR/doc/packages-list
826         fi
827   done
828   echo "== List of softwares used to build $NAME Version: $VERSION ==" > $BASEDIR/doc/packages-list.txt
829   grep -v 'configroot$\|img$\|initrd$\|initscripts$\|installer$\|install$\|setup$\|pakfire$\|stage2$\|smp$\|tools$\|tools1$\|tools2$\|.tgz$\|-config$\|_missing_rootfile$\|install1$\|install2$\|pass1$\|pass2$\|pass3$' \
830         $BASEDIR/doc/packages-list | sort >> $BASEDIR/doc/packages-list.txt
831   rm -f $BASEDIR/doc/packages-list
832   # packages-list.txt is ready to be displayed for wiki page
833   beautify message DONE
834   
835   # Update changelog
836   cd $BASEDIR
837   [ -z $GIT_TAG ]  || LAST_TAG=$GIT_TAG
838   [ -z $LAST_TAG ] || EXT="$LAST_TAG..HEAD"
839   git log -n 500 --no-merges --pretty=medium --shortstat $EXT > $BASEDIR/doc/ChangeLog
840
841   # Create images for install
842   ipfiremake cdrom
843
844   # Check if there is a loop device for building in virtual environments
845   modprobe loop 2>/dev/null
846   if [ $BUILD_IMAGES == 1 ] && ([ -e /dev/loop/0 ] || [ -e /dev/loop0 ] || [ -e "/dev/loop-control" ]); then
847         ipfiremake flash-images
848   fi
849
850   mv $LFS/install/images/{*.iso,*.tgz,*.img.gz,*.bz2} $BASEDIR >> $LOGFILE 2>&1
851
852   ipfirepackages
853
854   ipfiremake xen-image
855   mv $LFS/install/images/*.bz2 $BASEDIR >> $LOGFILE 2>&1
856
857   cd $BASEDIR
858   for i in `ls *.bz2 *.img.gz *.iso`; do
859         md5sum $i > $i.md5
860   done
861   cd $PWD
862
863   # Cleanup
864   stdumount
865   rm -rf $BASEDIR/build/tmp/*
866
867   # Generating total list of files
868   echo -n "Generating files list from logs" | tee -a $LOGFILE
869   rm -f $BASEDIR/log/FILES
870   for i in `ls -1tr $BASEDIR/log/[^_]*`; do
871         if [ "$i" != "$BASEDIR/log/FILES" -a -n $i ]; then
872                 echo "##" >>$BASEDIR/log/FILES
873                 echo "## `basename $i`" >>$BASEDIR/log/FILES
874                 echo "##" >>$BASEDIR/log/FILES
875                 cat $i | sed "s%^\./%#%" | sort >> $BASEDIR/log/FILES
876         fi
877   done
878   beautify message DONE
879
880   cd $PWD
881 }
882
883 ipfirepackages() {
884         ipfiremake core-updates
885
886         local i
887         for i in $(find $BASEDIR/config/rootfiles/packages{/${MACHINE},} -maxdepth 1 -type f); do
888                 i=$(basename ${i})
889                 if [ -e $BASEDIR/lfs/$i ]; then
890                         ipfiredist $i
891                 else
892                         echo -n $i
893                         beautify message SKIP
894                 fi
895         done
896   test -d $BASEDIR/packages || mkdir $BASEDIR/packages
897   mv -f $LFS/install/packages/* $BASEDIR/packages >> $LOGFILE 2>&1
898   rm -rf  $BASEDIR/build/install/packages/*
899 }
900
901 # See what we're supposed to do
902 case "$1" in 
903 build)
904         clear
905         PACKAGE=`ls -v -r $BASEDIR/cache/toolchains/$SNAME-$VERSION-toolchain-$TOOLCHAINVER-$MACHINE.tar.gz 2> /dev/null | head -n 1`
906         #only restore on a clean disk
907         if [ ! -f log/cleanup-toolchain-2-tools ]; then
908                 if [ ! -n "$PACKAGE" ]; then
909                         beautify build_stage "Full toolchain compilation - Native GCC: `gcc --version | grep GCC | awk {'print $3'}`"
910                         prepareenv
911                         buildtoolchain
912                 else
913                         PACKAGENAME=${PACKAGE%.tar.gz}
914                         beautify build_stage "Packaged toolchain compilation"
915                         if [ `md5sum $PACKAGE | awk '{print $1}'` == `cat $PACKAGENAME.md5 | awk '{print $1}'` ]; then
916                                 tar zxf $PACKAGE
917                                 prepareenv
918                         else
919                                 exiterror "$PACKAGENAME md5 did not match, check downloaded package"
920                         fi
921                 fi
922         else
923                 echo -n "Using installed toolchain" | tee -a $LOGFILE
924                 beautify message SKIP
925                 prepareenv
926         fi
927
928         beautify build_start
929         beautify build_stage "Building LFS"
930         buildbase
931
932         beautify build_stage "Building IPFire"
933         buildipfire
934
935         beautify build_stage "Building installer"
936         buildinstaller
937
938         beautify build_stage "Building packages"
939         buildpackages
940         
941         beautify build_stage "Checking Logfiles for new Files"
942
943         cd $BASEDIR
944         tools/checknewlog.pl
945         tools/checkwronginitlinks
946         cd $PWD
947
948         beautify build_end
949         ;;
950 shell)
951         # enter a shell inside LFS chroot
952         # may be used to changed kernel settings
953         prepareenv
954         entershell
955         ;;
956 clean)
957         echo -en "${BOLD}Cleaning build directory...${NORMAL}"
958         for i in `mount | grep $BASEDIR | sed 's/^.*loop=\(.*\))/\1/'`; do
959                 $LOSETUP -d $i 2>/dev/null
960         done
961         for i in `mount | grep $BASEDIR | cut -d " " -f 1`; do
962                 umount $i
963         done
964         stdumount
965         for i in `seq 0 7`; do
966             if ( losetup /dev/loop${i} 2>/dev/null | grep -q "/install/images" ); then
967                 umount /dev/loop${i}     2>/dev/null;
968                 losetup -d /dev/loop${i} 2>/dev/null;
969             fi;
970         done
971         rm -rf $BASEDIR/build
972         rm -rf $BASEDIR/cdrom
973         rm -rf $BASEDIR/packages
974         rm -rf $BASEDIR/log
975         if [ -h /tools ]; then
976                 rm -f /tools
977         fi
978         rm -f $BASEDIR/ipfire-*
979         beautify message DONE
980         ;;
981 downloadsrc)
982         if [ ! -d $BASEDIR/cache ]; then
983                 mkdir $BASEDIR/cache
984         fi
985         mkdir -p $BASEDIR/log
986         echo -e "${BOLD}Preload all source files${NORMAL}" | tee -a $LOGFILE
987         FINISHED=0
988         cd $BASEDIR/lfs
989         for c in `seq $MAX_RETRIES`; do
990                 if (( FINISHED==1 )); then 
991                         break
992                 fi
993                 FINISHED=1
994                 cd $BASEDIR/lfs
995                 for i in *; do
996                         if [ -f "$i" -a "$i" != "Config" ]; then
997                                 lfsmakecommoncheck ${i} || continue
998
999                                 make -s -f $i LFS_BASEDIR=$BASEDIR MACHINE=$MACHINE \
1000                                         MESSAGE="$i\t ($c/$MAX_RETRIES)" download >> $LOGFILE 2>&1
1001                                 if [ $? -ne 0 ]; then
1002                                         beautify message FAIL
1003                                         FINISHED=0
1004                                 else
1005                                         if [ $c -eq 1 ]; then
1006                                         beautify message DONE
1007                                         fi
1008                                 fi
1009                         fi
1010                 done
1011         done
1012         echo -e "${BOLD}***Verifying md5sums${NORMAL}"
1013         ERROR=0
1014         for i in *; do
1015                 if [ -f "$i" -a "$i" != "Config" ]; then
1016                         lfsmakecommoncheck ${i} > /dev/null || continue
1017                         make -s -f $i LFS_BASEDIR=$BASEDIR MACHINE=$MACHINE \
1018                                 MESSAGE="$i\t " md5 >> $LOGFILE 2>&1
1019                         if [ $? -ne 0 ]; then
1020                                 echo -ne "MD5 difference in lfs/$i"
1021                                 beautify message FAIL
1022                                 ERROR=1
1023                         fi
1024                 fi
1025         done
1026         if [ $ERROR -eq 0 ]; then
1027                 echo -ne "${BOLD}all files md5sum match${NORMAL}"
1028                 beautify message DONE
1029         else
1030                 echo -ne "${BOLD}not all files were correctly download${NORMAL}"
1031                 beautify message FAIL
1032         fi
1033         cd - >/dev/null 2>&1
1034         ;;
1035 toolchain)
1036         clear
1037         prepareenv
1038         beautify build_stage "Toolchain compilation - Native GCC: `gcc --version | grep GCC | awk {'print $3'}`"
1039         buildtoolchain
1040         echo "`date -u '+%b %e %T'`: Create toolchain tar.gz for $MACHINE" | tee -a $LOGFILE
1041         test -d $BASEDIR/cache/toolchains || mkdir -p $BASEDIR/cache/toolchains
1042         cd $BASEDIR && tar -zc --exclude='log/_build.*.log' -f cache/toolchains/$SNAME-$VERSION-toolchain-$TOOLCHAINVER-$MACHINE.tar.gz \
1043                 build/tools build/bin/sh log >> $LOGFILE
1044         md5sum cache/toolchains/$SNAME-$VERSION-toolchain-$TOOLCHAINVER-$MACHINE.tar.gz \
1045                 > cache/toolchains/$SNAME-$VERSION-toolchain-$TOOLCHAINVER-$MACHINE.md5
1046         stdumount
1047         ;;
1048 gettoolchain)
1049         # arbitrary name to be updated in case of new toolchain package upload
1050         PACKAGE=$SNAME-$VERSION-toolchain-$TOOLCHAINVER-$MACHINE
1051         if [ ! -f $BASEDIR/cache/toolchains/$PACKAGE.tar.gz ]; then
1052                 URL_TOOLCHAIN=`grep URL_TOOLCHAIN lfs/Config | awk '{ print $3 }'`
1053                 test -d $BASEDIR/cache/toolchains || mkdir -p $BASEDIR/cache/toolchains
1054                 echo "`date -u '+%b %e %T'`: Load toolchain tar.gz for $MACHINE" | tee -a $LOGFILE
1055                 cd $BASEDIR/cache/toolchains
1056                 wget -U "IPFireSourceGrabber/2.x" $URL_TOOLCHAIN/$PACKAGE.tar.gz $URL_TOOLCHAIN/$PACKAGE.md5 >& /dev/null
1057                 if [ $? -ne 0 ]; then
1058                         echo "`date -u '+%b %e %T'`: error downloading $PACKAGE toolchain for $MACHINE machine" | tee -a $LOGFILE
1059                 else
1060                         if [ "`md5sum $PACKAGE.tar.gz | awk '{print $1}'`" = "`cat $PACKAGE.md5 | awk '{print $1}'`" ]; then
1061                                 echo "`date -u '+%b %e %T'`: toolchain md5 ok" | tee -a $LOGFILE
1062                         else
1063                                 exiterror "$PACKAGE.md5 did not match, check downloaded package"
1064                         fi
1065                 fi
1066         else
1067                 echo "Toolchain is already downloaded. Exiting..."
1068         fi
1069         ;;
1070 othersrc)
1071         prepareenv
1072         echo -ne "`date -u '+%b %e %T'`: Build sources iso for $MACHINE" | tee -a $LOGFILE
1073         chroot $LFS /tools/bin/env -i   HOME=/root \
1074         TERM=$TERM PS1='\u:\w\$ ' \
1075         PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin \
1076         VERSION=$VERSION NAME="$NAME" SNAME="$SNAME" MACHINE=$MACHINE \
1077         /bin/bash -x -c "cd /usr/src/lfs && make -f sources-iso LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1
1078         mv $LFS/install/images/ipfire-* $BASEDIR >> $LOGFILE 2>&1
1079         if [ $? -eq "0" ]; then
1080                 beautify message DONE
1081         else
1082                 beautify message FAIL
1083         fi
1084         stdumount
1085         ;;
1086 uploadsrc)
1087         PWD=`pwd`
1088         if [ -z $IPFIRE_USER ]; then
1089                 echo -n "You have to setup IPFIRE_USER first. See .config for details."
1090                 beautify message FAIL
1091                 exit 1
1092         fi
1093
1094         URL_SOURCE=$(grep URL_SOURCE lfs/Config | awk '{ print $3 }')
1095         REMOTE_FILES=$(echo "ls -1" | sftp -C ${IPFIRE_USER}@${URL_SOURCE})
1096
1097         for file in ${BASEDIR}/cache/*; do
1098                 [ -d "${file}" ] && continue
1099                 grep -q "$(basename ${file})" <<<$REMOTE_FILES && continue
1100                 NEW_FILES="$NEW_FILES $file"
1101         done
1102         [ -n "$NEW_FILES" ] && scp -2 $NEW_FILES ${IPFIRE_USER}@${URL_SOURCE}
1103         cd $BASEDIR
1104         cd $PWD
1105         exit 0
1106         ;;
1107 lang)
1108         update_langs
1109         ;;
1110 *)
1111         echo "Usage: $0 {build|changelog|clean|gettoolchain|downloadsrc|shell|sync|toolchain}"
1112         cat doc/make.sh-usage
1113         ;;
1114 esac