xref: /titanic_50/usr/src/lib/libshell/misc/buildksh93.sh (revision 34f9b3eef6fdadbda0a846aa4d68691ac40eace5)
17c2fbfb3SApril Chin#!/bin/ksh -p
27c2fbfb3SApril Chin# (note we use "/bin/ksh -p" for Linux/pdksh support in this script)
37c2fbfb3SApril Chin
47c2fbfb3SApril Chin#
57c2fbfb3SApril Chin# CDDL HEADER START
67c2fbfb3SApril Chin#
77c2fbfb3SApril Chin# The contents of this file are subject to the terms of the
87c2fbfb3SApril Chin# Common Development and Distribution License (the "License").
97c2fbfb3SApril Chin# You may not use this file except in compliance with the License.
107c2fbfb3SApril Chin#
117c2fbfb3SApril Chin# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
127c2fbfb3SApril Chin# or http://www.opensolaris.org/os/licensing.
137c2fbfb3SApril Chin# See the License for the specific language governing permissions
147c2fbfb3SApril Chin# and limitations under the License.
157c2fbfb3SApril Chin#
167c2fbfb3SApril Chin# When distributing Covered Code, include this CDDL HEADER in each
177c2fbfb3SApril Chin# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
187c2fbfb3SApril Chin# If applicable, add the following below this CDDL HEADER, with the
197c2fbfb3SApril Chin# fields enclosed by brackets "[]" replaced with your own identifying
207c2fbfb3SApril Chin# information: Portions Copyright [yyyy] [name of copyright owner]
217c2fbfb3SApril Chin#
227c2fbfb3SApril Chin# CDDL HEADER END
237c2fbfb3SApril Chin#
247c2fbfb3SApril Chin
257c2fbfb3SApril Chin#
26*34f9b3eeSRoland Mainz# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
277c2fbfb3SApril Chin# Use is subject to license terms.
287c2fbfb3SApril Chin#
297c2fbfb3SApril Chin
307c2fbfb3SApril Chin#
31*34f9b3eeSRoland Mainz# buildksh93.sh - ast-ksh standalone build script for the
327c2fbfb3SApril Chin# OpenSolaris ksh93-integration project
337c2fbfb3SApril Chin#
347c2fbfb3SApril Chin
357c2fbfb3SApril Chin# ksh93t sources can be downloaded like this from the AT&T site:
36*34f9b3eeSRoland Mainz# wget --http-user="I accept www.opensource.org/licenses/cpl" --http-passwd="." 'http://www.research.att.com/sw/download/beta/INIT.2009-10-14.tgz'
37*34f9b3eeSRoland Mainz# wget --http-user="I accept www.opensource.org/licenses/cpl" --http-passwd="." 'http://www.research.att.com/sw/download/beta/ast-ksh.2009-10-14.tgz'
387c2fbfb3SApril Chin
397c2fbfb3SApril Chinfunction fatal_error
407c2fbfb3SApril Chin{
417c2fbfb3SApril Chin    print -u2 "${progname}: $*"
427c2fbfb3SApril Chin    exit 1
437c2fbfb3SApril Chin}
447c2fbfb3SApril Chin
457c2fbfb3SApril Chinset -o errexit
467c2fbfb3SApril Chinset -o xtrace
477c2fbfb3SApril Chin
487c2fbfb3SApril Chintypeset progname="$(basename "${0}")"
497c2fbfb3SApril Chintypeset buildmode="$1"
507c2fbfb3SApril Chin
517c2fbfb3SApril Chinif [[ "${buildmode}" == "" ]] ; then
527c2fbfb3SApril Chin    fatal_error "buildmode required."
537c2fbfb3SApril Chinfi
547c2fbfb3SApril Chin
557c2fbfb3SApril Chin# Make sure we use the C locale during building to avoid any unintended
567c2fbfb3SApril Chin# side-effects
577c2fbfb3SApril Chinexport LANG=C
587c2fbfb3SApril Chinexport LC_ALL=$LANG LC_MONETARY=$LANG LC_NUMERIC=$LANG LC_MESSAGES=$LANG LC_COLLATE=$LANG LC_CTYPE=$LANG
597c2fbfb3SApril Chin# Make sure the POSIX/XPG6 tools are in front of /usr/bin (/bin is needed for Linux after /usr/bin)
607c2fbfb3SApril Chinexport PATH=/usr/xpg6/bin:/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:/bin:/opt/SUNWspro/bin
617c2fbfb3SApril Chin
627c2fbfb3SApril Chin# Make sure the POSIX/XPG6 packages are installed (mandatory for building
637c2fbfb3SApril Chin# our version of ksh93 correctly).
647c2fbfb3SApril Chinif [[ "$(uname -s)" == "SunOS" ]] ; then
657c2fbfb3SApril Chin    if [[ ! -x "/usr/xpg6/bin/tr" ]] ; then
667c2fbfb3SApril Chin        fatal_error "XPG6/4 packages (SUNWxcu6,SUNWxcu4) not installed."
677c2fbfb3SApril Chin    fi
687c2fbfb3SApril Chinfi
697c2fbfb3SApril Chin
707c2fbfb3SApril Chinfunction print_solaris_builtin_header
717c2fbfb3SApril Chin{
727c2fbfb3SApril Chin# Make sure to use \\ instead of \ for continuations
737c2fbfb3SApril Chincat <<ENDOFTEXT
747c2fbfb3SApril Chin/*
757c2fbfb3SApril Chin * CDDL HEADER START
767c2fbfb3SApril Chin *
777c2fbfb3SApril Chin * The contents of this file are subject to the terms of the
787c2fbfb3SApril Chin * Common Development and Distribution License (the "License").
797c2fbfb3SApril Chin * You may not use this file except in compliance with the License.
807c2fbfb3SApril Chin *
817c2fbfb3SApril Chin * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
827c2fbfb3SApril Chin * or http://www.opensolaris.org/os/licensing.
837c2fbfb3SApril Chin * See the License for the specific language governing permissions
847c2fbfb3SApril Chin * and limitations under the License.
857c2fbfb3SApril Chin *
867c2fbfb3SApril Chin * When distributing Covered Code, include this CDDL HEADER in each
877c2fbfb3SApril Chin * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
887c2fbfb3SApril Chin * If applicable, add the following below this CDDL HEADER, with the
897c2fbfb3SApril Chin * fields enclosed by brackets "[]" replaced with your own identifying
907c2fbfb3SApril Chin * information: Portions Copyright [yyyy] [name of copyright owner]
917c2fbfb3SApril Chin *
927c2fbfb3SApril Chin * CDDL HEADER END
937c2fbfb3SApril Chin */
947c2fbfb3SApril Chin
957c2fbfb3SApril Chin/*
96*34f9b3eeSRoland Mainz * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
977c2fbfb3SApril Chin * Use is subject to license terms.
987c2fbfb3SApril Chin */
997c2fbfb3SApril Chin
1007c2fbfb3SApril Chin#ifndef _SOLARIS_KSH_CMDLIST_H
1017c2fbfb3SApril Chin#define	_SOLARIS_KSH_CMDLIST_H
1027c2fbfb3SApril Chin
1037c2fbfb3SApril Chin#ifdef	__cplusplus
1047c2fbfb3SApril Chinextern "C" {
1057c2fbfb3SApril Chin#endif
1067c2fbfb3SApril Chin
1077c2fbfb3SApril Chin/*
1087c2fbfb3SApril Chin * List builtins for Solaris.
1097c2fbfb3SApril Chin * The list here is partially autogenerated and partially hand-picked
1107c2fbfb3SApril Chin * based on compatibility with the native Solaris versions of these
1117c2fbfb3SApril Chin * tools
1127c2fbfb3SApril Chin */
1137c2fbfb3SApril Chin
1147c2fbfb3SApril Chin/* POSIX compatible commands */
1157c2fbfb3SApril Chin#ifdef _NOT_YET
1167c2fbfb3SApril Chin#define	XPG6CMDLIST(f)	\\
1177c2fbfb3SApril Chin	{ "/usr/xpg6/bin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
1187c2fbfb3SApril Chin#define	XPG4CMDLIST(f)	\\
1197c2fbfb3SApril Chin	{ "/usr/xpg4/bin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
1207c2fbfb3SApril Chin#else
1217c2fbfb3SApril Chin#define	XPG6CMDLIST(f)
1227c2fbfb3SApril Chin#define	XPG4CMDLIST(f)
1237c2fbfb3SApril Chin#endif /* NOT_YET */
1247c2fbfb3SApril Chin/*
1257c2fbfb3SApril Chin * Commands which are 100% compatible with native Solaris versions (/bin is
1267c2fbfb3SApril Chin * a softlink to ./usr/bin, ksh93 takes care about the lookup)
1277c2fbfb3SApril Chin */
1287c2fbfb3SApril Chin#define	BINCMDLIST(f)	\\
1297c2fbfb3SApril Chin	{ "/bin/"	#f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
1307c2fbfb3SApril Chin#define	USRBINCMDLIST(f)	\\
1317c2fbfb3SApril Chin	{ "/usr/bin/"	#f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
1327c2fbfb3SApril Chin#define	SBINCMDLIST(f)	\\
1337c2fbfb3SApril Chin	{ "/sbin/"	#f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
1347c2fbfb3SApril Chin#define	SUSRBINCMDLIST(f)	\\
1357c2fbfb3SApril Chin	{ "/usr/sbin/"	#f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
1367c2fbfb3SApril Chin/*
1377c2fbfb3SApril Chin * Make all ksh93 builtins accessible when /usr/ast/bin was added to
1387c2fbfb3SApril Chin * /usr/xpg6/bin:/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:/bin:/opt/SUNWspro/bin
1397c2fbfb3SApril Chin */
1407c2fbfb3SApril Chin#define	ASTCMDLIST(f)	\\
1417c2fbfb3SApril Chin	{ "/usr/ast/bin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
1427c2fbfb3SApril Chin
1437c2fbfb3SApril Chin/* undo ast_map.h #defines to avoid collision */
1447c2fbfb3SApril Chin#undef basename
1457c2fbfb3SApril Chin#undef dirname
146*34f9b3eeSRoland Mainz#undef mktemp
1477c2fbfb3SApril Chin
1487c2fbfb3SApril Chin/* Generated data, do not edit. */
1497c2fbfb3SApril ChinXPG4CMDLIST(basename)
1507c2fbfb3SApril ChinASTCMDLIST(basename)
1517c2fbfb3SApril ChinBINCMDLIST(cat)
1527c2fbfb3SApril ChinASTCMDLIST(cat)
1537c2fbfb3SApril ChinXPG4CMDLIST(chgrp)
1547c2fbfb3SApril ChinASTCMDLIST(chgrp)
1557c2fbfb3SApril ChinASTCMDLIST(chmod)
1567c2fbfb3SApril ChinXPG4CMDLIST(chown)
1577c2fbfb3SApril ChinBINCMDLIST(chown)
1587c2fbfb3SApril ChinASTCMDLIST(chown)
1597c2fbfb3SApril ChinBINCMDLIST(cksum)
1607c2fbfb3SApril ChinASTCMDLIST(cksum)
1617c2fbfb3SApril ChinBINCMDLIST(cmp)
1627c2fbfb3SApril ChinASTCMDLIST(cmp)
163*34f9b3eeSRoland MainzBINCMDLIST(comm)
1647c2fbfb3SApril ChinASTCMDLIST(comm)
1657c2fbfb3SApril ChinXPG4CMDLIST(cp)
1667c2fbfb3SApril ChinASTCMDLIST(cp)
1677c2fbfb3SApril ChinBINCMDLIST(cut)
1687c2fbfb3SApril ChinASTCMDLIST(cut)
1697c2fbfb3SApril ChinXPG4CMDLIST(date)
1707c2fbfb3SApril ChinASTCMDLIST(date)
1717c2fbfb3SApril ChinASTCMDLIST(dirname)
1727c2fbfb3SApril ChinXPG4CMDLIST(expr)
1737c2fbfb3SApril ChinASTCMDLIST(expr)
1747c2fbfb3SApril ChinASTCMDLIST(fds)
1757c2fbfb3SApril ChinASTCMDLIST(fmt)
176*34f9b3eeSRoland MainzBINCMDLIST(fold)
1777c2fbfb3SApril ChinASTCMDLIST(fold)
1787c2fbfb3SApril ChinBINCMDLIST(head)
1797c2fbfb3SApril ChinASTCMDLIST(head)
1807c2fbfb3SApril ChinXPG4CMDLIST(id)
1817c2fbfb3SApril ChinASTCMDLIST(id)
182*34f9b3eeSRoland MainzBINCMDLIST(join)
1837c2fbfb3SApril ChinASTCMDLIST(join)
1847c2fbfb3SApril ChinXPG4CMDLIST(ln)
1857c2fbfb3SApril ChinASTCMDLIST(ln)
1867c2fbfb3SApril ChinBINCMDLIST(logname)
1877c2fbfb3SApril ChinASTCMDLIST(logname)
1887c2fbfb3SApril ChinBINCMDLIST(mkdir)
1897c2fbfb3SApril ChinASTCMDLIST(mkdir)
1907c2fbfb3SApril ChinBINCMDLIST(mkfifo)
1917c2fbfb3SApril ChinASTCMDLIST(mkfifo)
192*34f9b3eeSRoland MainzBINCMDLIST(mktemp)
193*34f9b3eeSRoland MainzASTCMDLIST(mktemp)
1947c2fbfb3SApril ChinXPG4CMDLIST(mv)
1957c2fbfb3SApril ChinASTCMDLIST(mv)
1967c2fbfb3SApril ChinBINCMDLIST(paste)
1977c2fbfb3SApril ChinASTCMDLIST(paste)
198*34f9b3eeSRoland MainzBINCMDLIST(pathchk)
1997c2fbfb3SApril ChinASTCMDLIST(pathchk)
2007c2fbfb3SApril ChinBINCMDLIST(rev)
2017c2fbfb3SApril ChinASTCMDLIST(rev)
2027c2fbfb3SApril ChinXPG4CMDLIST(rm)
2037c2fbfb3SApril ChinASTCMDLIST(rm)
2047c2fbfb3SApril ChinBINCMDLIST(rmdir)
2057c2fbfb3SApril ChinASTCMDLIST(rmdir)
2067c2fbfb3SApril ChinXPG4CMDLIST(stty)
2077c2fbfb3SApril ChinASTCMDLIST(stty)
2087c2fbfb3SApril ChinBINCMDLIST(sum)
2097c2fbfb3SApril ChinASTCMDLIST(sum)
2107c2fbfb3SApril ChinSUSRBINCMDLIST(sync)
2117c2fbfb3SApril ChinSBINCMDLIST(sync)
2127c2fbfb3SApril ChinBINCMDLIST(sync)
2137c2fbfb3SApril ChinASTCMDLIST(sync)
214*34f9b3eeSRoland MainzBINCMDLIST(tail)
2157c2fbfb3SApril ChinXPG4CMDLIST(tail)
2167c2fbfb3SApril ChinASTCMDLIST(tail)
2177c2fbfb3SApril ChinBINCMDLIST(tee)
2187c2fbfb3SApril ChinASTCMDLIST(tee)
2197c2fbfb3SApril ChinBINCMDLIST(tty)
2207c2fbfb3SApril ChinASTCMDLIST(tty)
2217c2fbfb3SApril ChinASTCMDLIST(uname)
2227c2fbfb3SApril ChinBINCMDLIST(uniq)
2237c2fbfb3SApril ChinASTCMDLIST(uniq)
2247c2fbfb3SApril ChinBINCMDLIST(wc)
2257c2fbfb3SApril ChinASTCMDLIST(wc)
2267c2fbfb3SApril Chin
2277c2fbfb3SApril Chin/* Mandatory for ksh93 test suite and AST scripts */
2287c2fbfb3SApril ChinBINCMDLIST(getconf)
2297c2fbfb3SApril Chin
2307c2fbfb3SApril Chin#ifdef	__cplusplus
2317c2fbfb3SApril Chin}
2327c2fbfb3SApril Chin#endif
2337c2fbfb3SApril Chin
2347c2fbfb3SApril Chin#endif /* !_SOLARIS_KSH_CMDLIST_H */
2357c2fbfb3SApril ChinENDOFTEXT
2367c2fbfb3SApril Chin}
2377c2fbfb3SApril Chin
2387c2fbfb3SApril Chinfunction build_shell
2397c2fbfb3SApril Chin{
2407c2fbfb3SApril Chin    set -o errexit
2417c2fbfb3SApril Chin    set -o xtrace
2427c2fbfb3SApril Chin
2437c2fbfb3SApril Chin    # OS.cputype.XXbit.compiler
2447c2fbfb3SApril Chin    case "${buildmode}" in
2457c2fbfb3SApril Chin        *.linux.*)
2467c2fbfb3SApril Chin            # ksh93+AST config flags
2477c2fbfb3SApril Chin            bast_flags="-DSHOPT_CMDLIB_BLTIN=0 -DSH_CMDLIB_DIR=\\\"/usr/ast/bin\\\" -DSHOPT_SYSRC -D_map_libc=1"
2487c2fbfb3SApril Chin
2497c2fbfb3SApril Chin            # gcc flags
2507c2fbfb3SApril Chin            bgcc99="gcc -std=gnu99 "
2517c2fbfb3SApril Chin            bgcc_ccflags="${bon_flags} ${bast_flags} -g"
2527c2fbfb3SApril Chin
2537c2fbfb3SApril Chin            case "${buildmode}" in
2547c2fbfb3SApril Chin                # Linux i386
2557c2fbfb3SApril Chin                *.i386.32bit.gcc*)  HOSTTYPE="linux.i386" CC="${bgcc99} -fPIC" cc_sharedlib="-shared" CCFLAGS="${bgcc_ccflags}"
2567c2fbfb3SApril Chin                    ;;
2577c2fbfb3SApril Chin                *)
2587c2fbfb3SApril Chin                    fatal_error "build_shell: Illegal Linux type/compiler build mode \"${buildmode}\"."
2597c2fbfb3SApril Chin                    ;;
2607c2fbfb3SApril Chin            esac
2617c2fbfb3SApril Chin            ;;
2627c2fbfb3SApril Chin        *.solaris.*)
2637c2fbfb3SApril Chin            # Notes:
2647c2fbfb3SApril Chin            # 1. Do not remove/modify these flags or their order before either
2657c2fbfb3SApril Chin            # asking the project leads at
2667c2fbfb3SApril Chin            # http://www.opensolaris.org/os/project/ksh93-integration/
2677c2fbfb3SApril Chin            # These flags all have a purpose, even if they look
2687c2fbfb3SApril Chin            # weird/redundant/etc. at the first look.
2697c2fbfb3SApril Chin            #
2707c2fbfb3SApril Chin            # 2. We use -KPIC here since -Kpic is too small on 64bit sparc and
2717c2fbfb3SApril Chin            # on 32bit it's close to the barrier so we use it for both 32bit and
2727c2fbfb3SApril Chin            # 64bit to avoid later suprises when people update libast in the
2737c2fbfb3SApril Chin            # future
2747c2fbfb3SApril Chin            #
2757c2fbfb3SApril Chin            # 3. "-D_map_libc=1" is needed to force map.c to add a "_ast_" prefix to all
2767c2fbfb3SApril Chin            # AST symbol names which may otherwise collide with Solaris/Linux libc
2777c2fbfb3SApril Chin            #
2787c2fbfb3SApril Chin            # 4. "-DSHOPT_SYSRC" enables /etc/ksh.kshrc support (AST default is currently
2797c2fbfb3SApril Chin            # to enable it if /etc/ksh.kshrc or /etc/bash.bashrc are available on the
2807c2fbfb3SApril Chin            # build machine).
2817c2fbfb3SApril Chin            #
2827c2fbfb3SApril Chin            # 5. -D_lib_socket=1 -lsocket -lnsl" was added to make sure ksh93 is compiled
2837c2fbfb3SApril Chin            # with networking support enabled, the current AST build infratructure has
2847c2fbfb3SApril Chin            # problems with detecting networking support in Solaris.
2857c2fbfb3SApril Chin            #
2867c2fbfb3SApril Chin            # 6. "-xc99=%all -D_XOPEN_SOURCE=600 -D__EXTENSIONS__=1" is used to force
2877c2fbfb3SApril Chin            # the compiler into C99 mode. Otherwise ksh93 will be much slower and lacks
2887c2fbfb3SApril Chin            # lots of arithmethic functions.
2897c2fbfb3SApril Chin            #
2907c2fbfb3SApril Chin            # 7. "-D_TS_ERRNO -D_REENTRANT" are flags taken from the default OS/Net
2917c2fbfb3SApril Chin            # build system.
2927c2fbfb3SApril Chin            #
2937c2fbfb3SApril Chin            # 8. "-xpagesize_stack=64K is used on SPARC to enhance the performace
2947c2fbfb3SApril Chin            #
2957c2fbfb3SApril Chin            # 9. -DSHOPT_CMDLIB_BLTIN=0 -DSH_CMDLIB_DIR=\\\"/usr/ast/bin\\\" -DSHOPT_CMDLIB_HDR=\\\"/home/test001/ksh93/ast_ksh_20070322/solaris_cmdlist.h\\\"
2967c2fbfb3SApril Chin            # is used to bind all ksh93 builtins to a "virtual" directory
2977c2fbfb3SApril Chin            # called "/usr/ast/bin/" and to adjust the list of builtins
2987c2fbfb3SApril Chin            # enabled by default to those defined by PSARC 2006/550
2997c2fbfb3SApril Chin
3007c2fbfb3SApril Chin            solaris_builtin_header="${PWD}/tmp_solaris_builtin_header.h"
3017c2fbfb3SApril Chin            print_solaris_builtin_header >"${solaris_builtin_header}"
3027c2fbfb3SApril Chin
3037c2fbfb3SApril Chin            # OS/Net build flags
3047c2fbfb3SApril Chin            bon_flags="-D_TS_ERRNO -D_REENTRANT"
3057c2fbfb3SApril Chin
3067c2fbfb3SApril Chin            # ksh93+AST config flags
3077c2fbfb3SApril Chin            bast_flags="-DSHOPT_CMDLIB_BLTIN=0 -DSH_CMDLIB_DIR=\\\"/usr/ast/bin\\\" -DSHOPT_CMDLIB_HDR=\\\"${solaris_builtin_header}\\\" -DSHOPT_SYSRC -D_map_libc=1"
3087c2fbfb3SApril Chin
3097c2fbfb3SApril Chin            # Sun Studio flags
3107c2fbfb3SApril Chin            bsunc99="/opt/SUNWspro/bin/cc -xc99=%all -D_XOPEN_SOURCE=600 -D__EXTENSIONS__=1"
3117c2fbfb3SApril Chin            bsuncc_app_ccflags_sparc="-xpagesize_stack=64K" # use bsuncc_app_ccflags_sparc only for final executables
3127c2fbfb3SApril Chin            bsuncc_ccflags="${bon_flags} -KPIC -g -xs -xspace -Xa -xstrconst -z combreloc -xildoff -xcsi -errtags=yes ${bast_flags} -D_lib_socket=1 -lsocket -lnsl"
3137c2fbfb3SApril Chin
3147c2fbfb3SApril Chin            # gcc flags
3157c2fbfb3SApril Chin            bgcc99="/usr/sfw/bin/gcc -std=gnu99 -D_XOPEN_SOURCE=600 -D__EXTENSIONS__=1"
316*34f9b3eeSRoland Mainz            bgcc_warnflags="-Wall -Wextra -Wno-unknown-pragmas -Wno-missing-braces -Wno-sign-compare -Wno-parentheses -Wno-uninitialized -Wno-implicit-function-declaration -Wno-unused -Wno-trigraphs -Wno-char-subscripts -Wno-switch"
317*34f9b3eeSRoland Mainz            bgcc_ccflags="${bon_flags} ${bgcc_warnflags} ${bast_flags} -D_lib_socket=1 -lsocket -lnsl"
3187c2fbfb3SApril Chin
3197c2fbfb3SApril Chin            case "${buildmode}" in
320*34f9b3eeSRoland Mainz	        # for -m32/-m64 flags see usr/src/Makefile.master, makefile symbols *_XARCH/co.
321*34f9b3eeSRoland Mainz                *.i386.32bit.suncc*)  HOSTTYPE="sol11.i386" CC="${bsunc99} -m32"                  cc_sharedlib="-G" CCFLAGS="${bsuncc_ccflags}"  ;;
322*34f9b3eeSRoland Mainz                *.i386.64bit.suncc*)  HOSTTYPE="sol11.i386" CC="${bsunc99} -m64 -KPIC"            cc_sharedlib="-G" CCFLAGS="${bsuncc_ccflags}"  ;;
323*34f9b3eeSRoland Mainz                *.sparc.32bit.suncc*) HOSTTYPE="sol11.sun4" CC="${bsunc99} -m32"                  cc_sharedlib="-G" CCFLAGS="${bsuncc_ccflags}" bsuncc_app_ccflags="${bsuncc_app_ccflags_sparc}" ;;
324*34f9b3eeSRoland Mainz                *.sparc.64bit.suncc*) HOSTTYPE="sol11.sun4" CC="${bsunc99} -m64 -dalign -KPIC"    cc_sharedlib="-G" CCFLAGS="${bsuncc_ccflags}" bsuncc_app_ccflags="${bsuncc_app_ccflags_sparc}" ;;
3257c2fbfb3SApril Chin
3267c2fbfb3SApril Chin                *.i386.32bit.gcc*)  HOSTTYPE="sol11.i386" CC="${bgcc99} -fPIC"                                            cc_sharedlib="-shared" CCFLAGS="${bgcc_ccflags}"  ;;
3277c2fbfb3SApril Chin                *.i386.64bit.gcc*)  HOSTTYPE="sol11.i386" CC="${bgcc99} -m64 -mtune=opteron -Ui386 -U__i386 -fPIC"        cc_sharedlib="-shared" CCFLAGS="${bgcc_ccflags}"  ;;
3287c2fbfb3SApril Chin                *.sparc.32bit.gcc*) HOSTTYPE="sol11.sun4" CC="${bgcc99} -m32 -mcpu=v8 -fPIC"                              cc_sharedlib="-shared" CCFLAGS="${bgcc_ccflags}"  ;;
3297c2fbfb3SApril Chin                *.sparc.64bit.gcc*) HOSTTYPE="sol11.sun4" CC="${bgcc99} -m64 -mcpu=v9 -fPIC"                              cc_sharedlib="-shared" CCFLAGS="${bgcc_ccflags}"  ;;
3307c2fbfb3SApril Chin                *.s390.32bit.gcc*)  HOSTTYPE="sol11.s390" CC="${bgcc99} -m32          -fPIC"				  cc_sharedlib="-shared" CCFLAGS="${bgcc_ccflags}"  ;;
3317c2fbfb3SApril Chin                *.s390.64bit.gcc*)  HOSTTYPE="sol11.s390" CC="${bgcc99} -m64          -fPIC"				  cc_sharedlib="-shared" CCFLAGS="${bgcc_ccflags}"  ;;
3327c2fbfb3SApril Chin
3337c2fbfb3SApril Chin                *)
3347c2fbfb3SApril Chin                    fatal_error "build_shell: Illegal Solaris type/compiler build mode \"${buildmode}\"."
3357c2fbfb3SApril Chin                    ;;
3367c2fbfb3SApril Chin            esac
3377c2fbfb3SApril Chin            ;;
3387c2fbfb3SApril Chin        *)
3397c2fbfb3SApril Chin            fatal_error "Illegal OS build mode \"${buildmode}\"."
3407c2fbfb3SApril Chin            ;;
3417c2fbfb3SApril Chin    esac
3427c2fbfb3SApril Chin
3437c2fbfb3SApril Chin    # some prechecks
3447c2fbfb3SApril Chin    [[ -z "${CCFLAGS}"  ]] && fatal_error "build_shell: CCFLAGS is empty."
3457c2fbfb3SApril Chin    [[ -z "${CC}"       ]] && fatal_error "build_shell: CC is empty."
3467c2fbfb3SApril Chin    [[ -z "${HOSTTYPE}" ]] && fatal_error "build_shell: HOSTTYPE is empty."
3477c2fbfb3SApril Chin    [[ ! -f "bin/package" ]] && fatal_error "build_shell: bin/package missing."
3487c2fbfb3SApril Chin    [[ ! -x "bin/package" ]] && fatal_error "build_shell: bin/package not executable."
3497c2fbfb3SApril Chin
3507c2fbfb3SApril Chin    export CCFLAGS CC HOSTTYPE
3517c2fbfb3SApril Chin
3527c2fbfb3SApril Chin    # build ksh93
3537c2fbfb3SApril Chin    bin/package make CCFLAGS="${CCFLAGS}" CC="${CC}" HOSTTYPE="${HOSTTYPE}"
3547c2fbfb3SApril Chin
3557c2fbfb3SApril Chin    root="${PWD}/arch/${HOSTTYPE}"
3567c2fbfb3SApril Chin    [[ -d "$root" ]] || fatal_error "build_shell: directory ${root} not found."
3577c2fbfb3SApril Chin    log="${root}/lib/package/gen/make.out"
3587c2fbfb3SApril Chin
3597c2fbfb3SApril Chin    [[ -s $log ]] || fatal_error "build_shell: no make.out log found."
3607c2fbfb3SApril Chin
361*34f9b3eeSRoland Mainz    if [[ -f ${root}/lib/libast-g.a   ]] then link_libast="ast-g"     ; else link_libast="ast"     ; fi
362*34f9b3eeSRoland Mainz    if [[ -f ${root}/lib/libdll-g.a   ]] then link_libdll="dll-g"     ; else link_libdll="dll"     ; fi
363*34f9b3eeSRoland Mainz    if [[ -f ${root}/lib/libsum-g.a   ]] then link_libsum="sum-g"     ; else link_libsum="sum"     ; fi
364*34f9b3eeSRoland Mainz    if [[ -f ${root}/lib/libcmd-g.a   ]] then link_libcmd="cmd-g"     ; else link_libcmd="cmd"     ; fi
365*34f9b3eeSRoland Mainz    if [[ -f ${root}/lib/libshell-g.a ]] then link_libshell="shell-g" ; else link_libshell="shell" ; fi
366*34f9b3eeSRoland Mainz
3677c2fbfb3SApril Chin    if [[ "${buildmode}" != *.staticshell* ]] ; then
3687c2fbfb3SApril Chin        # libcmd causes some trouble since there is a squatter in solaris
3697c2fbfb3SApril Chin        # This has been fixed in Solaris 11/B48 but may require adjustments
3707c2fbfb3SApril Chin        # for older Solaris releases
3717c2fbfb3SApril Chin        for lib in libast libdll libsum libcmd libshell ; do
3727c2fbfb3SApril Chin            case "$lib" in
3737c2fbfb3SApril Chin            libshell)
374*34f9b3eeSRoland Mainz                base="src/cmd/ksh93/"
3757c2fbfb3SApril Chin                vers=1
376*34f9b3eeSRoland Mainz                link="-L${root}/lib/ -l${link_libcmd} -l${link_libsum} -l${link_libdll} -l${link_libast} -lm"
3777c2fbfb3SApril Chin                ;;
3787c2fbfb3SApril Chin            libdll)
3797c2fbfb3SApril Chin                base="src/lib/${lib}"
3807c2fbfb3SApril Chin                vers=1
3817c2fbfb3SApril Chin                link="-ldl"
3827c2fbfb3SApril Chin                ;;
3837c2fbfb3SApril Chin            libast)
3847c2fbfb3SApril Chin                base="src/lib/${lib}"
3857c2fbfb3SApril Chin                vers=1
3867c2fbfb3SApril Chin                link="-lm"
3877c2fbfb3SApril Chin                ;;
3887c2fbfb3SApril Chin            *)
3897c2fbfb3SApril Chin                base="src/lib/${lib}"
3907c2fbfb3SApril Chin                vers=1
391*34f9b3eeSRoland Mainz                link="-L${root}/lib/ -l${link_libast} -lm"
3927c2fbfb3SApril Chin                ;;
3937c2fbfb3SApril Chin            esac
3947c2fbfb3SApril Chin
3957c2fbfb3SApril Chin            (
3967c2fbfb3SApril Chin            cd "${root}/${base}"
397*34f9b3eeSRoland Mainz
398*34f9b3eeSRoland Mainz	    if [[ -f ${lib}-g.a ]] ; then lib_a="${lib}-g.a" ; else lib_a="${lib}.a" ; fi
399*34f9b3eeSRoland Mainz
4007c2fbfb3SApril Chin            if [[ "${buildmode}" == *solaris* ]] ; then
401*34f9b3eeSRoland Mainz                ${CC} ${cc_sharedlib} ${CCFLAGS} -Bdirect -Wl,-zallextract -Wl,-zmuldefs -o "${root}/lib/${lib}.so.${vers}" "${lib_a}"  $link
4027c2fbfb3SApril Chin            else
403*34f9b3eeSRoland Mainz                ${CC} ${cc_sharedlib} ${CCFLAGS} -Wl,--whole-archive -Wl,-zmuldefs "${lib_a}" -Wl,--no-whole-archive -o "${root}/lib/${lib}.so.${vers}" $link
4047c2fbfb3SApril Chin            fi
4057c2fbfb3SApril Chin
4067c2fbfb3SApril Chin            #rm ${lib}.a
407*34f9b3eeSRoland Mainz            mv "${lib_a}" "disabled_${lib_a}_"
4087c2fbfb3SApril Chin
4097c2fbfb3SApril Chin            cd "${root}/lib"
4107c2fbfb3SApril Chin            ln -sf "${lib}.so.${vers}" "${lib}.so"
4117c2fbfb3SApril Chin            )
4127c2fbfb3SApril Chin        done
4137c2fbfb3SApril Chin
4147c2fbfb3SApril Chin        (
4157c2fbfb3SApril Chin          base=src/cmd/ksh93
4167c2fbfb3SApril Chin          cd "${root}/${base}"
4177c2fbfb3SApril Chin          rm -f \
418*34f9b3eeSRoland Mainz	      "${root}/lib/libshell.a" "${root}/lib/libshell-g.a" \
419*34f9b3eeSRoland Mainz              "${root}/lib/libsum.a" "${root}/lib/libsum-g.a" \
420*34f9b3eeSRoland Mainz              "${root}/lib/libdll.a" "${root}/lib/libdll-g.a" \
421*34f9b3eeSRoland Mainz              "${root}/lib/libast.a""${root}/lib/libast-g.a"
4227c2fbfb3SApril Chin
4237c2fbfb3SApril Chin          if [[ "${buildmode}" == *solaris* ]] ; then
424*34f9b3eeSRoland Mainz              ${CC} ${CCFLAGS} ${bsuncc_app_ccflags} -L${root}/lib/ -Bdirect -o ksh pmain.o -lshell -Bstatic -l${link_libcmd} -Bdynamic -lsum -ldll -last -lm -lmd -lsecdb
4257c2fbfb3SApril Chin          else
4267c2fbfb3SApril Chin              ${CC} ${CCFLAGS} ${bsuncc_app_ccflags} -L${root}/lib/ -o ksh pmain.o -lshell -lcmd -lsum -ldll -last -lm
4277c2fbfb3SApril Chin          fi
4287c2fbfb3SApril Chin
4297c2fbfb3SApril Chin	  file ksh
4307c2fbfb3SApril Chin	  file shcomp
4317c2fbfb3SApril Chin
4327c2fbfb3SApril Chin	  export LD_LIBRARY_PATH="${root}/lib:${LD_LIBRARY_PATH}"
4337c2fbfb3SApril Chin	  export LD_LIBRARY_PATH_32="${root}/lib:${LD_LIBRARY_PATH_32}"
4347c2fbfb3SApril Chin	  export LD_LIBRARY_PATH_64="${root}/lib:${LD_LIBRARY_PATH_64}"
4357c2fbfb3SApril Chin	  ldd ksh
4367c2fbfb3SApril Chin        )
4377c2fbfb3SApril Chin    fi
4387c2fbfb3SApril Chin}
4397c2fbfb3SApril Chin
4407c2fbfb3SApril Chinfunction test_builtin_getconf
4417c2fbfb3SApril Chin{
4427c2fbfb3SApril Chin(
4437c2fbfb3SApril Chin    print "# testing getconf builtin..."
4447c2fbfb3SApril Chin    set +o errexit
4457c2fbfb3SApril Chin    export PATH=/bin:/usr/bin
4467c2fbfb3SApril Chin    for lang in ${TEST_LANG} ; do
4477c2fbfb3SApril Chin        (
4487c2fbfb3SApril Chin	    printf "## testing LANG=%s\n" "${lang}"
4497c2fbfb3SApril Chin            export LC_ALL="${lang}" LANG="${lang}"
4507c2fbfb3SApril Chin            ${SHELL} -c '/usr/bin/getconf -a |
4517c2fbfb3SApril Chin                         while read i ; do
4527c2fbfb3SApril Chin                         t="${i%:*}" ; a="$(getconf "$t" 2>/dev/null)" ;
4537c2fbfb3SApril Chin                         b="$(/usr/bin/getconf "$t" 2>/dev/null)" ; [ "$a" != "$b" ] && print "# |$t|:|$a| != |$b|" ;
4547c2fbfb3SApril Chin                         done'
4557c2fbfb3SApril Chin        )
4567c2fbfb3SApril Chin    done
4577c2fbfb3SApril Chin    print "# testing getconf done."
4587c2fbfb3SApril Chin)
4597c2fbfb3SApril Chin}
4607c2fbfb3SApril Chin
4617c2fbfb3SApril Chinfunction test_shell
4627c2fbfb3SApril Chin{
4637c2fbfb3SApril Chin    set -o errexit
4647c2fbfb3SApril Chin    set -o xtrace
4657c2fbfb3SApril Chin
466*34f9b3eeSRoland Mainz    ulimit -s 65536 # need larger stack on 64bit SPARC to pass all tests
467*34f9b3eeSRoland Mainz
4687c2fbfb3SApril Chin    export SHELL="$(ls -1 $PWD/arch/*/src/cmd/ksh93/ksh)"
4697c2fbfb3SApril Chin    export LD_LIBRARY_PATH="$(ls -1ad $PWD/arch/*/lib):${LD_LIBRARY_PATH}"
4707c2fbfb3SApril Chin    export LD_LIBRARY_PATH_32="$(ls -1ad $PWD/arch/*/lib):${LD_LIBRARY_PATH_32}"
4717c2fbfb3SApril Chin    export LD_LIBRARY_PATH_64="$(ls -1ad $PWD/arch/*/lib):${LD_LIBRARY_PATH_64}"
4727c2fbfb3SApril Chin    printf "## SHELL is |%s|\n" "${SHELL}"
4737c2fbfb3SApril Chin    printf "## LD_LIBRARY_PATH is |%s|\n" "${LD_LIBRARY_PATH}"
4747c2fbfb3SApril Chin
4757c2fbfb3SApril Chin    [[ ! -f "${SHELL}" ]] && fatal_error "test_shell: |${SHELL}| is not a file."
4767c2fbfb3SApril Chin    [[ ! -x "${SHELL}" ]] && fatal_error "test_shell: |${SHELL}| is not executable."
4777c2fbfb3SApril Chin
478*34f9b3eeSRoland Mainz    [[ "${TEST_LANG}" == "" ]] && TEST_LANG="C ja_JP.UTF-8"
4797c2fbfb3SApril Chin
4807c2fbfb3SApril Chin    case "${buildmode}" in
4817c2fbfb3SApril Chin            testshell.bcheck*)
4827c2fbfb3SApril Chin                for lang in ${TEST_LANG} ; do
4837c2fbfb3SApril Chin                    (
4847c2fbfb3SApril Chin                        export LC_ALL="${lang}" LANG="${lang}"
4857c2fbfb3SApril Chin                        for i in ./src/cmd/ksh93/tests/*.sh ; do
4867c2fbfb3SApril Chin                            bc_logfile="$(basename "$i").$$.bcheck"
4877c2fbfb3SApril Chin                            rm -f "${bc_logfile}"
4887c2fbfb3SApril Chin                            /opt/SUNWspro/bin/bcheck -q -access -o "${bc_logfile}" ${SHELL} ./src/cmd/ksh93/tests/shtests \
4897c2fbfb3SApril Chin                                LD_LIBRARY_PATH_64="$LD_LIBRARY_PATH_64" \
4907c2fbfb3SApril Chin                                LD_LIBRARY_PATH="$LD_LIBRARY_PATH" \
4917c2fbfb3SApril Chin                                LD_LIBRARY_PATH_32="$LD_LIBRARY_PATH_32"\
4927c2fbfb3SApril Chin                                LC_ALL="${lang}" LANG="${lang}" \
4937c2fbfb3SApril Chin                                VMDEBUG=a \
4947c2fbfb3SApril Chin                                "$i"
4957c2fbfb3SApril Chin                            cat "${bc_logfile}"
4967c2fbfb3SApril Chin                        done
4977c2fbfb3SApril Chin                    )
4987c2fbfb3SApril Chin                done
4997c2fbfb3SApril Chin                ;;
5007c2fbfb3SApril Chin            testshell.builtin.getconf)
5017c2fbfb3SApril Chin                test_builtin_getconf
5027c2fbfb3SApril Chin                ;;
5037c2fbfb3SApril Chin            testshell)
5047c2fbfb3SApril Chin                for lang in ${TEST_LANG} ; do
5057c2fbfb3SApril Chin                    (
5067c2fbfb3SApril Chin                        export LC_ALL="${lang}" LANG="${lang}"
5077c2fbfb3SApril Chin                        for i in ./src/cmd/ksh93/tests/*.sh ; do
5087c2fbfb3SApril Chin                            ${SHELL} ./src/cmd/ksh93/tests/shtests -a \
5097c2fbfb3SApril Chin                                LD_LIBRARY_PATH_64="$LD_LIBRARY_PATH_64" \
5107c2fbfb3SApril Chin                                LD_LIBRARY_PATH="$LD_LIBRARY_PATH" \
5117c2fbfb3SApril Chin                                LD_LIBRARY_PATH_32="$LD_LIBRARY_PATH_32" \
5127c2fbfb3SApril Chin                                LC_ALL="${lang}" LANG="${lang}" \
5137c2fbfb3SApril Chin                                VMDEBUG=a \
5147c2fbfb3SApril Chin				SHCOMP=$PWD/arch/*/bin/shcomp \
5157c2fbfb3SApril Chin                                "$i"
5167c2fbfb3SApril Chin                        done
5177c2fbfb3SApril Chin                    )
5187c2fbfb3SApril Chin                done
5197c2fbfb3SApril Chin                test_builtin_getconf
5207c2fbfb3SApril Chin                ;;
5217c2fbfb3SApril Chin    esac
5227c2fbfb3SApril Chin}
5237c2fbfb3SApril Chin
5247c2fbfb3SApril Chin# main
5257c2fbfb3SApril Chincase "${buildmode}" in
5267c2fbfb3SApril Chin        build.*) build_shell ;;
5277c2fbfb3SApril Chin        testshell*)  test_shell  ;;
5287c2fbfb3SApril Chin        *) fatal_error "Illegal build mode \"${buildmode}\"." ;;
5297c2fbfb3SApril Chinesac
5307c2fbfb3SApril Chin# EOF.
531