1 | #!/bin/bash
|
---|
2 | #
|
---|
3 | set -e
|
---|
4 |
|
---|
5 | declare TOPDIR='..'
|
---|
6 | declare ATOPDIR=`cd $TOPDIR; pwd`
|
---|
7 | declare MKFILE=Makefile
|
---|
8 | declare PREV_PACKAGE=""
|
---|
9 | declare BUILD_SCRIPTS=${TOPDIR}/scripts
|
---|
10 | declare TRACKING_FILE=tracking-dir/instpkg.xml
|
---|
11 | declare XSLDIR=${TOPDIR}/xsl
|
---|
12 | declare PACK_FILE=${TOPDIR}/packages.xml
|
---|
13 | declare BUMP=${XSLDIR}/bump.xsl
|
---|
14 |
|
---|
15 | HEADER="# 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 | (
|
---|
27 | cat << EOF
|
---|
28 |
|
---|
29 | $i: $PREV
|
---|
30 | @\$(call echo_message, Building)
|
---|
31 | @/bin/bash progress_bar.sh \$@ \$\$PPID &
|
---|
32 | EOF
|
---|
33 | ) >> $MKFILE.tmp
|
---|
34 | }
|
---|
35 |
|
---|
36 |
|
---|
37 |
|
---|
38 | #----------------------------------#
|
---|
39 | __write_build_cmd() { #
|
---|
40 | #----------------------------------#
|
---|
41 | (
|
---|
42 | cat << EOF
|
---|
43 | @${BUILD_SCRIPTS}/\$@ >logs/\$@ 2>&1
|
---|
44 | EOF
|
---|
45 | ) >> $MKFILE.tmp
|
---|
46 | }
|
---|
47 |
|
---|
48 | #----------------------------------#
|
---|
49 | __wrt_touch() { #
|
---|
50 | #----------------------------------#
|
---|
51 | local pkg_name="${1#*-?-}"
|
---|
52 | # For having a unique id, we have added lfs- to bootscripts package.
|
---|
53 | # We need to remove it now.
|
---|
54 | case "$pkg_name" in lfs-bootscripts) pkg_name=bootscripts ;; esac
|
---|
55 |
|
---|
56 | (
|
---|
57 | cat << 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)
|
---|
69 | EOF
|
---|
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 | #----------------------------#
|
---|
101 | generate_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 |
|
---|
123 | TRACKING_FILE= $TRACKING_FILE
|
---|
124 |
|
---|
125 | BOLD= "[0;1m"
|
---|
126 | RED= "[1;31m"
|
---|
127 | GREEN= "[0;32m"
|
---|
128 | ORANGE= "[0;33m"
|
---|
129 | BLUE= "[1;34m"
|
---|
130 | WHITE= "[00m"
|
---|
131 |
|
---|
132 | define echo_message
|
---|
133 | @echo \$(BOLD)
|
---|
134 | @echo --------------------------------------------------------------------------------
|
---|
135 | @echo \$(BOLD)\$(1) target \$(BLUE)\$@\$(BOLD)
|
---|
136 | @echo \$(WHITE)
|
---|
137 | endef
|
---|
138 |
|
---|
139 |
|
---|
140 | define end_message
|
---|
141 | @echo \$(BOLD)
|
---|
142 | @echo --------------------------------------------------------------------------------
|
---|
143 | @echo \$(BOLD) Build complete for the package \$(BLUE)\$(PACKAGE)\$(BOLD) and its dependencies
|
---|
144 | @echo \$(WHITE)
|
---|
145 | endef
|
---|
146 |
|
---|
147 | all : $pkg_list
|
---|
148 | @\$(call end_message )
|
---|
149 | EOF
|
---|
150 | ) > $MKFILE
|
---|
151 |
|
---|
152 | cat $MKFILE.tmp >> $MKFILE
|
---|
153 | echo "${tab_}Creating Makefile... ${BOLD}DONE${OFF}"
|
---|
154 |
|
---|
155 | rm $MKFILE.tmp
|
---|
156 |
|
---|
157 | }
|
---|
158 |
|
---|
159 | if [[ ! -d ${BUILD_SCRIPTS} ]] ; then
|
---|
160 | echo -e "\n\tThe '${BUILD_SCRIPTS}' directory has not been found.\n"
|
---|
161 | exit 1
|
---|
162 | fi
|
---|
163 |
|
---|
164 | # Let us make a clean base, but first ensure that we are
|
---|
165 | # not emptying a useful directory.
|
---|
166 | MYDIR=$(pwd)
|
---|
167 | MYDIR=$(basename $MYDIR)
|
---|
168 | if [ "${MYDIR#work}" = "${MYDIR}" ] ; then
|
---|
169 | echo -e \\n\\tDirectory ${BOLD}$MYDIR${OFF} does not begin with \"work\"\\n
|
---|
170 | exit 1
|
---|
171 | fi
|
---|
172 |
|
---|
173 | rm -rf *
|
---|
174 |
|
---|
175 | generate_Makefile
|
---|
176 |
|
---|
177 | cp ${TOPDIR}/progress_bar.sh .
|
---|
178 |
|
---|
179 | mkdir -p logs
|
---|