source: BLFS/gen-makefile.sh@ e253015

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

When running BLFS/gen-makefile.sh, the current working directory is emptied.
If this is not the directory you intended to work in, you may erase precious
data. So only erase data in directories whose name begin with "work".

  • Property mode set to 100755
File size: 4.2 KB
RevLine 
[6d0dbc3]1#!/bin/bash
[3c10176]2#
3# $Id$
[6d0dbc3]4#
5set -e
6
[e576789]7declare TOPDIR='..'
8declare ATOPDIR=`cd $TOPDIR; pwd`
[6d0dbc3]9declare MKFILE=Makefile
[3c10176]10declare PREV_PACKAGE=""
[e576789]11declare BUILD_SCRIPTS=${TOPDIR}/scripts
[e253015]12declare TRACKING_FILE=/var/lib/jhalfs/BLFS/instpkg.xml
[e576789]13declare XSLDIR=${TOPDIR}/xsl
14declare PACK_FILE=${TOPDIR}/packages.xml
15declare BUMP=${XSLDIR}/bump.xsl
[3c10176]16
[aecb378]17HEADER="# This file is automatically generated by gen-makefile.sh
[6d0dbc3]18# YOU MAY NEED TO EDIT THIS FILE MANUALLY
19#
20# Generated on `date \"+%F %X %Z\"`"
21
[3c10176]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)
[fc8b962]33 @/bin/bash progress_bar.sh \$@ \$\$PPID &
[3c10176]34EOF
35) >> $MKFILE.tmp
36}
37
38
39
40#----------------------------------#
41__write_build_cmd() { #
42#----------------------------------#
43(
44cat << EOF
[e576789]45 @source ${TOPDIR}/envars.conf && ${BUILD_SCRIPTS}/\$@ >logs/\$@ 2>&1
[3c10176]46EOF
47) >> $MKFILE.tmp
48}
49
50#----------------------------------#
51__wrt_touch() { #
52#----------------------------------#
53 local pkg_name=$1
[f4ed135]54
55(
56cat << EOF
[e576789]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 \$@ && \\
[3c10176]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
[f4ed135]77
[3c10176]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"
[dc67791]87 __write_build_cmd
[3c10176]88
89 # Include a touch of the target name so make can check
90 # if it's already been made.
[e576789]91 __wrt_touch "${script_name}"
[3c10176]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
[6d0dbc3]110
[e576789]111 for package_script in ${BUILD_SCRIPTS}/* ; do
[3c10176]112 this_script=`basename $package_script`
[f4ed135]113 pkg_list="$pkg_list ${this_script}"
[e576789]114 __write_entry "${this_script}"
[f4ed135]115 PREV_PACKAGE=${this_script}
[3c10176]116 done
117
118(
119 cat << EOF
120$HEADER
121
[e576789]122TRACKING_FILE= $TRACKING_FILE
[3c10176]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
[e576789]139define end_message
[3c10176]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
[e576789]147 @\$(call end_message )
[3c10176]148EOF
149) > $MKFILE
150
151 cat $MKFILE.tmp >> $MKFILE
152 echo "${tab_}Creating Makefile... ${BOLD}DONE${OFF}"
153
154 rm $MKFILE.tmp
155
156}
[6d0dbc3]157
[e576789]158if [[ ! -d ${BUILD_SCRIPTS} ]] ; then
[e253015]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
[aecb378]169 exit 1
170fi
171
[e576789]172rm -rf *
[aecb378]173
[6d0dbc3]174generate_Makefile
175
[e576789]176cp ${TOPDIR}/progress_bar.sh .
[6d0dbc3]177
178mkdir -p logs
Note: See TracBrowser for help on using the repository browser.