source: LFS/master.sh@ bfcaaa0

experimental
Last change on this file since bfcaaa0 was aafcfa9, checked in by Manuel Canales Esparcia <manuel@…>, 17 years ago

Makefile envars and fuctions revised.

  • Property mode set to 100644
File size: 14.1 KB
RevLine 
[9c9775f]1#!/bin/bash
[0170229]2
[a46ada0]3# $Id$
[0170229]4
5###################################
6### FUNCTIONS ###
7###################################
8
9
[50fb011]10#############################################################
11
12
[0170229]13#----------------------------#
[50fb011]14chapter4_Makefiles() { #
[0170229]15#----------------------------#
[50fb011]16 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter4 ( SETUP ) ${R_arrow}"
[0170229]17
[9c9775f]18# If $LUSER_HOME is already present in the host, we asume that the
[0170229]19# lfs user and group are also presents in the host, and a backup
20# of their bash init files is made.
21(
22 cat << EOF
[3b6adab]2304_02-creatingtoolsdir:
[0170229]24 @\$(call echo_message, Building)
[9199a13]25 @mkdir \$(MOUNT_PT)/tools && \\
26 rm -f /tools && \\
[9c9775f]27 ln -s \$(MOUNT_PT)/tools /
28 @\$(call housekeeping)
[0170229]29
[c5ae20a]3004_03-addinguser: 04_02-creatingtoolsdir
[0170229]31 @\$(call echo_message, Building)
[9c9775f]32 @if [ ! -d \$(LUSER_HOME) ]; then \\
[9485eba]33 groupadd \$(LGROUP); \\
34 useradd -s /bin/bash -g \$(LGROUP) -m -k /dev/null \$(LUSER); \\
[0170229]35 else \\
[30737ea8]36 touch luser-exist; \\
[0170229]37 fi;
[9485eba]38 @chown \$(LUSER) \$(MOUNT_PT)/tools && \\
[9c9775f]39 chmod -R a+wt \$(MOUNT_PT)/\$(SCRIPT_ROOT) && \\
40 chmod a+wt \$(SRCSDIR)
41 @\$(call housekeeping)
[0170229]42
[c5ae20a]4304_04-settingenvironment: 04_03-addinguser
[0170229]44 @\$(call echo_message, Building)
[9c9775f]45 @if [ -f \$(LUSER_HOME)/.bashrc -a ! -f \$(LUSER_HOME)/.bashrc.XXX ]; then \\
46 mv \$(LUSER_HOME)/.bashrc \$(LUSER_HOME)/.bashrc.XXX; \\
[0170229]47 fi;
[9c9775f]48 @if [ -f \$(LUSER_HOME)/.bash_profile -a ! -f \$(LUSER_HOME)/.bash_profile.XXX ]; then \\
49 mv \$(LUSER_HOME)/.bash_profile \$(LUSER_HOME)/.bash_profile.XXX; \\
[0170229]50 fi;
[9c9775f]51 @echo "set +h" > \$(LUSER_HOME)/.bashrc && \\
52 echo "umask 022" >> \$(LUSER_HOME)/.bashrc && \\
53 echo "LFS=\$(MOUNT_PT)" >> \$(LUSER_HOME)/.bashrc && \\
54 echo "LC_ALL=POSIX" >> \$(LUSER_HOME)/.bashrc && \\
55 echo "PATH=/tools/bin:/bin:/usr/bin" >> \$(LUSER_HOME)/.bashrc && \\
56 echo "export LFS LC_ALL PATH" >> \$(LUSER_HOME)/.bashrc && \\
[f5f857d]57 chown \$(LUSER):\$(LGROUP) \$(LUSER_HOME)/.bashrc
[9c9775f]58 @\$(call housekeeping)
[0170229]59EOF
[50fb011]60) > $MKFILE.tmp
61
[3b6adab]62 chapter4=" 04_02-creatingtoolsdir 04_03-addinguser 04_04-settingenvironment"
[0170229]63}
64
[50fb011]65
66
[0170229]67#----------------------------#
68chapter5_Makefiles() {
69#----------------------------#
[50fb011]70 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter5 ( LUSER ) ${R_arrow}"
[12a5707]71
[0170229]72 for file in chapter05/* ; do
73 # Keep the script file name
74 this_script=`basename $file`
75
76 # If no testsuites will be run, then TCL, Expect and DejaGNU aren't needed
[af4c7b1]77 case "${this_script}" in
78 *tcl) [[ "${TEST}" = "0" ]] && continue ;;
79 *expect) [[ "${TEST}" = "0" ]] && continue ;;
80 *dejagnu) [[ "${TEST}" = "0" ]] && continue ;;
[47fddc8]81 *stripping) [[ "${STRIP}" = "n" ]] && continue ;;
[af4c7b1]82 esac
[6b1576a]83
[0170229]84 # First append each name of the script files to a list (this will become
85 # the names of the targets in the Makefile
[9c9775f]86 # DO NOT append the changingowner script, it need be run as root.
[50fb011]87 # A hack is necessary: create script in chap5 BUT run as a dependency for
[9c9775f]88 # SUDO target
[50fb011]89 case "${this_script}" in
[9c9775f]90 *changingowner) runasroot="$runasroot ${this_script}" ;;
[50fb011]91 *) chapter5="$chapter5 ${this_script}" ;;
92 esac
[0170229]93
94 # Set the dependency for the first target.
[3b6adab]95 if [ -z $PREV ] ; then PREV=04_04-settingenvironment ; fi
[0170229]96
[3f858ca]97 #--------------------------------------------------------------------#
98 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
99 #--------------------------------------------------------------------#
100 #
[0170229]101 # Drop in the name of the target on a new line, and the previous target
102 # as a dependency. Also call the echo_message function.
[aafcfa9]103 wrt_target "${this_script}" "$PREV"
[0170229]104
[3b6adab]105 # Run the script.
[fed9756]106 # The changingowner script must be run as root.
107 case "${this_script}" in
[9c9775f]108 *changingowner) wrt_RunAsRoot "$file" ;;
[aafcfa9]109 *) wrt_RunScript "$file" ;;
[fed9756]110 esac
[0170229]111
112 # Include a touch of the target name so make can check
113 # if it's already been made.
[9199a13]114 wrt_touch
[3f858ca]115 #
116 #--------------------------------------------------------------------#
117 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
118 #--------------------------------------------------------------------#
[0170229]119
120 # Keep the script file name for Makefile dependencies.
121 PREV=${this_script}
122 done # end for file in chapter05/*
123}
124
[50fb011]125
[0170229]126#----------------------------#
127chapter6_Makefiles() {
128#----------------------------#
[50fb011]129
[615e37d]130 # Set envars and scripts for iteration targets
[b242136]131 if [[ -z "$1" ]] ; then
[aa08925]132 local N=""
133 else
134 local N=-build_$1
135 local chapter6=""
[615e37d]136 mkdir chapter06$N
137 cp chapter06/* chapter06$N
138 for script in chapter06$N/* ; do
[7aee0dd]139 # Overwrite existing symlinks, files, and dirs
[615e37d]140 sed -e 's/ln -sv/&f/g' \
141 -e 's/mv -v/&f/g' \
[7aee0dd]142 -e 's/mkdir -v/&p/g' -i ${script}
[9c9775f]143 # Rename the scripts
144 mv ${script} ${script}$N
[615e37d]145 done
[aa08925]146 fi
147
[50fb011]148 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter6$N ( CHROOT ) ${R_arrow}"
[af4c7b1]149
[615e37d]150 for file in chapter06$N/* ; do
[0170229]151 # Keep the script file name
152 this_script=`basename $file`
153
154 # We'll run the chroot commands differently than the others, so skip them in the
155 # dependencies and target creation.
[9c9775f]156 # Skip also linux-headers in iterative builds.
[af4c7b1]157 case "${this_script}" in
158 *chroot) continue ;;
[47fddc8]159 *stripping*) [[ "${STRIP}" = "n" ]] && continue ;;
[9c9775f]160 *linux-headers*) [[ -n "$N" ]] && continue ;;
[af4c7b1]161 esac
[0170229]162
[6bf3770]163 # If building a package, grab the phase name to be used with INSTALL_LOG
164 name=`grep "^PKG_PHASE=" ${file} | sed -e 's@PKG_PHASE=@@'`
[b242136]165
[3b6adab]166 # Skip scripts not needed for iterations rebuilds
167 if [[ "$name" = "" ]] && [[ -n "$N" ]] ; then
[b242136]168 case "${this_script}" in
169 *stripping*) ;;
170 *) continue ;;
171 esac
172 fi
173
[4edbc92]174 # Append each name of the script files to a list (this will become
175 # the names of the targets in the Makefile)
[9c9775f]176 # The kernfs script must be run as part of SUDO target.
177 case "${this_script}" in
178 *kernfs) runasroot="$runasroot ${this_script}" ;;
179 *) chapter6="$chapter6 ${this_script}" ;;
180 esac
[4edbc92]181
[3f858ca]182 #--------------------------------------------------------------------#
183 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
184 #--------------------------------------------------------------------#
185 #
[0170229]186 # Drop in the name of the target on a new line, and the previous target
187 # as a dependency. Also call the echo_message function.
[aafcfa9]188 wrt_target "${this_script}" "$PREV"
[0170229]189
[f5f857d]190 # Touch timestamp file if installed files logs will be created.
191 # But only for the firt build when running iterative builds.
192 if [ "$name" != "" ] && [ "${INSTALL_LOG}" = "y" ] && [ "x${N}" = "x" ] ; then
[aafcfa9]193 wrt_TouchTimestamp
[0170229]194 fi
195
196 # In the mount of kernel filesystems we need to set LFS
197 # and not to use chroot.
[af4c7b1]198 case "${this_script}" in
[aafcfa9]199 *kernfs) wrt_RunAsRoot "$file" ;;
200 *) wrt_RunScript "$file" ;;
[af4c7b1]201 esac
[0170229]202
[3b6adab]203 # Write installed files log
204 if [ "$name" != "" ] && [ "${INSTALL_LOG}" = "y" ] && [ "x${N}" = "x" ] ; then
[aafcfa9]205 wrt_LogNewFiles "$name"
[0170229]206 fi
207
208 # Include a touch of the target name so make can check
209 # if it's already been made.
[9199a13]210 wrt_touch
[3f858ca]211 #
212 #--------------------------------------------------------------------#
213 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
214 #--------------------------------------------------------------------#
[0170229]215
216 # Keep the script file name for Makefile dependencies.
[9c9775f]217 PREV=${this_script}
[aa08925]218 # Set system_build envar for iteration targets
219 system_build=$chapter6
[0170229]220 done # end for file in chapter06/*
221}
222
223#----------------------------#
[9c9775f]224chapter78_Makefiles() {
[0170229]225#----------------------------#
[9c9775f]226 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter7/8 ( BOOT ) ${R_arrow}"
[af4c7b1]227
[9c9775f]228 for file in chapter0{7,8}/* ; do
[0170229]229 # Keep the script file name
230 this_script=`basename $file`
231
232 # Grub must be configured manually.
[9c9775f]233 # Handle fstab creation.
[0170229]234 # If no .config file is supplied, the kernel build is skipped
[0271c0c]235 case ${this_script} in
236 *grub) continue ;;
[50fb011]237 *fstab) [[ ! -z ${FSTAB} ]] && cp ${FSTAB} $BUILDDIR/sources/fstab ;;
[0271c0c]238 *kernel) [[ -z ${CONFIG} ]] && continue
239 cp ${CONFIG} $BUILDDIR/sources/kernel-config ;;
240 esac
[0170229]241
242 # First append each name of the script files to a list (this will become
243 # the names of the targets in the Makefile
[9c9775f]244 chapter78="$chapter78 ${this_script}"
[0170229]245
[3f858ca]246 #--------------------------------------------------------------------#
247 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
248 #--------------------------------------------------------------------#
249 #
[0170229]250 # Drop in the name of the target on a new line, and the previous target
251 # as a dependency. Also call the echo_message function.
[aafcfa9]252 wrt_target "${this_script}" "$PREV"
[0170229]253
[3b6adab]254 # For bootscripts and kernel, start INSTALL_LOG if requested
[af4c7b1]255 case "${this_script}" in
[3b6adab]256 *bootscripts | *kernel ) if [ "${INSTALL_LOG}" = "y" ] ; then
[aafcfa9]257 wrt_TouchTimestamp
258 fi ;;
[af4c7b1]259 esac
[6b1576a]260
[0170229]261 # Check if we have a real /etc/fstab file
[af4c7b1]262 case "${this_script}" in
263 *fstab) if [[ -n $FSTAB ]]; then
[aafcfa9]264 wrt_CopyFstab
[af4c7b1]265 else
[aafcfa9]266 wrt_RunScript "$file"
267 fi ;;
268 *) wrt_RunScript "$file" ;;
[af4c7b1]269 esac
[0170229]270
[af4c7b1]271 case "${this_script}" in
[3b6adab]272 *bootscripts) if [ "${INSTALL_LOG}" = "y" ] ; then
[aafcfa9]273 wrt_LogNewFiles "lfs-bootscripts"
[9c9775f]274 fi ;;
[3b6adab]275 *kernel) if [ "${INSTALL_LOG}" = "y" ] ; then
[aafcfa9]276 wrt_LogNewFiles "linux"
[9c9775f]277 fi ;;
[af4c7b1]278 esac
[6b1576a]279
[0170229]280 # Include a touch of the target name so make can check
281 # if it's already been made.
[9199a13]282 wrt_touch
[3f858ca]283 #
284 #--------------------------------------------------------------------#
285 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
286 #--------------------------------------------------------------------#
[0170229]287
288 # Keep the script file name for Makefile dependencies.
289 PREV=${this_script}
[9c9775f]290 done # for file in chapter0{7,8}/*
[9e4b9a1]291
[0170229]292}
293
294
[50fb011]295
[0170229]296#----------------------------#
[50fb011]297build_Makefile() { #
[0170229]298#----------------------------#
[50fb011]299
[a702b4d]300 echo "Creating Makefile... ${BOLD}START${OFF}"
[03b3eba]301
[0170229]302 cd $JHALFSDIR/${PROGNAME}-commands
303
304 # Start with a clean Makefile.tmp file
[50fb011]305 >$MKFILE
[03b3eba]306
[0170229]307 chapter4_Makefiles
308 chapter5_Makefiles
309 chapter6_Makefiles
[4edbc92]310 # Add the iterations targets, if needed
[47fddc8]311 [[ "$COMPARE" = "y" ]] && wrt_compare_targets
[9c9775f]312 chapter78_Makefiles
313 # Add the CUSTOM_TOOLS targets, if needed
314 [[ "$CUSTOM_TOOLS" = "y" ]] && wrt_CustomTools_target
[fd7455c]315 # Add the BLFS_TOOL targets, if needed
316 [[ "$BLFS_TOOL" = "y" ]] && wrt_blfs_tool_targets
[0170229]317
318 # Add a header, some variables and include the function file
319 # to the top of the real Makefile.
[9c9775f]320 wrt_Makefile_header
[0170229]321
322 # Add chroot commands
[8381f6e]323 CHROOT_LOC="`whereis -b chroot | cut -d " " -f2`"
[0170229]324 i=1
325 for file in chapter06/*chroot* ; do
[3b6adab]326 chroot=`cat $file | tr -d '\n' | \
[8381f6e]327 sed -e "s@chroot@$CHROOT_LOC@" \
[3b6adab]328 -e 's@ \\\@ @g' \
[f5f857d]329 -e 's/ */ /g' \
[8381f6e]330 -e 's|\\$|&&|g' \
331 -e 's|"$$LFS"|$(MOUNT_PT)|' \
[3b6adab]332 -e 's|$| -c|'`
[0170229]333 echo -e "CHROOT$i= $chroot\n" >> $MKFILE
334 i=`expr $i + 1`
335 done
336
337 # Drop in the main target 'all:' and the chapter targets with each sub-target
338 # as a dependency.
339(
340 cat << EOF
[50fb011]341
[9c9775f]342all: ck_UID mk_SETUP mk_LUSER mk_SUDO mk_CHROOT mk_BOOT create-sbu_du-report mk_CUSTOM_TOOLS mk_BLFS_TOOL
[4012541]343 @sudo make do_housekeeping
[9c9775f]344 @echo "$VERSION - jhalfs build" > lfs-release && \\
345 sudo mv lfs-release \$(MOUNT_PT)/etc
[0170229]346 @\$(call echo_finished,$VERSION)
347
[7d4cc81]348ck_UID:
349 @if [ \`id -u\` = "0" ]; then \\
350 echo "--------------------------------------------------"; \\
351 echo "You cannot run this makefile from the root account"; \\
352 echo "--------------------------------------------------"; \\
353 exit 1; \\
354 fi
[0167dd8]355
[50fb011]356mk_SETUP:
357 @\$(call echo_SU_request)
[9c9775f]358 @sudo make BREAKPOINT=\$(BREAKPOINT) SETUP
[50fb011]359 @touch \$@
[03b3eba]360
[50fb011]361mk_LUSER: mk_SETUP
362 @\$(call echo_SULUSER_request)
[9c9775f]363 @( sudo \$(SU_LUSER) "source .bashrc && cd \$(MOUNT_PT)/\$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) LUSER" )
[621f01f]364 @sudo make restore-luser-env
[50fb011]365 @touch \$@
[7d4cc81]366
367mk_SUDO: mk_LUSER
[9c9775f]368 @sudo make BREAKPOINT=\$(BREAKPOINT) SUDO
369 @touch \$@
370
[496f8f3]371mk_CHROOT: mk_SUDO
[50fb011]372 @\$(call echo_CHROOT_request)
[9c9775f]373 @( sudo \$(CHROOT1) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) CHROOT")
[50fb011]374 @touch \$@
375
[03b3eba]376mk_BOOT: mk_CHROOT
[50fb011]377 @\$(call echo_CHROOT_request)
[9c9775f]378 @( sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) BOOT")
[50fb011]379 @touch \$@
[03b3eba]380
[9c9775f]381mk_CUSTOM_TOOLS: create-sbu_du-report
382 @if [ "\$(ADD_CUSTOM_TOOLS)" = "y" ]; then \\
383 \$(call sh_echo_PHASE,Building CUSTOM_TOOLS); \\
384 sudo mkdir -p ${BUILDDIR}${TRACKING_DIR}; \\
385 (sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) CUSTOM_TOOLS"); \\
386 fi;
387 @touch \$@
[50fb011]388
[9c9775f]389mk_BLFS_TOOL: mk_CUSTOM_TOOLS
390 @if [ "\$(ADD_BLFS_TOOLS)" = "y" ]; then \\
391 \$(call sh_echo_PHASE,Building BLFS_TOOL); \\
392 sudo mkdir -p $BUILDDIR$TRACKING_DIR; \\
393 (sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) BLFS_TOOL"); \\
394 fi;
395 @touch \$@
[50fb011]396
[7d4cc81]397
[9c9775f]398SETUP: $chapter4
399LUSER: $chapter5
400SUDO: $runasroot
401CHROOT: SHELL=/tools/bin/bash
402CHROOT: $chapter6
403BOOT: $chapter78
404CUSTOM_TOOLS: $custom_list
405BLFS_TOOL: $blfs_tool
[50fb011]406
[0170229]407
[9c9775f]408create-sbu_du-report: mk_BOOT
409 @\$(call echo_message, Building)
410 @if [ "\$(ADD_REPORT)" = "y" ]; then \\
411 ./create-sbu_du-report.sh logs $VERSION; \\
412 \$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report); \\
413 fi;
414 @touch \$@
[0170229]415
[30737ea8]416restore-luser-env:
[0170229]417 @\$(call echo_message, Building)
[9c9775f]418 @if [ -f \$(LUSER_HOME)/.bashrc.XXX ]; then \\
419 mv -f \$(LUSER_HOME)/.bashrc.XXX \$(LUSER_HOME)/.bashrc; \\
[0170229]420 fi;
[9c9775f]421 @if [ -f \$(LUSER_HOME)/.bash_profile.XXX ]; then \\
422 mv \$(LUSER_HOME)/.bash_profile.XXX \$(LUSER_HOME)/.bash_profile; \\
[0170229]423 fi;
[9c9775f]424 @chown \$(LUSER):\$(LGROUP) \$(LUSER_HOME)/.bash*
425 @\$(call housekeeping)
[460ea63]426
[3a27393]427do_housekeeping:
[9199a13]428 @-umount \$(MOUNT_PT)/sys
429 @-umount \$(MOUNT_PT)/proc
430 @-umount \$(MOUNT_PT)/dev/shm
431 @-umount \$(MOUNT_PT)/dev/pts
432 @-umount \$(MOUNT_PT)/dev
[0167dd8]433 @-rm /tools
[30737ea8]434 @-if [ ! -f luser-exist ]; then \\
[9485eba]435 userdel \$(LUSER); \\
[9c9775f]436 rm -rf \$(LUSER_HOME); \\
[3a27393]437 fi;
[460ea63]438
[9199a13]439
[42346b2]440EOF
441) >> $MKFILE
442
[0170229]443 # Bring over the items from the Makefile.tmp
444 cat $MKFILE.tmp >> $MKFILE
445 rm $MKFILE.tmp
[a702b4d]446 echo "Creating Makefile... ${BOLD}DONE${OFF}"
447}
Note: See TracBrowser for help on using the repository browser.