# HG changeset patch
# User Vladimir Marek <Vladimir.Marek at Sun.COM>
# Date 1221994157 -7200
# Node ID 3724edd8d6ca256fb522d76b9b84d419e924b7ec
# Parent  d3890432621ed2623753d876272c8a6a132eadcb
Change to SFW build system
Makefile.targ has now few new rules:
 .downloaded - downloads all the tarballs
 .undownloaded - removes all the tarballs
 sha1sum - usefull for converting the package, creates missing *.sha1sum files

diff --git a/usr/src/Makefile.master b/usr/src/Makefile.master
--- a/usr/src/Makefile.master
+++ b/usr/src/Makefile.master
@@ -129,6 +129,7 @@
 PYTHON_64=     /usr/bin/$(MACH64)/python
 ELFEDIT=       /usr/bin/elfedit
 GINSTALL=      /usr/bin/ginstall
+OBTAIN_SOURCES=        $(SRC)/tools/obtain_sources.ksh
 
 
 
diff --git a/usr/src/cmd/Makefile.targ b/usr/src/cmd/Makefile.targ
--- a/usr/src/cmd/Makefile.targ
+++ b/usr/src/cmd/Makefile.targ
@@ -21,7 +21,7 @@
 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 # 
-#ident "@(#)Makefile.targ      1.5     08/06/24 SMI"
+#ident "@(#)Makefile.targ      1.6     08/09/19 SMI"
 #
 # cmd/Makefile.targ
 # common target definitions for command builds
@@ -44,7 +44,7 @@
        (cd $(VER) ; $(GPATCH) -p0 < ../$<)
        touch $@
 
-$(VER)/.unpacked:      $(TARBALL) $(PATCHES)
+$(VER)/.unpacked:      .downloaded $(PATCHES)
        -$(RM) -r $(VER)
        $(UNPACKARCHIVE) $(TARBALL) $(VER)
        touch $@
@@ -57,8 +57,19 @@
        (cd $(VER64) ; $(GPATCH) -p0 < ../$<)
        touch $@
 
-$(VER64)/.unpacked:    $(TARBALL) $(PATCHES64)
+$(VER64)/.unpacked:    .downloaded $(PATCHES64)
        -$(RM) -r $(VER64)
        mkdir -p tmp; (cd tmp; $(UNPACKARCHIVE) ../$(TARBALL) $(VER))
        mv tmp/$(VER) $(VER64); rmdir tmp
        touch $@
