dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / tools / ndrgen / ndrgen.sh
blob7367870b53dff6474c12ab4e437788dc99818e7c
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
23 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
27 # This is a wrapper script around the ndrgen compiler (ndrgen1).
28 # CC must be defined in the environment or on the command line.
30 NDRPROG="${0%/*}/ndrgen1"
31 INCDIR=${ROOT}/usr/include/smbsrv
33 PROGNAME=`basename $0`
35 ndrgen_usage()
37 if [[ $1 != "" ]] ; then
38 print "$PROGNAME: ERROR: $1"
41 echo "usage: $PROGNAME [-Y cpp-path] file [file]..."
42 exit 1
45 # Copy header text from the input ndl file to the generated ndr C file.
46 ndrgen_copy_header()
48 ndl_file=$1
49 ndr_file=$2
51 nawk 'BEGIN { copy=0; }
52 /^\/\* NDRGEN_HEADER_BEGIN \*\// { copy=1; next; }
53 /^\/\* NDRGEN_HEADER_END \*\// { copy=0; next; }
54 /./ { if (copy==1) print; }' < $ndl_file > $ndr_file
57 if [[ $# -lt 1 ]] ; then
58 ndrgen_usage
61 while getopts "Y" FLAG $*; do
62 case $FLAG in
64 CC_FLAG="y"
67 ndrgen_usage
69 esac
70 done
72 if [[ $CC_FLAG = "y" ]] ; then
73 shift $(($OPTIND - 1))
75 if [[ $# -lt 1 ]] ; then
76 ndrgen_usage "C pre-processor path is missing"
77 else
78 CC=$1
79 shift $(($OPTIND - 1))
83 if [[ $CC = "" ]] ; then
84 ndrgen_usage "C pre-processor is not defined"
87 if [ ! -f $CC ] || [ ! -x $CC ] ; then
88 ndrgen_usage "cannot run $CC"
91 for i
93 if [[ ! -r $i ]] ; then
94 print "$PROGNAME: ERROR: cannot read $i"
95 exit 1
98 BASENAME=`basename $i .ndl`
99 TMP_NAME=$BASENAME.ndl.c
101 cp $i $TMP_NAME
103 if $CC -E -D__sun -D__a64 -D__EXTENSIONS__ -D_FILE_OFFSET_BITS=64 \
104 -I. -I${INCDIR} -I${INCDIR}/ndl -DNDRGEN $TMP_NAME | \
105 $NDRPROG > $BASENAME.raw
106 then
107 touch ${BASENAME}_ndr.c
108 ndrgen_copy_header $i ${BASENAME}_ndr.c
110 cat - << EOF >> ${BASENAME}_ndr.c
112 * Please do not edit this file.
113 * It was generated using ndrgen.
116 #include <strings.h>
117 #include <smbsrv/ndr.h>
118 #include <smbsrv/ndl/$BASENAME.ndl>
121 cat $BASENAME.raw >> ${BASENAME}_ndr.c
123 rm -f $BASENAME.raw
124 rm -f $TMP_NAME
125 else
126 rm -f $BASENAME.raw
127 rm -f $TMP_NAME
128 exit 1
130 done