[6d0dbc3] | 1 | #!/bin/bash
|
---|
[3c10176] | 2 | #
|
---|
[6d0dbc3] | 3 | set -e
|
---|
| 4 |
|
---|
[e576789] | 5 | declare TOPDIR='..'
|
---|
| 6 | declare ATOPDIR=`cd $TOPDIR; pwd`
|
---|
[6d0dbc3] | 7 | declare MKFILE=Makefile
|
---|
[3c10176] | 8 | declare PREV_PACKAGE=""
|
---|
[e576789] | 9 | declare BUILD_SCRIPTS=${TOPDIR}/scripts
|
---|
[8ebac92] | 10 | declare TRACKING_FILE=tracking-dir/instpkg.xml
|
---|
[e576789] | 11 | declare XSLDIR=${TOPDIR}/xsl
|
---|
| 12 | declare PACK_FILE=${TOPDIR}/packages.xml
|
---|
| 13 | declare BUMP=${XSLDIR}/bump.xsl
|
---|
[3c10176] | 14 |
|
---|
[aecb378] | 15 | HEADER="# This file is automatically generated by gen-makefile.sh
|
---|
[6d0dbc3] | 16 | # YOU MAY NEED TO EDIT THIS FILE MANUALLY
|
---|
| 17 | #
|
---|
| 18 | # Generated on `date \"+%F %X %Z\"`"
|
---|
| 19 |
|
---|
[3c10176] | 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)
|
---|
[fc8b962] | 31 | @/bin/bash progress_bar.sh \$@ \$\$PPID &
|
---|
[3c10176] | 32 | EOF
|
---|
| 33 | ) >> $MKFILE.tmp
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 |
|
---|
| 37 |
|
---|
| 38 | #----------------------------------#
|
---|
| 39 | __write_build_cmd() { #
|
---|
| 40 | #----------------------------------#
|
---|
| 41 | (
|
---|
| 42 | cat << EOF
|
---|
[0a93085] | 43 | @${BUILD_SCRIPTS}/\$@ >logs/\$@ 2>&1
|
---|
[3c10176] | 44 | EOF
|
---|
| 45 | ) >> $MKFILE.tmp
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | #----------------------------------#
|
---|
| 49 | __wrt_touch() { #
|
---|
| 50 | #----------------------------------#
|
---|
[a30c80e] | 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
|
---|
[f4ed135] | 55 |
|
---|
| 56 | (
|
---|
| 57 | cat << EOF
|
---|
[e576789] | 58 | @xsltproc --stringparam packages ${PACK_FILE} \\
|
---|
[a30c80e] | 59 | --stringparam package "${pkg_name}" \\
|
---|
[e576789] | 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 \$@ && \\
|
---|
[3c10176] | 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
|
---|
[f4ed135] | 78 |
|
---|
[3c10176] | 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"
|
---|
[dc67791] | 88 | __write_build_cmd
|
---|
[3c10176] | 89 |
|
---|
| 90 | # Include a touch of the target name so make can check
|
---|
| 91 | # if it's already been made.
|
---|
[e576789] | 92 | __wrt_touch "${script_name}"
|
---|
[3c10176] | 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 |
|
---|
[6d0dbc3] | 111 |
|
---|
[e576789] | 112 | for package_script in ${BUILD_SCRIPTS}/* ; do
|
---|
[3c10176] | 113 | this_script=`basename $package_script`
|
---|
[f4ed135] | 114 | pkg_list="$pkg_list ${this_script}"
|
---|
[e576789] | 115 | __write_entry "${this_script}"
|
---|
[f4ed135] | 116 | PREV_PACKAGE=${this_script}
|
---|
[3c10176] | 117 | done
|
---|
| 118 |
|
---|
| 119 | (
|
---|
| 120 | cat << EOF
|
---|
| 121 | $HEADER
|
---|
| 122 |
|
---|
[e576789] | 123 | TRACKING_FILE= $TRACKING_FILE
|
---|
[3c10176] | 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 |
|
---|
[e576789] | 140 | define end_message
|
---|
[3c10176] | 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
|
---|
[e576789] | 148 | @\$(call end_message )
|
---|
[3c10176] | 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 | }
|
---|
[6d0dbc3] | 158 |
|
---|
[e576789] | 159 | if [[ ! -d ${BUILD_SCRIPTS} ]] ; then
|
---|
[e253015] | 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
|
---|
[aecb378] | 170 | exit 1
|
---|
| 171 | fi
|
---|
| 172 |
|
---|
[e576789] | 173 | rm -rf *
|
---|
[aecb378] | 174 |
|
---|
[6d0dbc3] | 175 | generate_Makefile
|
---|
| 176 |
|
---|
[e576789] | 177 | cp ${TOPDIR}/progress_bar.sh .
|
---|
[6d0dbc3] | 178 |
|
---|
| 179 | mkdir -p logs
|
---|