Home | History | Annotate | Line # | Download | only in sets
syspkgdeps revision 1.1
      1 #!/bin/sh
      2 #
      3 # syspkgdeps [-a arch] [-m machine] [-s setsdir] [-p prefix] sets
      4 #
      5 # Compute naive package dependencies based on file & directory
      6 # nesting. E.g., if pkg P contains /foo/bar and Q contains /foo,
      7 # then Q is considered a dependency of P.
      8 #
      9 
     10 #set -u
     11 
     12 DB="db -q"
     13 
     14 #
     15 # set defaults and import setlist subroutines
     16 #
     17 . ./sets.subr
     18 setd=$(pwd)
     19 prefix=/
     20 
     21 usage() {
     22 exec 1>&2
     23 
     24 echo "Usage: $0 [-a arch] [-m machine] [-s setsdir] [-p prefix] sets"
     25 echo "	-a arch		set arch (e.g, m68k, mips, powerpc)	[$machine_arch]"
     26 echo "	-m machine	set machine (e.g, amiga, i386, macppc)	[$machine]"
     27 echo "	-s setsdir	directory to find sets			[$setd]"
     28 echo "	-p prefix	prefix for created plist		[$prefix]"
     29 echo "	sets		sets to find dependencies for"
     30 
     31 exit 1
     32 }
     33 
     34 # parse arguments
     35 while : ; do
     36 	case $1 in
     37 	-a*)
     38 		machine_arch=`MACHINE_ARCH=${2} ${make} print_machine_arch`
     39 		machine_cpu=`MACHINE_ARCH=${2} ${make} print_machine_cpu`
     40 		shift
     41 		;;
     42 	-m*)
     43 		machine=$2; shift
     44 		;;
     45 	-s*)
     46 		setd=$2; shift
     47 		;;
     48 	-p*)
     49 		prefix=$2; shift
     50 		;;
     51 	-*)
     52 		usage
     53 		;;
     54 	*)
     55 		break
     56 		;;
     57 	esac
     58 	shift
     59 done
     60 if [ $# -lt 1 ]; then
     61 	usage
     62 fi
     63 
     64 sets=$@
     65 
     66 if [ "$object_fmt" = "ELF" ]; then
     67 	shlib=elf
     68 else
     69 	shlib=aout
     70 fi
     71 stlib=$shlib
     72 
     73 # Turn off shlibs for some ports.
     74 if [ "$machine_cpu" = "sh3" -o "$machine_arch" = "m68000" ]; then
     75 	shlib=no
     76 fi
     77 
     78 lkm=yes
     79 # Turn off LKMs for some ports.
     80 if [ "$machine" = "evbppc" ]; then
     81 	lkm=no
     82 fi
     83 
     84 # Turn off lintlibs for some ports.
     85 # Not needed anymore, leave the hook here for future use.
     86 lintlibs=
     87 
     88 # TBD clean up
     89 SCRATCH=$(mktemp -d /var/tmp/$(basename $0).XXXXXX)
     90 
     91 [ $? -ne 0 ] && { echo "Could not create scratch directory." 1>&2 ; exit 1 ; }
     92 
     93 PATH_MEMBERSHIP=$SCRATCH/path-membership
     94 PATH_TO_PKGNAME=$SCRATCH/pathpkg.db
     95 PARENT_PKGNAMES=$SCRATCH/parent-pkgnames
     96 PARENT_PATHNAMES=$SCRATCH/parent-pathnames
     97 
     98 echo "indexing packages by pathnames" 1>&2
     99 
    100 list_set_files $sets | sed 's/^\.\///' | \
    101 env PREFIX=$prefix awk '{
    102 	if ($1 == ".") {
    103 		print ENVIRON["PREFIX"] " " $2;
    104 	} else {
    105 		print ENVIRON["PREFIX"] $1 " " $2;
    106 	}
    107 }' | sort -k 1 -u > $PATH_MEMBERSHIP
    108 
    109 $DB -w -f - btree $PATH_TO_PKGNAME < $PATH_MEMBERSHIP || echo "shit" 1>&2
    110 
    111 echo "computing parent pathnames" 1>&2
    112 
    113 while read pathname pkgname; do
    114 	# print parent pathname
    115 	dirname $pathname
    116 done < $PATH_MEMBERSHIP > $PARENT_PATHNAMES
    117 
    118 echo "selecting parent packages using parent pathnames" 1>&2
    119 
    120 $DB -f - btree $PATH_TO_PKGNAME < $PARENT_PATHNAMES | \
    121 	paste $PATH_MEMBERSHIP - | \
    122 	awk '{ if ($2 != $4) print $2 " " $4; }' | sort -u | ./culldeps
    123 
    124 if [ $? -ne 0 ]; then
    125 	echo "error in parent-directory lookup, aborting" 1>&2
    126 	exit 1
    127 fi
    128