xref: /titanic_50/usr/src/tools/ndrgen/ndrgen.sh (revision d4c0a8c59bf9b2697b3dda08963d7f424dcba394)
1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
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.
8#
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.
13#
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]
19#
20# CDDL HEADER END
21#
22#
23# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26# ident	"%Z%%M%	%I%	%E% SMI"
27#
28
29# This is a wrapper script around the ndrgen compiler (ndrgen1).
30# CC must be defined in the environment or on the command line.
31
32NDRPROG="${0%/*}/ndrgen1"
33INCDIR=${ROOT}/usr/include/smbsrv
34
35PROGNAME=`basename $0`
36
37ndrgen_usage()
38{
39	if [[ $1 != "" ]] ; then
40		print "$PROGNAME: ERROR: $1"
41	fi
42
43	echo "usage: $PROGNAME [-Y cpp-path] file [file]..."
44	exit 1
45}
46
47if [[ $# -lt 1 ]] ; then
48	ndrgen_usage
49fi
50
51while getopts "Y" FLAG $*; do
52	case $FLAG in
53	Y)
54		CC_FLAG="y"
55		;;
56	*)
57		ndrgen_usage
58		;;
59	esac
60done
61
62if [[ $CC_FLAG = "y" ]] ; then
63	shift $(($OPTIND - 1))
64
65	if [[ $# -lt 1 ]] ; then
66		ndrgen_usage "C pre-processor path is missing"
67	else
68		CC=$1
69		shift $(($OPTIND - 1))
70
71		# Check for cw being invoked with -_cc or -_gcc
72		if [[ $1 = "-_cc" || $1 = "-_gcc" ]] ; then
73			CC_ARG=$1
74			shift $(($OPTIND - 1))
75		fi
76	fi
77fi
78
79if [[ $CC = "" ]] ; then
80	ndrgen_usage "C pre-processor is not defined"
81fi
82
83if [ ! -f $CC ] || [ ! -x $CC ] ; then
84	ndrgen_usage "cannot run $CC"
85fi
86
87for i
88do
89	if [[ ! -r $i ]] ; then
90		print "$PROGNAME: ERROR: cannot read $i"
91		exit 1
92	fi
93
94	BASENAME=`basename $i .ndl`
95	TMP_NAME=$BASENAME.ndl.c
96
97	cp $i $TMP_NAME
98
99	if $CC $CC_ARG -E  -D__a64 -D__EXTENSIONS__ -D_FILE_OFFSET_BITS=64 \
100		-I. -I${INCDIR} -I${INCDIR}/ndl -DNDRGEN $TMP_NAME | \
101		$NDRPROG > $BASENAME.raw
102	then
103		cat - << EOF > ${BASENAME}_ndr.c
104/*
105 * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
106 * Use is subject to license terms.
107 */
108
109#pragma ident	"@(#)${BASENAME}_ndr.c	1.2	07/01/07 SMI"
110
111/*
112 * THIS FILE IS GENERATED. DO NOT EDIT IT
113 */
114#include <strings.h>
115#include <smbsrv/ndr.h>
116#include <smbsrv/ndl/$BASENAME.ndl>
117EOF
118
119		cat $BASENAME.raw >> ${BASENAME}_ndr.c
120
121		rm -f $BASENAME.raw
122		rm -f $TMP_NAME
123	else
124		rm -f $BASENAME.raw
125		rm -f $TMP_NAME
126		exit 1
127	fi
128done
129