1 #!/bin/sh 2 3 DIRNAME=`dirname "$0"` 4 PROGNAME=`basename "$0"` 5 6 TEMPLATES="$DIRNAME/templates" 7 8 # Test for arguments. 9 10 if [ ! "$1" ] || [ "$1" = '--help' ] ; then 11 cat 1>&2 <<EOF 12 Usage: $PROGNAME [ -C ] <interface filename> \\ 13 [ -N <interface name> ] [ <interface filename> ... ] 14 15 This program reads a template from... 16 17 $TEMPLATES 18 19 ...and produces a Makefile for inclusion in other Makefiles alongside suitable 20 definitions and rules. 21 22 Specifying the -C option produces a compound/composite/component interface 23 employing other interfaces. Providing the -N option with a name overrides the 24 name of the generated interface. The individual interface names or filenames 25 must then be given. 26 EOF 27 exit 1 28 fi 29 30 # Determine what kind of interface is involved. 31 32 if [ "$1" = '-C' ] ; then 33 COMP=$1 34 shift 1 35 else 36 COMP= 37 fi 38 39 # Get the interface name, filename or filename prefix. 40 41 NAME=$1 42 shift 1 43 44 # Obtain the prefix or root of the interface filename. 45 46 INTERFACE_PREFIX=`basename "$NAME" .idl` 47 48 # Test for an interface name. 49 50 INTERFACE_NAME=$INTERFACE_PREFIX 51 52 if [ "$COMP" ] ; then 53 if [ "$1" = '-N' ] ; then 54 shift 1 55 INTERFACE_NAME=$1 56 shift 1 57 fi 58 59 INTERFACE_FILES= 60 61 for NAME in $* ; do 62 INTERFACE_FILES="$INTERFACE_FILES `basename \"$NAME\" .idl`" 63 done 64 fi 65 66 # Obtain a suitable identifier as a variable name prefix. 67 68 VARNAME=`echo "$INTERFACE_PREFIX" | tr [:blank:] _` 69 70 # Substitution rules. 71 72 SUB_VARNAME='s/{VARNAME}/'"$VARNAME"'/g' 73 SUB_PREFIX='s/{INTERFACE_PREFIX}/'"$INTERFACE_PREFIX"'/g' 74 SUB_FILES='s/{INTERFACE_FILES}/'"$INTERFACE_FILES"'/g' 75 SUB_NAME='s/{INTERFACE_NAME}/'"$INTERFACE_NAME"'/g' 76 77 # Substitute the above values for the placeholders in the Makefile template. 78 79 if [ "$COMP" ] ; then 80 sed "$SUB_VARNAME;$SUB_PREFIX;$SUB_FILES;$SUB_NAME" "$TEMPLATES/comp_interface.inc" 81 else 82 sed "$SUB_VARNAME;$SUB_PREFIX" "$TEMPLATES/interface.inc" 83 fi