source: BLFS/gen-makefile.sh@ cd87e52

ablfs-more trunk
Last change on this file since cd87e52 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
Line 
1#!/bin/bash
2#
3set -e
4
5declare TOPDIR='..'
6declare ATOPDIR=`cd $TOPDIR; pwd`
7declare MKFILE=Makefile
8declare PREV_PACKAGE=""
9declare BUILD_SCRIPTS=${TOPDIR}/scripts
10declare TRACKING_FILE=tracking-dir/instpkg.xml
11declare XSLDIR=${TOPDIR}/xsl
12declare PACK_FILE=${TOPDIR}/packages.xml
13declare BUMP=${XSLDIR}/bump.xsl
14
15HEADER="# This file is automatically generated by gen-makefile.sh
16# YOU MAY NEED TO EDIT THIS FILE MANUALLY
17#
18# Generated on `date \"+%F %X %Z\"`"
19
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)
31 @/bin/bash progress_bar.sh \$@ \$\$PPID &
32EOF
33) >> $MKFILE.tmp
34}
35
36
37
38#----------------------------------#
39__write_build_cmd() { #
40#----------------------------------#
41(
42cat << EOF
43 @${BUILD_SCRIPTS}/\$@ >logs/\$@ 2>&1
44EOF
45) >> $MKFILE.tmp
46}
47
48#----------------------------------#
49__wrt_touch() { #
50#----------------------------------#
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
55
56(
57cat << EOF
58 @xsltproc --stringparam packages ${PACK_FILE} \\
59 --stringparam package "${pkg_name}" \\
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 \$@ && \\
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
78
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"
88 __write_build_cmd
89
90 # Include a touch of the target name so make can check
91 # if it's already been made.
92 __wrt_touch "${script_name}"
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
111
112 for package_script in ${BUILD_SCRIPTS}/* ; do
113 this_script=`basename $package_script`
114 pkg_list="$pkg_list ${this_script}"
115 __write_entry "${this_script}"
116 PREV_PACKAGE=${this_script}
117 done
118
119(
120 cat << EOF
121$HEADER
122
123TRACKING_FILE= $TRACKING_FILE
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
140define end_message
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
148 @\$(call end_message )
149EOF
150) > $MKFILE
151
152 cat $MKFILE.tmp >> $MKFILE
153 echo "${tab_}Creating Makefile... ${BOLD}DONE${OFF}"
154
155 rm $MKFILE.tmp
156
157}
158
159if [[ ! -d ${BUILD_SCRIPTS} ]] ; then
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
170 exit 1
171fi
172
173rm -rf *
174
175generate_Makefile
176
177cp ${TOPDIR}/progress_bar.sh .
178
179mkdir -p logs
Note: See TracBrowser for help on using the repository browser.