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 |
|
---|
55 | (
|
---|
56 | cat << EOF
|
---|
57 | @xsltproc --stringparam packages ${PACK_FILE} \\
|
---|
58 | --stringparam package ${pkg_name#*-?-} \\
|
---|
59 | -o track.tmp \\
|
---|
60 | ${BUMP} \$(TRACKING_FILE) && \\
|
---|
61 | sed -i 's@PACKDESC@${ATOPDIR}/packdesc.dtd@' track.tmp && \\
|
---|
62 | xmllint --format --postvalid track.tmp > \$(TRACKING_FILE) && \\
|
---|
63 | rm track.tmp && \\
|
---|
64 | touch \$@ && \\
|
---|
65 | sleep .25 && \\
|
---|
66 | echo -e "\n\n "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
|
---|
67 | echo --------------------------------------------------------------------------------\$(WHITE)
|
---|
68 | EOF
|
---|
69 | ) >> $MKFILE.tmp
|
---|
70 | }
|
---|
71 |
|
---|
72 |
|
---|
73 | #----------------------------#
|
---|
74 | __write_entry() { #
|
---|
75 | #----------------------------#
|
---|
76 | local script_name=$1
|
---|
77 |
|
---|
78 | echo -n "${tab_}${tab_} entry for <$script_name>"
|
---|
79 |
|
---|
80 | #--------------------------------------------------------------------#
|
---|
81 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
82 | #--------------------------------------------------------------------#
|
---|
83 | #
|
---|
84 | # Drop in the name of the target on a new line, and the previous target
|
---|
85 | # as a dependency. Also call the echo_message function.
|
---|
86 | __wrt_target "${script_name}" "$PREV_PACKAGE"
|
---|
87 | __write_build_cmd
|
---|
88 |
|
---|
89 | # Include a touch of the target name so make can check
|
---|
90 | # if it's already been made.
|
---|
91 | __wrt_touch "${script_name}"
|
---|
92 | #
|
---|
93 | #--------------------------------------------------------------------#
|
---|
94 | # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
|
---|
95 | #--------------------------------------------------------------------#
|
---|
96 | echo " .. OK"
|
---|
97 | }
|
---|
98 |
|
---|
99 | #----------------------------#
|
---|
100 | generate_Makefile () { #
|
---|
101 | #----------------------------#
|
---|
102 |
|
---|
103 |
|
---|
104 | echo "${tab_}Creating Makefile... ${BOLD}START${OFF}"
|
---|
105 |
|
---|
106 | # Start with a clean files
|
---|
107 | >$MKFILE
|
---|
108 | >$MKFILE.tmp
|
---|
109 |
|
---|
110 |
|
---|
111 | for package_script in ${BUILD_SCRIPTS}/* ; do
|
---|
112 | this_script=`basename $package_script`
|
---|
113 | pkg_list="$pkg_list ${this_script}"
|
---|
114 | __write_entry "${this_script}"
|
---|
115 | PREV_PACKAGE=${this_script}
|
---|
116 | done
|
---|
117 |
|
---|
118 | (
|
---|
119 | cat << EOF
|
---|
120 | $HEADER
|
---|
121 |
|
---|
122 | TRACKING_FILE= $TRACKING_FILE
|
---|
123 |
|
---|
124 | BOLD= "[0;1m"
|
---|
125 | RED= "[1;31m"
|
---|
126 | GREEN= "[0;32m"
|
---|
127 | ORANGE= "[0;33m"
|
---|
128 | BLUE= "[1;34m"
|
---|
129 | WHITE= "[00m"
|
---|
130 |
|
---|
131 | define echo_message
|
---|
132 | @echo \$(BOLD)
|
---|
133 | @echo --------------------------------------------------------------------------------
|
---|
134 | @echo \$(BOLD)\$(1) target \$(BLUE)\$@\$(BOLD)
|
---|
135 | @echo \$(WHITE)
|
---|
136 | endef
|
---|
137 |
|
---|
138 |
|
---|
139 | define end_message
|
---|
140 | @echo \$(BOLD)
|
---|
141 | @echo --------------------------------------------------------------------------------
|
---|
142 | @echo \$(BOLD) Build complete for the package \$(BLUE)\$(PACKAGE)\$(BOLD) and its dependencies
|
---|
143 | @echo \$(WHITE)
|
---|
144 | endef
|
---|
145 |
|
---|
146 | all : $pkg_list
|
---|
147 | @\$(call end_message )
|
---|
148 | EOF
|
---|
149 | ) > $MKFILE
|
---|
150 |
|
---|
151 | cat $MKFILE.tmp >> $MKFILE
|
---|
152 | echo "${tab_}Creating Makefile... ${BOLD}DONE${OFF}"
|
---|
153 |
|
---|
154 | rm $MKFILE.tmp
|
---|
155 |
|
---|
156 | }
|
---|
157 |
|
---|
158 | if [[ ! -d ${BUILD_SCRIPTS} ]] ; then
|
---|
159 | echo -e "\n\tThe '${BUILD_SCRIPTS}' directory has not been found.\n"
|
---|
160 | exit 1
|
---|
161 | fi
|
---|
162 |
|
---|
163 | # Let us make a clean base, but first ensure that we are
|
---|
164 | # not emptying a useful directory.
|
---|
165 | MYDIR=$(pwd)
|
---|
166 | MYDIR=$(basename $MYDIR)
|
---|
167 | if [ "${MYDIR#work}" = "${MYDIR}" ] ; then
|
---|
168 | echo -e \\n\\tDirectory ${BOLD}$MYDIR${OFF} does not begin with \"work\"\\n
|
---|
169 | exit 1
|
---|
170 | fi
|
---|
171 |
|
---|
172 | rm -rf *
|
---|
173 |
|
---|
174 | generate_Makefile
|
---|
175 |
|
---|
176 | cp ${TOPDIR}/progress_bar.sh .
|
---|
177 |
|
---|
178 | mkdir -p logs
|
---|