xref: /illumos-gate/usr/src/cmd/adbgen/common/adbgen.sh (revision 533affcbc7fc4d0c8132976ea454aaa715fe2307)
1#! /bin/sh
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, Version 1.0 only
7# (the "License").  You may not use this file except in compliance
8# with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or http://www.opensolaris.org/os/licensing.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23#
24# Copyright (c) 1998 by Sun Microsystems, Inc.
25# All rights reserved.
26#
27# ident	"%Z%%M%	%I%	%E% SMI"
28#
29USAGE="adbgen [-d] [-m ilp32|lp64] [-w] <adb macro file>"
30cflags=
31mflag=-milp32
32subdir=
33
34while getopts dwm: c
35do
36	case $c in
37	d)
38		DEBUG=:
39		;;
40	m)
41		case $OPTARG in
42		ilp32)
43			mflag=-milp32
44			;;
45		lp64)
46			mflag=-mlp64
47			cflags=-xarch=v9
48			subdir=sparcv9
49			/usr/bin/optisa sparcv9 > /dev/null
50			if [ $? -ne 0 ]
51			then
52				echo adbgen -mlp64 must be run on 64-bit system
53			fi
54			;;
55		*)
56			echo $USAGE
57			exit 2
58			;;
59		esac
60		;;
61	w)
62		flag=-w
63		;;
64	\?)
65		echo $USAGE
66		exit 2
67		;;
68        esac
69done
70shift `expr $OPTIND - 1`
71
72ADBDIR=/usr/lib/adb
73PATH=$PATH:$ADBDIR
74for file in $*
75do
76	if [ `expr "XX$file" : ".*\.adb"` -eq 0 ]
77	then
78		echo File $file invalid.
79		exit 1
80	fi
81	if [ $# -gt 1 ]
82	then
83		echo $file:
84	fi
85	file=`expr "XX$file" : "XX\(.*\)\.adb"`
86	if adbgen1 $flag $mflag < $file.adb > $file.adb.c
87	then
88		if ${CC:-cc} -w -D${ARCH:-`uname -m`} $cflags \
89			-I/usr/share/src/uts/${ARCH:-`uname -m`} \
90			-o $file.run $file.adb.c $ADBDIR/$subdir/adbsub.o
91		then
92			$file.run | adbgen3 | adbgen4 > $file
93			$DEBUG rm -f $file.run $file.adb.C $file.adb.c $file.adb.o
94		else
95			$DEBUG rm -f $file.run $file.adb.C $file.adb.c $file.adb.o
96			echo compile failed
97			exit 1
98		fi
99	else
100		$DEBUG rm -f $file.adb.C
101		echo adbgen1 failed
102		exit 1
103	fi
104done
105