1#!/bin/sh 2# usage: 3# .../install-wrap $(PYTHON_PATH) install <options-to-install> <src>... <dest> 4# where 5# PYTHON_PATH is what to put after #! and may be `/usr/bin/env python' 6# 7# Used via $(INSTALL_PYTHON_PROG) in Rules.mk; PYTHON_PATH comes from $(PYTHON) 8 9set -e 10if test $# -lt 2; then 11 echo >&2 "${0##*/}: too few arguments" 12 exit 1 13fi 14 15pythonpath="$1" 16shift 17 18install="$1" 19shift 20srcs="" 21 22while [ $# != 0 ]; do 23 case "$1" in 24 -|--) install=`echo "${install} $1"` 25 shift 26 break 27 ;; 28 -*) install=`echo "${install} $1"` 29 shift 30 ;; 31 *) break 32 ;; 33 esac 34done 35 36while test $# -gt 1; do 37 srcs=`echo "${srcs} $1"` 38 shift 39done 40 41dest="$1" 42shift 43 44destf="$dest" 45for srcf in ${srcs}; do 46 if test -d "$dest"; then 47 destf="$dest/${srcf%%*/}" 48 fi 49 org="$(sed -n '2q; /^#! *\/usr\/bin\/env python *$/p' $srcf)" 50 if test "x$org" = x; then 51 eval "${install} $srcf $destf" 52 continue 53 fi 54 tmpf="$destf.tmp" 55 eval "${install} $srcf $tmpf" 56 printf >"$tmpf" "#!%s\n" "$pythonpath" 57 sed -e 1d "$srcf" >>"$tmpf" 58 mv -f "$tmpf" "$destf" 59done 60exit 0 61