Artifact Content

Artifact 773c04dec94e413f9586ce2c8af627462e795d39:


     1  #! /bin/bash
     2  
     3  VERS=1.16
     4  VERS_TAG="$(echo "${VERS}" | sed 's@\.@-@g')"
     5  VERS_US="$(echo "${VERS}" | sed 's@\.@_@g')"
     6  SRC="src/tcllib-${VERS}.tar.gz"
     7  SRCURL="http://sourceforge.net/projects/tcllib/files/tcllib/${VERS}/tcllib-${VERS}.tar.gz/download"
     8  SRCURL="http://core.tcl.tk/tcllib/tarball/tcllib-${VERS}.tar.gz?uuid=tcllib-${VERS_TAG}"
     9  SRCURL="https://github.com/tcltk/tcllib/archive/tcllib_${VERS_US}.tar.gz"
    10  BUILDDIR="tcllib-tcllib_${VERS_US}"
    11  export VERS SRC SRCURL BUILDDIR
    12  
    13  # Load common functions
    14  source ../common.sh
    15  
    16  # Do not build if the "tcl" platform has NOT been requested
    17  only_platforms 'tcl'
    18  
    19  # Download source
    20  download_src
    21  
    22  rm -rf "${WORKDIR}" >/dev/null 2>/dev/null
    23  mkdir -p "${WORKDIR}" || exit 1
    24  
    25  retval=0
    26  (
    27  	rm -rf build
    28  	mkdir -p "${PLATDIR}" >/dev/null 2>/dev/null
    29  	mkdir build
    30  
    31  	cd build/ || exit 1
    32  
    33  	gzip -dc "../${SRC}" | tar -xf -
    34  	cd "${BUILDDIR}" || exit 1
    35  
    36  	find modules -type f -name '*.test' -o -name 'ChangeLog' -o -name '*.man' -o -name '*.txt' | xargs rm -f
    37  
    38  	workfile="${WORKDIR}/file"
    39  	worksubfile="${WORKDIR}/subfile"
    40  	pkgfiles=""
    41  	for file in modules/*/*.tcl; do
    42  		cat "${file}" | tr ';[]{}' "\n\n\n\n\n" | sed 's@^[	 ]*#.*$@@' "${file}" > "${workfile}"
    43  
    44  		if grep '^ *package  *provide  *' "${workfile}" >/dev/null; then
    45  			pkgfiles="${pkgfiles}
    46  ${file}"
    47  		fi
    48  	done
    49  
    50  	for file in modules/*/*.tcl; do
    51  		filetail="$(basename "${file}")"
    52  		if [ "${filetail}" = "pkgIndex.tcl" ]; then
    53  			continue
    54  		fi
    55  
    56  		pkgdir="$(dirname "${file}")"
    57  
    58  		cat "${file}" | tr ';[]{}	' "\n\n\n\n\n " | sed 's@^ *#.*$@@' > "${workfile}"
    59  
    60  		# Some packages try to require a package, if that doesn't work they implement it and say they provide it (lies)
    61  		# We remove any "package provide blah" in a file also containing "package require blah"
    62  		# TODO: We should add "blah" to the recommended packages if we ended up removing anything
    63  		grep '^ *package  *require  *' "${workfile}" | while read blah blah reqpkg remain; do
    64  			grep -v "^ *package  *provide  *${reqpkg}  *" "${workfile}" > "${workfile}.new"
    65  			mv "${workfile}.new" "${workfile}"
    66  		done
    67  
    68  		if ! grep '^ *package  *provide  *[^ ][^ ]*  *[^ ][^ ]*' "${workfile}" >/dev/null; then
    69  			continue
    70  		fi
    71  
    72  		# Determine package name and version
    73  		pkg="$(grep '^ *package  *provide  *[^ ][^ ]*  *[^ ][^ ]*' "${workfile}" | head -1 | sed 's@^ *package  *provide  *\([^ ][^ ]*\) .*$@\1@' | sed 's@^  *@@;s@  *$@@')"
    74  		pkgver="$(grep '^ *package  *provide  *[^ ][^ ]*  *[^ ][^ ]*' "${workfile}" | head -1 | sed 's@^ *package  *provide  *[^ ][^ ]*  *\([^ ][^ ]*\)*$@\1@;s@^[^0-9\.].*@@g')"
    75  
    76  		if echo "${pkg}" | grep '^ *\[' >/dev/null || [ -z "${pkg}" ]; then
    77  			pkg="$(grep "package  *ifneeded  *" "${pkgdir}/pkgIndex.tcl" | sed 's@^.*package  *ifneeded  *\([^ ][^ ]*\) .*$@\1@' | sed 's@^  *@@;s@  *$@@')"
    78  			if [ "$(echo "${pkg}" | wc -l | awk '{ print $1 }')" != "1" ]; then
    79  				pkg="$(basename "${file}" .tcl)"
    80  
    81  				echo "Unable to determine name of package: $file, assuming it is $pkg"
    82  			fi
    83  		fi
    84  		if [ -z "${pkgver}" ]; then
    85  			pkgver="$(grep "package  *ifneeded  *.*source  *.* ${filetail}" "${pkgdir}/pkgIndex.tcl" 2>/dev/null | sed 's@^.*package  *ifneeded  *[^ ][^ ]*  *\([^ ][^ ]*\) .*$@\1@' | head -1)"
    86  		fi
    87  		if [ -z "${pkgver}" ]; then
    88  			pkgver="$(grep "package  *ifneeded  *${pkg}  *" "${pkgdir}/pkgIndex.tcl" 2>/dev/null | sed 's@^.*package  *ifneeded  *[^ ][^ ]*  *\([^ ][^ ]*\) .*$@\1@' | head -1)"
    89  		fi
    90  		if [ -z "${pkgver}" ]; then
    91  			echo "Unable to determine version of ${pkg}: $(grep '^ *package  *provide  *' "${workfile}" | head -1), skipping."
    92  
    93  			continue
    94  		fi
    95  
    96  		# Skip marker package names
    97  		if [ "${pkg}" = "@@" ]; then
    98  			continue
    99  		fi
   100  
   101  		# Create output directory
   102  		outdir="${PLATDIR}/${pkg}-${pkgver}"
   103  		if [ -d "${outdir}" ]; then
   104  			echo "ERROR: $outdir already exists, skipping ${file} which provides ${pkg} v${pkgver}"
   105  
   106  			continue
   107  		fi
   108  		mkdir -p "${outdir}" || continue
   109  
   110  		# Put relevant files into the directory
   111  		if grep '^ *source  *' "${workfile}" >/dev/null; then
   112  			# Include all the files in the directory that do not contain packages
   113  			cp "${file}" "${outdir}"
   114  			for subfile in "${pkgdir}"/*; do
   115  				if ! echo "${pkgfiles}" | grep "^${subfile}$" >/dev/null; then
   116  					cp "${subfile}" "${outdir}" >/dev/null 2>/dev/null
   117  				fi
   118  			done
119 grep -v "package *ifneeded *" "${pkgdir}/pkgIndex.tcl" > "${outdir}/pkgIndex.tcl" 120 grep "package *ifneeded *${pkg} *" "${pkgdir}/pkgIndex.tcl" >> "${outdir}/pkgIndex.tcl"
121 122 # Create Teapot info 123 pkgdesc="Part of the Tclib $(basename $(dirname ${file})) module" 124 pkgteapotfile="${outdir}/teapot.txt" 125 else 126 # Make a tclModule 127 cp "${file}" "${outdir}/" 128 outfile="${outdir}/${filetail}" 129 130 # Create Teapot info 131 pkgdesc="Part of the Tclib $(basename $(dirname ${file})) module" 132 pkgteapotfile="${outfile}" 133 fi 134 135 pkgdeps=$( ( for subfile in "${outdir}"/*.tcl; do 136 cat "${subfile}" | grep -v 'catch ' | tr ';[]{} ' "\n\n\n\n\n " | sed 's@^ *#.*$@@' > "${worksubfile}" 137 grep '^ *package *require *' "${worksubfile}" | while read blah blah reqpkg reqpkgver extra; do 138 reqpkgver="$(echo "${reqpkgver}" | sed 's@ *\$.*$@@')" 139 if [ -n "${reqpkgver}" ]; then 140 reqpkgver=$(echo "${reqpkgver}" | sed 's@[+=-]*$@@g') 141 echo "${reqpkg} ${reqpkgver}" 142 else 143 echo "${reqpkg}" 144 fi 145 done | sort -u | grep -v '__undefined__' | grep -v '__does_not_exist__' 146 done | tr "\n" ','; echo ) | sed 's@,,*$@@') 147 148 ../../../create_teapot "${pkgteapotfile}" "$pkg" "$pkgver" "http://tcllib.sourceforge.net/" "tcl" "${pkgdeps}" "${pkgdesc}" 149 done 150 ) || retval=1 151 152 rm -rf "${WORKDIR}" 153 154 exit $retval