[6d0dbc3] | 1 | #!/bin/bash
|
---|
[3c10176] | 2 | #
|
---|
| 3 | # $Id$
|
---|
[6d0dbc3] | 4 | #
|
---|
| 5 | set -e
|
---|
| 6 |
|
---|
[e576789] | 7 | declare TOPDIR='..'
|
---|
| 8 | declare ATOPDIR=`cd $TOPDIR; pwd`
|
---|
[6d0dbc3] | 9 | declare MKFILE=Makefile
|
---|
[3c10176] | 10 | declare PREV_PACKAGE=""
|
---|
[e576789] | 11 | declare BUILD_SCRIPTS=${TOPDIR}/scripts
|
---|
[8ebac92] | 12 | declare TRACKING_FILE=tracking-dir/instpkg.xml
|
---|
[e576789] | 13 | declare XSLDIR=${TOPDIR}/xsl
|
---|
| 14 | declare PACK_FILE=${TOPDIR}/packages.xml
|
---|
| 15 | declare BUMP=${XSLDIR}/bump.xsl
|
---|
[3c10176] | 16 |
|
---|
[aecb378] | 17 | HEADER="# 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 | (
|
---|
| 29 | cat << EOF
|
---|
| 30 |
|
---|
| 31 | $i: $PREV
|
---|
| 32 | @\$(call echo_message, Building)
|
---|
[fc8b962] | 33 | @/bin/bash progress_bar.sh \$@ \$\$PPID &
|
---|
[3c10176] | 34 | EOF
|
---|
| 35 | ) >> $MKFILE.tmp
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 |
|
---|
| 39 |
|
---|
| 40 | #----------------------------------#
|
---|
| 41 | __write_build_cmd() { #
|
---|
| 42 | #----------------------------------#
|
---|
| 43 | (
|
---|
| 44 | cat << EOF
|
---|
[e576789] | 45 | @source ${TOPDIR}/envars.conf && ${BUILD_SCRIPTS}/\$@ >logs/\$@ 2>&1
|
---|
[3c10176] | 46 | EOF
|
---|
| 47 | ) >> $MKFILE.tmp
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | #----------------------------------#
|
---|
| 51 | __wrt_touch() { #
|
---|
| 52 | #----------------------------------#
|
---|
[a30c80e] | 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
|
---|
[f4ed135] | 57 |
|
---|
| 58 | (
|
---|
| 59 | cat << EOF
|
---|
[e576789] | 60 | @xsltproc --stringparam packages ${PACK_FILE} \\
|
---|
[a30c80e] | 61 | --stringparam package "${pkg_name}" \\
|
---|
[e576789] | 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 \$@ && \\
|
---|
[3c10176] | 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
|
---|
[f4ed135] | 80 |
|
---|
[3c10176] | 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"
|
---|
[dc67791] | 90 | __write_build_cmd
|
---|
[3c10176] | 91 |
|
---|
| 92 | # Include a touch of the target name so make can check
|
---|
| 93 | # if it's already been made.
|
---|
[e576789] | 94 | __wrt_touch "${script_name}"
|
---|
[3c10176] | 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 |
|
---|
[6d0dbc3] | 113 |
|
---|
[e576789] | 114 | for package_script in ${BUILD_SCRIPTS}/* ; do
|
---|
[3c10176] | 115 | this_script=`basename $package_script`
|
---|
[f4ed135] | 116 | pkg_list="$pkg_list ${this_script}"
|
---|
[e576789] | 117 | __write_entry "${this_script}"
|
---|
[f4ed135] | 118 | PREV_PACKAGE=${this_script}
|
---|
[3c10176] | 119 | done
|
---|
| 120 |
|
---|
| 121 | (
|
---|
| 122 | cat << EOF
|
---|
| 123 | $HEADER
|
---|
| 124 |
|
---|
[e576789] | 125 | TRACKING_FILE= $TRACKING_FILE
|
---|
[3c10176] | 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 |
|
---|
[e576789] | 142 | define end_message
|
---|
[3c10176] | 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
|
---|
[e576789] | 150 | @\$(call end_message )
|
---|
[3c10176] | 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 | }
|
---|
[6d0dbc3] | 160 |
|
---|
[e576789] | 161 | if [[ ! -d ${BUILD_SCRIPTS} ]] ; then
|
---|
[e253015] | 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
|
---|
[aecb378] | 172 | exit 1
|
---|
| 173 | fi
|
---|
| 174 |
|
---|
[e576789] | 175 | rm -rf *
|
---|
[aecb378] | 176 |
|
---|
[6d0dbc3] | 177 | generate_Makefile
|
---|
| 178 |
|
---|
[e576789] | 179 | cp ${TOPDIR}/progress_bar.sh .
|
---|
[6d0dbc3] | 180 |
|
---|
| 181 | mkdir -p logs
|
---|