1d0e51869Samw#!/bin/ksh -p 2d0e51869Samw# 3d0e51869Samw# CDDL HEADER START 4d0e51869Samw# 5d0e51869Samw# The contents of this file are subject to the terms of the 6d0e51869Samw# Common Development and Distribution License (the "License"). 7d0e51869Samw# You may not use this file except in compliance with the License. 8d0e51869Samw# 9d0e51869Samw# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10d0e51869Samw# or http://www.opensolaris.org/os/licensing. 11d0e51869Samw# See the License for the specific language governing permissions 12d0e51869Samw# and limitations under the License. 13d0e51869Samw# 14d0e51869Samw# When distributing Covered Code, include this CDDL HEADER in each 15d0e51869Samw# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16d0e51869Samw# If applicable, add the following below this CDDL HEADER, with the 17d0e51869Samw# fields enclosed by brackets "[]" replaced with your own identifying 18d0e51869Samw# information: Portions Copyright [yyyy] [name of copyright owner] 19d0e51869Samw# 20d0e51869Samw# CDDL HEADER END 21d0e51869Samw# 22d0e51869Samw# 23*a0b6e447SAlan Wright# Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24d0e51869Samw# Use is subject to license terms. 25d0e51869Samw# 26d0e51869Samw 27d0e51869Samw# This is a wrapper script around the ndrgen compiler (ndrgen1). 28d0e51869Samw# CC must be defined in the environment or on the command line. 29d0e51869Samw 30d0e51869SamwNDRPROG="${0%/*}/ndrgen1" 31d0e51869SamwINCDIR=${ROOT}/usr/include/smbsrv 32d0e51869Samw 33d0e51869SamwPROGNAME=`basename $0` 34d0e51869Samw 35d0e51869Samwndrgen_usage() 36d0e51869Samw{ 37d0e51869Samw if [[ $1 != "" ]] ; then 38d0e51869Samw print "$PROGNAME: ERROR: $1" 39d0e51869Samw fi 40d0e51869Samw 41d0e51869Samw echo "usage: $PROGNAME [-Y cpp-path] file [file]..." 42d0e51869Samw exit 1 43d0e51869Samw} 44d0e51869Samw 459c21fe17Samw# Copy header text from the input ndl file to the generated ndr C file. 469c21fe17Samwndrgen_copy_header() 479c21fe17Samw{ 489c21fe17Samw ndl_file=$1 499c21fe17Samw ndr_file=$2 509c21fe17Samw 519c21fe17Samw nawk 'BEGIN { copy=0; } 529c21fe17Samw /^\/\* NDRGEN_HEADER_BEGIN \*\// { copy=1; next; } 539c21fe17Samw /^\/\* NDRGEN_HEADER_END \*\// { copy=0; next; } 549c21fe17Samw /./ { if (copy==1) print; }' < $ndl_file > $ndr_file 559c21fe17Samw} 569c21fe17Samw 57d0e51869Samwif [[ $# -lt 1 ]] ; then 58d0e51869Samw ndrgen_usage 59d0e51869Samwfi 60d0e51869Samw 61d0e51869Samwwhile getopts "Y" FLAG $*; do 62d0e51869Samw case $FLAG in 63d0e51869Samw Y) 64d0e51869Samw CC_FLAG="y" 65d0e51869Samw ;; 66d0e51869Samw *) 67d0e51869Samw ndrgen_usage 68d0e51869Samw ;; 69d0e51869Samw esac 70d0e51869Samwdone 71d0e51869Samw 72d0e51869Samwif [[ $CC_FLAG = "y" ]] ; then 73d0e51869Samw shift $(($OPTIND - 1)) 74d0e51869Samw 75d0e51869Samw if [[ $# -lt 1 ]] ; then 76d0e51869Samw ndrgen_usage "C pre-processor path is missing" 77d0e51869Samw else 78d0e51869Samw CC=$1 79d0e51869Samw shift $(($OPTIND - 1)) 80d0e51869Samw 817451ee93Samw # Check for cw being invoked with -_cc or -_gcc 827451ee93Samw if [[ $1 = "-_cc" || $1 = "-_gcc" ]] ; then 83d0e51869Samw CC_ARG=$1 84d0e51869Samw shift $(($OPTIND - 1)) 85d0e51869Samw fi 86d0e51869Samw fi 87d0e51869Samwfi 88d0e51869Samw 89d0e51869Samwif [[ $CC = "" ]] ; then 90d0e51869Samw ndrgen_usage "C pre-processor is not defined" 91d0e51869Samwfi 92d0e51869Samw 93d0e51869Samwif [ ! -f $CC ] || [ ! -x $CC ] ; then 94d0e51869Samw ndrgen_usage "cannot run $CC" 95d0e51869Samwfi 96d0e51869Samw 97d0e51869Samwfor i 98d0e51869Samwdo 99d0e51869Samw if [[ ! -r $i ]] ; then 100d0e51869Samw print "$PROGNAME: ERROR: cannot read $i" 101d0e51869Samw exit 1 102d0e51869Samw fi 103d0e51869Samw 104d0e51869Samw BASENAME=`basename $i .ndl` 105d0e51869Samw TMP_NAME=$BASENAME.ndl.c 106d0e51869Samw 107d0e51869Samw cp $i $TMP_NAME 108d0e51869Samw 109d0e51869Samw if $CC $CC_ARG -E -D__a64 -D__EXTENSIONS__ -D_FILE_OFFSET_BITS=64 \ 110d0e51869Samw -I. -I${INCDIR} -I${INCDIR}/ndl -DNDRGEN $TMP_NAME | \ 111d0e51869Samw $NDRPROG > $BASENAME.raw 112d0e51869Samw then 1139c21fe17Samw touch ${BASENAME}_ndr.c 1149c21fe17Samw ndrgen_copy_header $i ${BASENAME}_ndr.c 1159c21fe17Samw 1169c21fe17Samw cat - << EOF >> ${BASENAME}_ndr.c 117d0e51869Samw/* 1189c21fe17Samw * Please do not edit this file. 1199c21fe17Samw * It was generated using ndrgen. 120d0e51869Samw */ 121d0e51869Samw 122d0e51869Samw#include <strings.h> 123d0e51869Samw#include <smbsrv/ndr.h> 124d0e51869Samw#include <smbsrv/ndl/$BASENAME.ndl> 125d0e51869SamwEOF 126d0e51869Samw 127d0e51869Samw cat $BASENAME.raw >> ${BASENAME}_ndr.c 128d0e51869Samw 129d0e51869Samw rm -f $BASENAME.raw 130d0e51869Samw rm -f $TMP_NAME 131d0e51869Samw else 132d0e51869Samw rm -f $BASENAME.raw 133d0e51869Samw rm -f $TMP_NAME 134d0e51869Samw exit 1 135d0e51869Samw fi 136d0e51869Samwdone 137