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*9c21fe17Samw# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24d0e51869Samw# Use is subject to license terms. 25d0e51869Samw# 26d0e51869Samw# ident "%Z%%M% %I% %E% SMI" 27d0e51869Samw# 28d0e51869Samw 29d0e51869Samw# This is a wrapper script around the ndrgen compiler (ndrgen1). 30d0e51869Samw# CC must be defined in the environment or on the command line. 31d0e51869Samw 32d0e51869SamwNDRPROG="${0%/*}/ndrgen1" 33d0e51869SamwINCDIR=${ROOT}/usr/include/smbsrv 34d0e51869Samw 35d0e51869SamwPROGNAME=`basename $0` 36d0e51869Samw 37d0e51869Samwndrgen_usage() 38d0e51869Samw{ 39d0e51869Samw if [[ $1 != "" ]] ; then 40d0e51869Samw print "$PROGNAME: ERROR: $1" 41d0e51869Samw fi 42d0e51869Samw 43d0e51869Samw echo "usage: $PROGNAME [-Y cpp-path] file [file]..." 44d0e51869Samw exit 1 45d0e51869Samw} 46d0e51869Samw 47*9c21fe17Samw# Copy header text from the input ndl file to the generated ndr C file. 48*9c21fe17Samwndrgen_copy_header() 49*9c21fe17Samw{ 50*9c21fe17Samw ndl_file=$1 51*9c21fe17Samw ndr_file=$2 52*9c21fe17Samw 53*9c21fe17Samw nawk 'BEGIN { copy=0; } 54*9c21fe17Samw /^\/\* NDRGEN_HEADER_BEGIN \*\// { copy=1; next; } 55*9c21fe17Samw /^\/\* NDRGEN_HEADER_END \*\// { copy=0; next; } 56*9c21fe17Samw /./ { if (copy==1) print; }' < $ndl_file > $ndr_file 57*9c21fe17Samw} 58*9c21fe17Samw 59d0e51869Samwif [[ $# -lt 1 ]] ; then 60d0e51869Samw ndrgen_usage 61d0e51869Samwfi 62d0e51869Samw 63d0e51869Samwwhile getopts "Y" FLAG $*; do 64d0e51869Samw case $FLAG in 65d0e51869Samw Y) 66d0e51869Samw CC_FLAG="y" 67d0e51869Samw ;; 68d0e51869Samw *) 69d0e51869Samw ndrgen_usage 70d0e51869Samw ;; 71d0e51869Samw esac 72d0e51869Samwdone 73d0e51869Samw 74d0e51869Samwif [[ $CC_FLAG = "y" ]] ; then 75d0e51869Samw shift $(($OPTIND - 1)) 76d0e51869Samw 77d0e51869Samw if [[ $# -lt 1 ]] ; then 78d0e51869Samw ndrgen_usage "C pre-processor path is missing" 79d0e51869Samw else 80d0e51869Samw CC=$1 81d0e51869Samw shift $(($OPTIND - 1)) 82d0e51869Samw 837451ee93Samw # Check for cw being invoked with -_cc or -_gcc 847451ee93Samw if [[ $1 = "-_cc" || $1 = "-_gcc" ]] ; then 85d0e51869Samw CC_ARG=$1 86d0e51869Samw shift $(($OPTIND - 1)) 87d0e51869Samw fi 88d0e51869Samw fi 89d0e51869Samwfi 90d0e51869Samw 91d0e51869Samwif [[ $CC = "" ]] ; then 92d0e51869Samw ndrgen_usage "C pre-processor is not defined" 93d0e51869Samwfi 94d0e51869Samw 95d0e51869Samwif [ ! -f $CC ] || [ ! -x $CC ] ; then 96d0e51869Samw ndrgen_usage "cannot run $CC" 97d0e51869Samwfi 98d0e51869Samw 99d0e51869Samwfor i 100d0e51869Samwdo 101d0e51869Samw if [[ ! -r $i ]] ; then 102d0e51869Samw print "$PROGNAME: ERROR: cannot read $i" 103d0e51869Samw exit 1 104d0e51869Samw fi 105d0e51869Samw 106d0e51869Samw BASENAME=`basename $i .ndl` 107d0e51869Samw TMP_NAME=$BASENAME.ndl.c 108d0e51869Samw 109d0e51869Samw cp $i $TMP_NAME 110d0e51869Samw 111d0e51869Samw if $CC $CC_ARG -E -D__a64 -D__EXTENSIONS__ -D_FILE_OFFSET_BITS=64 \ 112d0e51869Samw -I. -I${INCDIR} -I${INCDIR}/ndl -DNDRGEN $TMP_NAME | \ 113d0e51869Samw $NDRPROG > $BASENAME.raw 114d0e51869Samw then 115*9c21fe17Samw touch ${BASENAME}_ndr.c 116*9c21fe17Samw ndrgen_copy_header $i ${BASENAME}_ndr.c 117*9c21fe17Samw 118*9c21fe17Samw cat - << EOF >> ${BASENAME}_ndr.c 119d0e51869Samw/* 120*9c21fe17Samw * Please do not edit this file. 121*9c21fe17Samw * It was generated using ndrgen. 122d0e51869Samw */ 123d0e51869Samw 124*9c21fe17Samw#pragma ident "@(#)${BASENAME}_ndr.c" 125d0e51869Samw 126d0e51869Samw#include <strings.h> 127d0e51869Samw#include <smbsrv/ndr.h> 128d0e51869Samw#include <smbsrv/ndl/$BASENAME.ndl> 129d0e51869SamwEOF 130d0e51869Samw 131d0e51869Samw cat $BASENAME.raw >> ${BASENAME}_ndr.c 132d0e51869Samw 133d0e51869Samw rm -f $BASENAME.raw 134d0e51869Samw rm -f $TMP_NAME 135d0e51869Samw else 136d0e51869Samw rm -f $BASENAME.raw 137d0e51869Samw rm -f $TMP_NAME 138d0e51869Samw exit 1 139d0e51869Samw fi 140d0e51869Samwdone 141