ndrgen.sh revision a0b6e447978c306e15941d158bf6939a42ed2726
d0e518695adc90b82233b99af7dffbb3d3f92c00amw#!/bin/ksh -p
d0e518695adc90b82233b99af7dffbb3d3f92c00amw#
d0e518695adc90b82233b99af7dffbb3d3f92c00amw# CDDL HEADER START
d0e518695adc90b82233b99af7dffbb3d3f92c00amw#
d0e518695adc90b82233b99af7dffbb3d3f92c00amw# The contents of this file are subject to the terms of the
d0e518695adc90b82233b99af7dffbb3d3f92c00amw# Common Development and Distribution License (the "License").
d0e518695adc90b82233b99af7dffbb3d3f92c00amw# You may not use this file except in compliance with the License.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw#
d0e518695adc90b82233b99af7dffbb3d3f92c00amw# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
d0e518695adc90b82233b99af7dffbb3d3f92c00amw# or http://www.opensolaris.org/os/licensing.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw# See the License for the specific language governing permissions
d0e518695adc90b82233b99af7dffbb3d3f92c00amw# and limitations under the License.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw#
d0e518695adc90b82233b99af7dffbb3d3f92c00amw# When distributing Covered Code, include this CDDL HEADER in each
d0e518695adc90b82233b99af7dffbb3d3f92c00amw# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw# If applicable, add the following below this CDDL HEADER, with the
d0e518695adc90b82233b99af7dffbb3d3f92c00amw# fields enclosed by brackets "[]" replaced with your own identifying
d0e518695adc90b82233b99af7dffbb3d3f92c00amw# information: Portions Copyright [yyyy] [name of copyright owner]
d0e518695adc90b82233b99af7dffbb3d3f92c00amw#
d0e518695adc90b82233b99af7dffbb3d3f92c00amw# CDDL HEADER END
d0e518695adc90b82233b99af7dffbb3d3f92c00amw#
d0e518695adc90b82233b99af7dffbb3d3f92c00amw#
a0b6e447978c306e15941d158bf6939a42ed2726Alan Wright# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw# Use is subject to license terms.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw#
d0e518695adc90b82233b99af7dffbb3d3f92c00amw
d0e518695adc90b82233b99af7dffbb3d3f92c00amw# This is a wrapper script around the ndrgen compiler (ndrgen1).
d0e518695adc90b82233b99af7dffbb3d3f92c00amw# CC must be defined in the environment or on the command line.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw
d0e518695adc90b82233b99af7dffbb3d3f92c00amwNDRPROG="${0%/*}/ndrgen1"
d0e518695adc90b82233b99af7dffbb3d3f92c00amwINCDIR=${ROOT}/usr/include/smbsrv
d0e518695adc90b82233b99af7dffbb3d3f92c00amw
d0e518695adc90b82233b99af7dffbb3d3f92c00amwPROGNAME=`basename $0`
d0e518695adc90b82233b99af7dffbb3d3f92c00amw
d0e518695adc90b82233b99af7dffbb3d3f92c00amwndrgen_usage()
d0e518695adc90b82233b99af7dffbb3d3f92c00amw{
d0e518695adc90b82233b99af7dffbb3d3f92c00amw if [[ $1 != "" ]] ; then
d0e518695adc90b82233b99af7dffbb3d3f92c00amw print "$PROGNAME: ERROR: $1"
d0e518695adc90b82233b99af7dffbb3d3f92c00amw fi
d0e518695adc90b82233b99af7dffbb3d3f92c00amw
d0e518695adc90b82233b99af7dffbb3d3f92c00amw echo "usage: $PROGNAME [-Y cpp-path] file [file]..."
d0e518695adc90b82233b99af7dffbb3d3f92c00amw exit 1
d0e518695adc90b82233b99af7dffbb3d3f92c00amw}
d0e518695adc90b82233b99af7dffbb3d3f92c00amw
9c21fe179ede0eb7881c4d5244e0ab090fdd3c9camw# Copy header text from the input ndl file to the generated ndr C file.
9c21fe179ede0eb7881c4d5244e0ab090fdd3c9camwndrgen_copy_header()
9c21fe179ede0eb7881c4d5244e0ab090fdd3c9camw{
9c21fe179ede0eb7881c4d5244e0ab090fdd3c9camw ndl_file=$1
9c21fe179ede0eb7881c4d5244e0ab090fdd3c9camw ndr_file=$2
9c21fe179ede0eb7881c4d5244e0ab090fdd3c9camw
9c21fe179ede0eb7881c4d5244e0ab090fdd3c9camw nawk 'BEGIN { copy=0; }
9c21fe179ede0eb7881c4d5244e0ab090fdd3c9camw /^\/\* NDRGEN_HEADER_BEGIN \*\// { copy=1; next; }
9c21fe179ede0eb7881c4d5244e0ab090fdd3c9camw /^\/\* NDRGEN_HEADER_END \*\// { copy=0; next; }
9c21fe179ede0eb7881c4d5244e0ab090fdd3c9camw /./ { if (copy==1) print; }' < $ndl_file > $ndr_file
9c21fe179ede0eb7881c4d5244e0ab090fdd3c9camw}
9c21fe179ede0eb7881c4d5244e0ab090fdd3c9camw
d0e518695adc90b82233b99af7dffbb3d3f92c00amwif [[ $# -lt 1 ]] ; then
d0e518695adc90b82233b99af7dffbb3d3f92c00amw ndrgen_usage
d0e518695adc90b82233b99af7dffbb3d3f92c00amwfi
d0e518695adc90b82233b99af7dffbb3d3f92c00amw
d0e518695adc90b82233b99af7dffbb3d3f92c00amwwhile getopts "Y" FLAG $*; do
d0e518695adc90b82233b99af7dffbb3d3f92c00amw case $FLAG in
d0e518695adc90b82233b99af7dffbb3d3f92c00amw Y)
d0e518695adc90b82233b99af7dffbb3d3f92c00amw CC_FLAG="y"
d0e518695adc90b82233b99af7dffbb3d3f92c00amw ;;
d0e518695adc90b82233b99af7dffbb3d3f92c00amw *)
d0e518695adc90b82233b99af7dffbb3d3f92c00amw ndrgen_usage
d0e518695adc90b82233b99af7dffbb3d3f92c00amw ;;
d0e518695adc90b82233b99af7dffbb3d3f92c00amw esac
d0e518695adc90b82233b99af7dffbb3d3f92c00amwdone
d0e518695adc90b82233b99af7dffbb3d3f92c00amw
d0e518695adc90b82233b99af7dffbb3d3f92c00amwif [[ $CC_FLAG = "y" ]] ; then
d0e518695adc90b82233b99af7dffbb3d3f92c00amw shift $(($OPTIND - 1))
d0e518695adc90b82233b99af7dffbb3d3f92c00amw
d0e518695adc90b82233b99af7dffbb3d3f92c00amw if [[ $# -lt 1 ]] ; then
d0e518695adc90b82233b99af7dffbb3d3f92c00amw ndrgen_usage "C pre-processor path is missing"
d0e518695adc90b82233b99af7dffbb3d3f92c00amw else
d0e518695adc90b82233b99af7dffbb3d3f92c00amw CC=$1
d0e518695adc90b82233b99af7dffbb3d3f92c00amw shift $(($OPTIND - 1))
d0e518695adc90b82233b99af7dffbb3d3f92c00amw
7451ee9355b4d9cafcf1bb6055bb01fc7bdaa1a1amw # Check for cw being invoked with -_cc or -_gcc
7451ee9355b4d9cafcf1bb6055bb01fc7bdaa1a1amw if [[ $1 = "-_cc" || $1 = "-_gcc" ]] ; then
d0e518695adc90b82233b99af7dffbb3d3f92c00amw CC_ARG=$1
d0e518695adc90b82233b99af7dffbb3d3f92c00amw shift $(($OPTIND - 1))
d0e518695adc90b82233b99af7dffbb3d3f92c00amw fi
d0e518695adc90b82233b99af7dffbb3d3f92c00amw fi
d0e518695adc90b82233b99af7dffbb3d3f92c00amwfi
d0e518695adc90b82233b99af7dffbb3d3f92c00amw
d0e518695adc90b82233b99af7dffbb3d3f92c00amwif [[ $CC = "" ]] ; then
d0e518695adc90b82233b99af7dffbb3d3f92c00amw ndrgen_usage "C pre-processor is not defined"
d0e518695adc90b82233b99af7dffbb3d3f92c00amwfi
d0e518695adc90b82233b99af7dffbb3d3f92c00amw
d0e518695adc90b82233b99af7dffbb3d3f92c00amwif [ ! -f $CC ] || [ ! -x $CC ] ; then
d0e518695adc90b82233b99af7dffbb3d3f92c00amw ndrgen_usage "cannot run $CC"
d0e518695adc90b82233b99af7dffbb3d3f92c00amwfi
d0e518695adc90b82233b99af7dffbb3d3f92c00amw
d0e518695adc90b82233b99af7dffbb3d3f92c00amwfor i
d0e518695adc90b82233b99af7dffbb3d3f92c00amwdo
d0e518695adc90b82233b99af7dffbb3d3f92c00amw if [[ ! -r $i ]] ; then
d0e518695adc90b82233b99af7dffbb3d3f92c00amw print "$PROGNAME: ERROR: cannot read $i"
d0e518695adc90b82233b99af7dffbb3d3f92c00amw exit 1
d0e518695adc90b82233b99af7dffbb3d3f92c00amw fi
d0e518695adc90b82233b99af7dffbb3d3f92c00amw
d0e518695adc90b82233b99af7dffbb3d3f92c00amw BASENAME=`basename $i .ndl`
d0e518695adc90b82233b99af7dffbb3d3f92c00amw TMP_NAME=$BASENAME.ndl.c
d0e518695adc90b82233b99af7dffbb3d3f92c00amw
d0e518695adc90b82233b99af7dffbb3d3f92c00amw cp $i $TMP_NAME
d0e518695adc90b82233b99af7dffbb3d3f92c00amw
d0e518695adc90b82233b99af7dffbb3d3f92c00amw if $CC $CC_ARG -E -D__a64 -D__EXTENSIONS__ -D_FILE_OFFSET_BITS=64 \
d0e518695adc90b82233b99af7dffbb3d3f92c00amw -I. -I${INCDIR} -I${INCDIR}/ndl -DNDRGEN $TMP_NAME | \
d0e518695adc90b82233b99af7dffbb3d3f92c00amw $NDRPROG > $BASENAME.raw
d0e518695adc90b82233b99af7dffbb3d3f92c00amw then
9c21fe179ede0eb7881c4d5244e0ab090fdd3c9camw touch ${BASENAME}_ndr.c
9c21fe179ede0eb7881c4d5244e0ab090fdd3c9camw ndrgen_copy_header $i ${BASENAME}_ndr.c
9c21fe179ede0eb7881c4d5244e0ab090fdd3c9camw
9c21fe179ede0eb7881c4d5244e0ab090fdd3c9camw cat - << EOF >> ${BASENAME}_ndr.c
d0e518695adc90b82233b99af7dffbb3d3f92c00amw/*
9c21fe179ede0eb7881c4d5244e0ab090fdd3c9camw * Please do not edit this file.
9c21fe179ede0eb7881c4d5244e0ab090fdd3c9camw * It was generated using ndrgen.
d0e518695adc90b82233b99af7dffbb3d3f92c00amw */
d0e518695adc90b82233b99af7dffbb3d3f92c00amw
d0e518695adc90b82233b99af7dffbb3d3f92c00amw#include <strings.h>
d0e518695adc90b82233b99af7dffbb3d3f92c00amw#include <smbsrv/ndr.h>
d0e518695adc90b82233b99af7dffbb3d3f92c00amw#include <smbsrv/ndl/$BASENAME.ndl>
d0e518695adc90b82233b99af7dffbb3d3f92c00amwEOF
d0e518695adc90b82233b99af7dffbb3d3f92c00amw
d0e518695adc90b82233b99af7dffbb3d3f92c00amw cat $BASENAME.raw >> ${BASENAME}_ndr.c
d0e518695adc90b82233b99af7dffbb3d3f92c00amw
d0e518695adc90b82233b99af7dffbb3d3f92c00amw rm -f $BASENAME.raw
d0e518695adc90b82233b99af7dffbb3d3f92c00amw rm -f $TMP_NAME
d0e518695adc90b82233b99af7dffbb3d3f92c00amw else
d0e518695adc90b82233b99af7dffbb3d3f92c00amw rm -f $BASENAME.raw
d0e518695adc90b82233b99af7dffbb3d3f92c00amw rm -f $TMP_NAME
d0e518695adc90b82233b99af7dffbb3d3f92c00amw exit 1
d0e518695adc90b82233b99af7dffbb3d3f92c00amw fi
d0e518695adc90b82233b99af7dffbb3d3f92c00amwdone