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