This repository has been archived on 2024-10-17. You can view files and clone it, but cannot push or open issues or pull requests.
MahiroOS-jhalfs/BLFS/gen-makefile.sh

171 lines
3.9 KiB
Bash
Raw Permalink Normal View History

#!/bin/bash
#
# $Id$
#
set -e
declare TOPDIR='..'
declare ATOPDIR=`cd $TOPDIR; pwd`
declare MKFILE=Makefile
declare PREV_PACKAGE=""
2012-02-22 18:09:47 +01:00
declare BUILD_SCRIPTS=${TOPDIR}/scripts
declare TRACKING_FILE=tracking-dir/instpkg.xml
declare XSLDIR=${TOPDIR}/xsl
declare PACK_FILE=${TOPDIR}/packages.xml
declare BUMP=${XSLDIR}/bump.xsl
HEADER="# This file is automatically generated by gen-makefile.sh
# YOU MAY NEED TO EDIT THIS FILE MANUALLY
#
# Generated on `date \"+%F %X %Z\"`"
#----------------------------------#
__wrt_target() { # Create target and initialize log file
#----------------------------------#
local i=$1
local PREV=$2
(
cat << EOF
$i: $PREV
@\$(call echo_message, Building)
2007-07-26 21:40:24 +02:00
@/bin/bash progress_bar.sh \$@ \$\$PPID &
EOF
) >> $MKFILE.tmp
}
#----------------------------------#
__write_build_cmd() { #
#----------------------------------#
(
cat << EOF
2012-02-22 18:09:47 +01:00
@source ${TOPDIR}/envars.conf && ${BUILD_SCRIPTS}/\$@ >logs/\$@ 2>&1
EOF
) >> $MKFILE.tmp
}
#----------------------------------#
__wrt_touch() { #
#----------------------------------#
local pkg_name=$1
2006-08-24 22:38:22 +02:00
(
cat << EOF
2012-02-22 18:09:47 +01:00
@xsltproc --stringparam packages ${PACK_FILE} \\
--stringparam package ${pkg_name#*-?-} \\
-o track.tmp \\
${BUMP} \$(TRACKING_FILE) && \\
sed -i 's@PACKDESC@${ATOPDIR}/packdesc.dtd@' track.tmp && \\
2012-02-22 18:09:47 +01:00
xmllint --format --postvalid track.tmp > \$(TRACKING_FILE) && \\
rm track.tmp && \\
touch \$@ && \\
sleep .25 && \\
echo -e "\n\n "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
echo --------------------------------------------------------------------------------\$(WHITE)
EOF
) >> $MKFILE.tmp
}
#----------------------------#
__write_entry() { #
#----------------------------#
local script_name=$1
2006-08-24 22:38:22 +02:00
echo -n "${tab_}${tab_} entry for <$script_name>"
#--------------------------------------------------------------------#
# >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
#--------------------------------------------------------------------#
#
# Drop in the name of the target on a new line, and the previous target
# as a dependency. Also call the echo_message function.
__wrt_target "${script_name}" "$PREV_PACKAGE"
__write_build_cmd
# Include a touch of the target name so make can check
# if it's already been made.
2012-02-22 18:09:47 +01:00
__wrt_touch "${script_name}"
#
#--------------------------------------------------------------------#
# >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
#--------------------------------------------------------------------#
echo " .. OK"
}
#----------------------------#
generate_Makefile () { #
#----------------------------#
echo "${tab_}Creating Makefile... ${BOLD}START${OFF}"
# Start with a clean files
>$MKFILE
>$MKFILE.tmp
2012-02-22 18:09:47 +01:00
for package_script in ${BUILD_SCRIPTS}/* ; do
this_script=`basename $package_script`
2006-08-24 22:38:22 +02:00
pkg_list="$pkg_list ${this_script}"
2012-02-22 18:09:47 +01:00
__write_entry "${this_script}"
2006-08-24 22:38:22 +02:00
PREV_PACKAGE=${this_script}
done
(
cat << EOF
$HEADER
2012-02-22 18:09:47 +01:00
TRACKING_FILE= $TRACKING_FILE
BOLD= ""
RED= ""
GREEN= ""
ORANGE= ""
BLUE= ""
WHITE= ""
define echo_message
@echo \$(BOLD)
@echo --------------------------------------------------------------------------------
@echo \$(BOLD)\$(1) target \$(BLUE)\$@\$(BOLD)
@echo \$(WHITE)
endef
2012-02-22 18:09:47 +01:00
define end_message
@echo \$(BOLD)
@echo --------------------------------------------------------------------------------
@echo \$(BOLD) Build complete for the package \$(BLUE)\$(PACKAGE)\$(BOLD) and its dependencies
@echo \$(WHITE)
endef
all : $pkg_list
2012-02-22 18:09:47 +01:00
@\$(call end_message )
EOF
) > $MKFILE
cat $MKFILE.tmp >> $MKFILE
echo "${tab_}Creating Makefile... ${BOLD}DONE${OFF}"
rm $MKFILE.tmp
}
2012-02-22 18:09:47 +01:00
if [[ ! -d ${BUILD_SCRIPTS} ]] ; then
echo -e "\n\tThe \'${BUILD_SCRIPTS}\' directory has not been found.\n"
exit 1
fi
# Let us make a clean base:
rm -rf *
generate_Makefile
cp ${TOPDIR}/progress_bar.sh .
mkdir -p logs