source: BLFS/gen-makefile.sh@ 24ad4fd

ablfs-more trunk
Last change on this file since 24ad4fd was 0a93085, checked in by Pierre Labastie <pierre.labastie@…>, 3 years ago

BLFS tools: Do not source envars.conf

Now the environment variables are taken from configuration.

  • Property mode set to 100755
File size: 4.3 KB
RevLine 
[6d0dbc3]1#!/bin/bash
[3c10176]2#
[6d0dbc3]3set -e
4
[e576789]5declare TOPDIR='..'
6declare ATOPDIR=`cd $TOPDIR; pwd`
[6d0dbc3]7declare MKFILE=Makefile
[3c10176]8declare PREV_PACKAGE=""
[e576789]9declare BUILD_SCRIPTS=${TOPDIR}/scripts
[8ebac92]10declare TRACKING_FILE=tracking-dir/instpkg.xml
[e576789]11declare XSLDIR=${TOPDIR}/xsl
12declare PACK_FILE=${TOPDIR}/packages.xml
13declare BUMP=${XSLDIR}/bump.xsl
[3c10176]14
[aecb378]15HEADER="# This file is automatically generated by gen-makefile.sh
[6d0dbc3]16# YOU MAY NEED TO EDIT THIS FILE MANUALLY
17#
18# Generated on `date \"+%F %X %Z\"`"
19
[3c10176]20
21#----------------------------------#
22__wrt_target() { # Create target and initialize log file
23#----------------------------------#
24 local i=$1
25 local PREV=$2
26(
27cat << EOF
28
29$i: $PREV
30 @\$(call echo_message, Building)
[fc8b962]31 @/bin/bash progress_bar.sh \$@ \$\$PPID &
[3c10176]32EOF
33) >> $MKFILE.tmp
34}
35
36
37
38#----------------------------------#
39__write_build_cmd() { #
40#----------------------------------#
41(
42cat << EOF
[0a93085]43 @${BUILD_SCRIPTS}/\$@ >logs/\$@ 2>&1
[3c10176]44EOF
45) >> $MKFILE.tmp
46}
47
48#----------------------------------#
49__wrt_touch() { #
50#----------------------------------#
[a30c80e]51local pkg_name="${1#*-?-}"
52# For having a unique id, we have added lfs- to bootscripts package.
53# We need to remove it now.
54case "$pkg_name" in lfs-bootscripts) pkg_name=bootscripts ;; esac
[f4ed135]55
56(
57cat << EOF
[e576789]58 @xsltproc --stringparam packages ${PACK_FILE} \\
[a30c80e]59 --stringparam package "${pkg_name}" \\
[e576789]60 -o track.tmp \\
61 ${BUMP} \$(TRACKING_FILE) && \\
62 sed -i 's@PACKDESC@${ATOPDIR}/packdesc.dtd@' track.tmp && \\
63 xmllint --format --postvalid track.tmp > \$(TRACKING_FILE) && \\
64 rm track.tmp && \\
65 touch \$@ && \\
[3c10176]66 sleep .25 && \\
67 echo -e "\n\n "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
68 echo --------------------------------------------------------------------------------\$(WHITE)
69EOF
70) >> $MKFILE.tmp
71}
72
73
74#----------------------------#
75__write_entry() { #
76#----------------------------#
77 local script_name=$1
[f4ed135]78
[3c10176]79 echo -n "${tab_}${tab_} entry for <$script_name>"
80
81 #--------------------------------------------------------------------#
82 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
83 #--------------------------------------------------------------------#
84 #
85 # Drop in the name of the target on a new line, and the previous target
86 # as a dependency. Also call the echo_message function.
87 __wrt_target "${script_name}" "$PREV_PACKAGE"
[dc67791]88 __write_build_cmd
[3c10176]89
90 # Include a touch of the target name so make can check
91 # if it's already been made.
[e576789]92 __wrt_touch "${script_name}"
[3c10176]93 #
94 #--------------------------------------------------------------------#
95 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
96 #--------------------------------------------------------------------#
97 echo " .. OK"
98}
99
100#----------------------------#
101generate_Makefile () { #
102#----------------------------#
103
104
105 echo "${tab_}Creating Makefile... ${BOLD}START${OFF}"
106
107 # Start with a clean files
108 >$MKFILE
109 >$MKFILE.tmp
110
[6d0dbc3]111
[e576789]112 for package_script in ${BUILD_SCRIPTS}/* ; do
[3c10176]113 this_script=`basename $package_script`
[f4ed135]114 pkg_list="$pkg_list ${this_script}"
[e576789]115 __write_entry "${this_script}"
[f4ed135]116 PREV_PACKAGE=${this_script}
[3c10176]117 done
118
119(
120 cat << EOF
121$HEADER
122
[e576789]123TRACKING_FILE= $TRACKING_FILE
[3c10176]124
125BOLD= "[0;1m"
126RED= "[1;31m"
127GREEN= "[0;32m"
128ORANGE= "[0;33m"
129BLUE= "[1;34m"
130WHITE= "[00m"
131
132define echo_message
133 @echo \$(BOLD)
134 @echo --------------------------------------------------------------------------------
135 @echo \$(BOLD)\$(1) target \$(BLUE)\$@\$(BOLD)
136 @echo \$(WHITE)
137endef
138
139
[e576789]140define end_message
[3c10176]141 @echo \$(BOLD)
142 @echo --------------------------------------------------------------------------------
143 @echo \$(BOLD) Build complete for the package \$(BLUE)\$(PACKAGE)\$(BOLD) and its dependencies
144 @echo \$(WHITE)
145endef
146
147all : $pkg_list
[e576789]148 @\$(call end_message )
[3c10176]149EOF
150) > $MKFILE
151
152 cat $MKFILE.tmp >> $MKFILE
153 echo "${tab_}Creating Makefile... ${BOLD}DONE${OFF}"
154
155 rm $MKFILE.tmp
156
157}
[6d0dbc3]158
[e576789]159if [[ ! -d ${BUILD_SCRIPTS} ]] ; then
[e253015]160 echo -e "\n\tThe '${BUILD_SCRIPTS}' directory has not been found.\n"
161 exit 1
162fi
163
164# Let us make a clean base, but first ensure that we are
165# not emptying a useful directory.
166MYDIR=$(pwd)
167MYDIR=$(basename $MYDIR)
168if [ "${MYDIR#work}" = "${MYDIR}" ] ; then
169 echo -e \\n\\tDirectory ${BOLD}$MYDIR${OFF} does not begin with \"work\"\\n
[aecb378]170 exit 1
171fi
172
[e576789]173rm -rf *
[aecb378]174
[6d0dbc3]175generate_Makefile
176
[e576789]177cp ${TOPDIR}/progress_bar.sh .
[6d0dbc3]178
179mkdir -p logs
Note: See TracBrowser for help on using the repository browser.