+
+.downloaded: $(TARBALL)
+
+sha1sum: FRC
+       $(OBTAIN_SOURCES) -C $(TARBALL)
+
+.undownloaded: FRC
+       rm -f $(TARBALL)
+
+$(TARBALL): FRC
+       $(OBTAIN_SOURCES) $@
diff --git a/usr/src/tools/obtain_sources.ksh b/usr/src/tools/obtain_sources.ksh
new file mode 100755
--- /dev/null
+++ b/usr/src/tools/obtain_sources.ksh
@@ -0,0 +1,215 @@
+#!/bin/ksh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+# Use is subject to license terms.
+#
+
+# Options. Disabled when empty, enabled when non-empty
+DO_CHECKSUM=yes # you can turn off checksum computing to speed things up
+DO_SYMLINKS=yes # when enabled, create symlinks to file:/// URI files instead 
of copying them
+DO_CREATE_CHECKSUM= # when enabled, create missing .sha1sum files
+I=${0##*/}     # My file name.
+
+# If you want to define your mirror, export environment SFW_MIRROR prior to
+# running this script
+#
+# If you want to disable other mirrors, export SFW_MIRROR_1="" prior to running
+# this script (mirror lookup stops at first empty or undefined value)
+SFW_MIRROR_1=${SFW_MIRROR_1-http://dlc.sun.cot/}
+SFW_MIRROR_2=${SFW_MIRROR_2-file:///net/sfwnv.sfbat/}
+
+WGET=/usr/sfw/bin/wget
+OPENSSL=/usr/sfw/bin/openssl
+WORKSPACE=/opt/teamware/bin/workspace
+HG=/usr/bin/hg
+
+TARBALLPWD=${PWD%/*}
+TARBALLDIR=${TARBALLPWD##*/}
+TARBALLBASE=${PWD##*/} # Thats the same as TARBALLDIR?
+
+print "Downloading tarballs for $TARBALLDIR/$TARBALLBASE"
+
+# Intercept Ctrl+C and other interrupts
+trap 'exit 1' INT TERM QUIT
+
+# Error handling
+alias err='set -u; trap '"'"'ERR=$?; print -u2 "$0: error on line $LINENO 
(\$?=$ERR)"; return $ERR'"'"' ERR'
+err
+
+#-----
+##
+## @function fail
+##
+## @desc critical error handling
+##
+## @param $@ - Text to be written to stdout
+##
+#-----
+function fail {
+       print -u2 "$@"
+       exit 1
+}
+
+#-----
+##
+## @function download_file_from_mirror
+##
+## @desc try to obtain file from given mirror
+##
+## @param $1 - file name
+## @param $2 - mirror uri
+##
+#-----
+function download_file_from_mirror {
+       err
+
+       typeset file=$1
+       typeset uri=$2
+
+       # http/https URI
+       if [[ $uri == http?(s):* ]]; then
+               $WGET --no-verbose -O $file $uri/$file || rm $file || true
+               return
+       fi
+
+       # file URI
+       if [[ $uri == file:* ]] || [[ $uri == /* ]]; then
+           typeset path=${uri#file://}
+           if [[ ! -r $path/$file ]]; then
+                       # Can't find file - maybe we are looking at another 
repository ?
+                       typeset pwd=$(pwd)
+                       typeset repo
+
+                       [ -x "$WORKSPACE" ] && repo=$("$WORKSPACE" name)
+                       [ -z "$repo" ] && repo=$("$HG" root)
+                       [ -z "$repo" ] && return
+                       path="$path/${pwd#$repo}"
+                       [ ! -r "$path/$file" ] && return
+               fi
+
+               rm -f "$file"
+               if [[ -n $DO_SYMLINKS ]]; then
+                       ln -s "$path/$file" "$file"
+               else
+                       cp "$path/$file" "$file"
+               fi
+               return
+       fi
+
+       fail "Unknown URI '$2'"
+}
+
+#-----
+##
+## @function download_file
+##
+## @desc download file of a given name
+##
+## @param $1 - file name
+##
+#-----
+function download_file {
+       err
+
+       # We're done if the file is accessible
+       [[ -r $1 ]] && return
+
+       # If there's symlink pointing nowhere, remove it
+       [[ -L $1 ]] && rm $1
+
+       typeset -i i=-1
+       typeset mirror
+       typeset suffix=""
+       while : ; do
+               (( i+=1 ))
+               [[ $i -gt 0 ]] && suffix=_$i
+               eval "mirror=\"\${SFW_MIRROR$suffix-}\""
+               [[ -z $mirror ]] && {
+                       [[ $i -eq 0 ]] && continue || break
+               }
+               echo $mirror
+               download_file_from_mirror "$1" "$mirror"
+               [[ ! -r $1 ]] && continue
+               check_file "$1" || continue
+               return 0
+       done
+       fail "Can't download file '$1' from any mirror"
+}
+
+#-----
+##
+## @function check_file
+##
+## @desc if enabled check file's checksum
+##
+## @param $1 - file name
+##
+#-----
+function check_file {
+       err
+
+       [[ -z $DO_CHECKSUM ]] && return 0
+       typeset sum="$1.sha1sum"
+       typeset sum_actual=$($OPENSSL dgst -sha1 $1)
+       sum_actual=${sum_actual##* }
+       if [[ ! -r "$sum" ]]; then
+               [[ -z "$DO_CREATE_CHECKSUM" ]] && fail "Can't read '$sum' - 
can't verify file '$file' ($sum_actual)"
+               echo "Creating '$sum'"
+               echo $sum_actual > "$sum"
+       fi
+       typeset sum_ok=$(< $sum)
+       [[ $sum_actual == $sum_ok ]] && return 0
+       echo "Actual sum is '$sum_actual', required sum is '$sum_ok'"
+       return 1
+}
+
+function usage {
+    print -u2 "No arguments given!
+    Usage $I [-Xcs] list_of_files_to_download
+       -X Debug (verbose)
+       -c Disable checksum
+       -C Create missing checksums
+       -s Do not create symlinks, copy the files
+"
+exit 1
+}
+
+[[ $# -le 0 ]] && usage
+
+while getopts :XcCs opt
+do
+  case $opt in
+      (X)      typeset -ft $(typeset +f); set -x;; # DEBUG
+      (c)      DO_CHECKSUM="";;
+      (C)      DO_CREATE_CHECKSUM=yes;;
+      (s)      DO_SYMLINKS="";;
+      (?)      usage;; # No returns
+  esac
+done
+shift `expr $OPTIND - 1`       # Skip over option arguments
+
+
+for file in "$@"; do
+       download_file "$file"
+       check_file "$file"
+       print "$file available" 
+done

Reply via email to