[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 | #----------------------------------#
|
---|
| 53 | local pkg_name=$1
|
---|
[f4ed135] | 54 |
|
---|
| 55 | (
|
---|
| 56 | cat << 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)
|
---|
| 68 | EOF
|
---|
| 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 | #----------------------------#
|
---|
| 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 |
|
---|
[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] | 122 | TRACKING_FILE= $TRACKING_FILE
|
---|
[3c10176] | 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 |
|
---|
[e576789] | 139 | define 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)
|
---|
| 144 | endef
|
---|
| 145 |
|
---|
| 146 | all : $pkg_list
|
---|
[e576789] | 147 | @\$(call end_message )
|
---|
[3c10176] | 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 | }
|
---|
[6d0dbc3] | 157 |
|
---|
[e576789] | 158 | if [[ ! -d ${BUILD_SCRIPTS} ]] ; then
|
---|
[e253015] | 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
|
---|
[aecb378] | 169 | exit 1
|
---|
| 170 | fi
|
---|
| 171 |
|
---|
[e576789] | 172 | rm -rf *
|
---|
[aecb378] | 173 |
|
---|
[6d0dbc3] | 174 | generate_Makefile
|
---|
| 175 |
|
---|
[e576789] | 176 | cp ${TOPDIR}/progress_bar.sh .
|
---|
[6d0dbc3] | 177 |
|
---|
| 178 | mkdir -p logs
|
---|