source: BLFS/gen-makefile.sh@ 2cef19f

ablfs-more legacy trunk
Last change on this file since 2cef19f was 8ebac92, checked in by Pierre Labastie <pierre@…>, 9 years ago

Preceding commit fix

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