Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / usr / src / tools / ndrgen / ndrgen.sh
blob19dbb9f8e55023a74b1396b2e87a5a31216e9568
1 #!/bin/ksh -p
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
20 # CDDL HEADER END
24 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
27 # Copyright 2013 Nexenta Systems, Inc. All rights reserved.
30 # This is a wrapper script around the ndrgen compiler (ndrgen1).
32 NDRPROG="${0}1"
34 # Note: most *.ndl files require an ANSI-compatible cpp,
35 # so we can NOT use /usr/lib/cpp or /usr/ccs/lib/cpp
36 # Wish there was an easier way to get an ANSI cpp.
37 CPP="${CC} -E"
38 CPPFLAGS="-DNDRGEN"
39 V_FLAG=
41 PROGNAME=`basename $0`
43 ndrgen_usage()
45 if [[ $1 != "" ]] ; then
46 print "$PROGNAME: ERROR: $1"
49 echo "usage: $PROGNAME [options] file.ndl [file.ndl]..."
50 echo " options: -Y cc-path -Ddefine -Iinclude"
51 exit 1
54 # Process the input ndl file ($1) generating C code on stdout.
55 process()
58 # Put the standard top matter
60 # Want the include directive to have just
61 # include "file.ndl" (no path) so...
62 inc_ndl=`basename $1`
63 cat - << EOF
65 * Please do not edit this file.
66 * It was generated using ndrgen.
69 #include <strings.h>
70 #include <libmlrpc/ndr.h>
71 #include "$inc_ndl"
72 EOF
74 # Put optional custom top matter
75 nawk 'BEGIN { copy=0; }
76 /^\/\* NDRGEN_HEADER_BEGIN \*\// { copy=1; next; }
77 /^\/\* NDRGEN_HEADER_END \*\// { copy=0; next; }
78 /./ { if (copy==1) print; }' $1
80 # now the real ndrgen output
81 [ -n "$V_FLAG" ] &&
82 echo "$CPP $CPPFLAGS $1 | $NDRPROG" >&2
83 $CPP $CPPFLAGS $1 | $NDRPROG
87 while getopts "D:I:Y:V" FLAG
89 case $FLAG in
90 D|I) CPPFLAGS="$CPPFLAGS -${FLAG}${OPTARG}";;
91 Y) CPP="$OPTARG";;
92 V) V_FLAG="V";;
93 *) ndrgen_usage;;
94 esac
95 done
96 shift $(($OPTIND - 1))
98 if [[ $# -lt 1 ]] ; then
99 ndrgen_usage
102 if [ ! -x $CPP ] ; then
103 ndrgen_usage "cannot run $CPP"
106 for i
108 if [[ ! -r $i ]] ; then
109 print "$PROGNAME: ERROR: cannot read $i"
110 exit 1
113 base=`basename $i .ndl`
114 process $i > ${base}_ndr.c || {
115 echo "ndrgen error";
116 rm ${base}_ndr.c;
118 done