#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
#
#
# buildksh93.sh - ast-ksh/ast-open standalone build script for the
# OpenSolaris ksh93-integration project
#
# ksh93u sources can be downloaded like this from the AT&T site:
# wget --http-user="I accept www.opensource.org/licenses/cpl" --http-passwd="." 'http://www2.research.att.com/~gsf/download/tgz/INIT.2011-02-08.tgz'
# wget --http-user="I accept www.opensource.org/licenses/cpl" --http-passwd="." 'http://www2.research.att.com/~gsf/download/tgz/ast-ksh.2011-02-08.tgz'
# wget --http-user="I accept www.opensource.org/licenses/cpl" --http-passwd="." 'http://www2.research.att.com/~gsf/download/tgz/ast-open.2011-02-08.tgz'
function fatal_error
{
print -u2 "${progname}: $*"
exit 1
}
set -o errexit
set -o xtrace
typeset buildmode="$1"
if [[ "${buildmode}" == '' ]] ; then
fatal_error 'buildmode required.'
fi
# Make sure we use the C locale during building to avoid any unintended
# side-effects
export LANG='C'
export LC_ALL="$LANG" LC_MONETARY="$LANG" LC_NUMERIC="$LANG" LC_MESSAGES="$LANG" LC_COLLATE="$LANG" LC_CTYPE="$LANG"
# our version of ksh93 correctly).
fatal_error 'XPG6/4 packages (SUNWxcu6,SUNWxcu4) not installed.'
fi
fi
function print_solaris_builtin_header
{
# Make sure to use \\ instead of \ for continuations
cat <<ENDOFTEXT
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
*/
#ifndef _SOLARIS_KSH_CMDLIST_H
#define _SOLARIS_KSH_CMDLIST_H
#ifdef __cplusplus
extern "C" {
#endif
/*
* List builtins for Solaris.
* The list here is partially autogenerated and partially hand-picked
* based on compatibility with the native Solaris versions of these
* tools
*/
/*
* Commands which are 100% compatible with native Solaris versions (/bin is
* a softlink to ./usr/bin, ksh93 takes care about the lookup)
*/
#define BINCMDLIST(f) \\
{ "/bin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
#define USRBINCMDLIST(f) \\
{ "/usr/bin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
#define SBINCMDLIST(f) \\
{ "/sbin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
#define SUSRBINCMDLIST(f) \\
{ "/usr/sbin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
/* POSIX compatible commands */
#define XPG6CMDLIST(f) \\
{ "/usr/xpg6/bin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
#define XPG4CMDLIST(f) \\
{ "/usr/xpg4/bin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
#ifdef SHOPT_USR_GNU_BIN_BUILTINS
/* GNU coreutils compatible commands */
#define GNUCMDLIST(f) \\
{ "/usr/gnu/bin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
#else
#define GNUCMDLIST(f)
#endif
/*
* Make all ksh93 builtins accessible when /usr/ast/bin was added to
* /usr/xpg6/bin:/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:/bin:/opt/SUNWspro/bin
*/
#define ASTCMDLIST(f) \\
{ "/usr/ast/bin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
/* undo ast_map.h #defines to avoid collision */
#undef basename
#undef dirname
#undef mktemp
/* Generated data, do not edit. */
ASTCMDLIST(basename)
GNUCMDLIST(basename)
XPG4CMDLIST(basename)
ASTCMDLIST(cat)
BINCMDLIST(cat)
ASTCMDLIST(chgrp)
// XPG4CMDLIST(chgrp)
ASTCMDLIST(chmod)
ASTCMDLIST(chown)
// XPG4CMDLIST(chown)
BINCMDLIST(chown)
ASTCMDLIST(cksum)
BINCMDLIST(cksum)
GNUCMDLIST(cksum)
ASTCMDLIST(cmp)
BINCMDLIST(cmp)
ASTCMDLIST(comm)
BINCMDLIST(comm)
GNUCMDLIST(comm)
ASTCMDLIST(cp)
// XPG4CMDLIST(cp)
ASTCMDLIST(cut)
BINCMDLIST(cut)
GNUCMDLIST(cut)
ASTCMDLIST(date)
// XPG4CMDLIST(date)
ASTCMDLIST(dirname)
BINCMDLIST(dirname)
GNUCMDLIST(dirname)
// ASTCMDLIST(egrep)
// XPG4CMDLIST(egrep)
ASTCMDLIST(expr)
GNUCMDLIST(expr)
XPG6CMDLIST(expr)
ASTCMDLIST(fds)
// ASTCMDLIST(fgrep)
// XPG4CMDLIST(fgrep)
ASTCMDLIST(fmt)
ASTCMDLIST(fold)
BINCMDLIST(fold)
GNUCMDLIST(fold)
// ASTCMDLIST(grep)
// XPG4CMDLIST(grep)
ASTCMDLIST(head)
BINCMDLIST(head)
ASTCMDLIST(id)
XPG4CMDLIST(id)
ASTCMDLIST(join)
BINCMDLIST(join)
GNUCMDLIST(join)
ASTCMDLIST(ln)
// XPG4CMDLIST(ln)
ASTCMDLIST(logname)
BINCMDLIST(logname)
GNUCMDLIST(logname)
ASTCMDLIST(md5sum)
ASTCMDLIST(mkdir)
BINCMDLIST(mkdir)
GNUCMDLIST(mkdir)
ASTCMDLIST(mkfifo)
BINCMDLIST(mkfifo)
GNUCMDLIST(mkfifo)
ASTCMDLIST(mktemp)
BINCMDLIST(mktemp)
GNUCMDLIST(mktemp)
ASTCMDLIST(mv)
// XPG4CMDLIST(mv)
ASTCMDLIST(paste)
BINCMDLIST(paste)
GNUCMDLIST(paste)
ASTCMDLIST(pathchk)
BINCMDLIST(pathchk)
GNUCMDLIST(pathchk)
// ASTCMDLIST(readlink)
ASTCMDLIST(rev)
BINCMDLIST(rev)
BINCMDLIST(rm)
ASTCMDLIST(rm)
XPG4CMDLIST(rm)
ASTCMDLIST(rmdir)
BINCMDLIST(rmdir)
GNUCMDLIST(rmdir)
GNUCMDLIST(sleep)
ASTCMDLIST(stty)
// XPG4CMDLIST(stty)
ASTCMDLIST(sum)
BINCMDLIST(sum)
ASTCMDLIST(sync)
BINCMDLIST(sync)
GNUCMDLIST(sync)
SBINCMDLIST(sync)
SUSRBINCMDLIST(sync)
ASTCMDLIST(tail)
BINCMDLIST(tail)
XPG4CMDLIST(tail)
ASTCMDLIST(tee)
BINCMDLIST(tee)
GNUCMDLIST(tee)
ASTCMDLIST(tty)
BINCMDLIST(tty)
GNUCMDLIST(tty)
ASTCMDLIST(uname)
ASTCMDLIST(uniq)
BINCMDLIST(uniq)
GNUCMDLIST(uniq)
ASTCMDLIST(wc)
BINCMDLIST(wc)
GNUCMDLIST(wc)
// ASTCMDLIST(xgrep)
// BINCMDLIST(xgrep)
/* Mandatory for ksh93 test suite and AST scripts */
BINCMDLIST(getconf)
#ifdef __cplusplus
}
#endif
#endif /* !_SOLARIS_KSH_CMDLIST_H */
ENDOFTEXT
return 0
}
function print_gnulinux_builtin_header
{
# Make sure to use \\ instead of \ for continuations
cat <<ENDOFTEXT
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1982-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.opensource.org/licenses/cpl1.0.txt *
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Roland Mainz <roland.mainz@nrubsig.org> *
* *
***********************************************************************/
#ifndef _GNULINUX_KSH_CMDLIST_H
#define _GNULINUX_KSH_CMDLIST_H
#ifdef __cplusplus
extern "C" {
#endif
/*
* List builtins for Linux.
* The list here is partially autogenerated and partially hand-picked
* based on compatibility with the native GNU coreutils versions of
* these tools
*/
/* GNU coreutils compatible commands.
* Be careful, some are in /bin while others are in /usr/bin
*/
#define ASTCMDLIST(f) { "/usr/ast/bin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
#define BINCMDLIST(f) { "/bin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
#define USRBINCMDLIST(f) { "/usr/bin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
/* undo ast_map.h #defines to avoid collision */
#undef basename
#undef dirname
#undef mktemp
/* Generated data, do not edit. */
USRBINCMDLIST(basename)
USRBINCMDLIST(cksum)
USRBINCMDLIST(comm)
USRBINCMDLIST(cut)
USRBINCMDLIST(dirname)
USRBINCMDLIST(expr)
USRBINCMDLIST(fold)
USRBINCMDLIST(join)
USRBINCMDLIST(logname)
BINCMDLIST(mkdir)
USRBINCMDLIST(mkfifo)
BINCMDLIST(mktemp)
USRBINCMDLIST(paste)
USRBINCMDLIST(pathchk)
USRBINCMDLIST(rev)
BINCMDLIST(rmdir)
BINCMDLIST(sleep)
BINCMDLIST(sync)
USRBINCMDLIST(tee)
USRBINCMDLIST(tty)
USRBINCMDLIST(uniq)
USRBINCMDLIST(wc)
/* Mandatory for ksh93 test suite and AST scripts */
USRBINCMDLIST(getconf)
ASTCMDLIST(basename)
ASTCMDLIST(cat)
ASTCMDLIST(chgrp)
ASTCMDLIST(chmod)
ASTCMDLIST(chown)
ASTCMDLIST(cksum)
ASTCMDLIST(cmp)
ASTCMDLIST(comm)
ASTCMDLIST(cp)
ASTCMDLIST(cut)
ASTCMDLIST(date)
ASTCMDLIST(dirname)
// ASTCMDLIST(egrep)
ASTCMDLIST(expr)
ASTCMDLIST(fds)
// ASTCMDLIST(fgrep)
ASTCMDLIST(fmt)
ASTCMDLIST(fold)
// ASTCMDLIST(grep)
ASTCMDLIST(head)
ASTCMDLIST(id)
ASTCMDLIST(join)
ASTCMDLIST(ln)
ASTCMDLIST(logname)
ASTCMDLIST(md5sum)
ASTCMDLIST(mkdir)
ASTCMDLIST(mkfifo)
ASTCMDLIST(mktemp)
ASTCMDLIST(mv)
ASTCMDLIST(paste)
ASTCMDLIST(pathchk)
// ASTCMDLIST(readlink)
ASTCMDLIST(rev)
ASTCMDLIST(rm)
ASTCMDLIST(rmdir)
ASTCMDLIST(stty)
ASTCMDLIST(sum)
ASTCMDLIST(sync)
ASTCMDLIST(tail)
ASTCMDLIST(tee)
ASTCMDLIST(tty)
ASTCMDLIST(uname)
ASTCMDLIST(uniq)
ASTCMDLIST(wc)
// ASTCMDLIST(xgrep)
#ifdef __cplusplus
}
#endif
#endif /* !_GNULINUX_KSH_CMDLIST_H */
ENDOFTEXT
return 0
}
function build_shell
{
set -o errexit
set -o xtrace
*.linux.*)
print_gnulinux_builtin_header >"${gnulinux_builtin_header}"
*.opt.*)
bgcc_optdebug_flags='-O2'
;;
*.debug.*)
bgcc_optdebug_flags='-g -ggdb'
;;
*)
fatal_error "build_shell: Illegal optimiser flag \"${buildmode}\"."
;;
esac
# ksh93+AST config flags
bast_flags="-DSHOPT_CMDLIB_BLTIN=0 -DSH_CMDLIB_DIR=\\\"/usr/ast/bin\\\" -DSHOPT_CMDLIB_HDR=\\\"${gnulinux_builtin_header}\\\" -DSHOPT_SYSRC -D_map_libc=1"
# gcc flags
bgcc99='gcc -std=gnu99 -fstrict-aliasing -Wstrict-aliasing'
bgcc_ccflags="${bon_flags} ${bast_flags} ${bgcc_optdebug_flags}"
# Linux i386
;;
;;
*)
fatal_error "build_shell: Illegal Linux type/compiler build mode \"${buildmode}\"."
;;
esac
;;
*.solaris.*)
# Notes:
# asking the project leads at
# These flags all have a purpose, even if they look
#
# 2. We use -KPIC here since -Kpic is too small on 64bit sparc and
# on 32bit it's close to the barrier so we use it for both 32bit and
# 64bit to avoid later suprises when people update libast in the
# future
#
# 3. "-D_map_libc=1" is needed to force map.c to add a "_ast_" prefix to all
#
# to enable it if /etc/ksh.kshrc or /etc/bash.bashrc are available on the
# build machine).
#
# 5. -D_lib_socket=1 -lsocket -lnsl" was added to make sure ksh93 is compiled
# with networking support enabled, the current AST build infratructure has
# problems with detecting networking support in Solaris.
#
# 6. "-xc99=%all -D_XOPEN_SOURCE=600 -D__EXTENSIONS__=1" is used to force
# the compiler into C99 mode. Otherwise ksh93 will be much slower and lacks
# lots of arithmethic functions.
#
# build system.
#
# 8. "-xpagesize_stack=64K is used on SPARC to enhance the performace
#
# 9. -DSHOPT_CMDLIB_BLTIN=0 -DSH_CMDLIB_DIR=\\\"/usr/ast/bin\\\" -DSHOPT_CMDLIB_HDR=\\\"/home/test001/ksh93/ast_ksh_20070322/solaris_cmdlist.h\\\"
# is used to bind all ksh93 builtins to a "virtual" directory
# enabled by default to those defined by PSARC 2006/550
print_solaris_builtin_header >"${solaris_builtin_header}"
bon_flags='-D_TS_ERRNO -D_REENTRANT'
# ksh93+AST config flags
bast_flags="-DSHOPT_CMDLIB_BLTIN=0 -DSH_CMDLIB_DIR=\\\"/usr/ast/bin\\\" -DSHOPT_CMDLIB_HDR=\\\"${solaris_builtin_header}\\\" -DSHOPT_SYSRC -D_map_libc=1"
*.opt.*)
bsuncc_optdebug_flags='-xO4 -xalias_level=std'
bgcc_optdebug_flags='-O2'
;;
*.debug.*)
bsuncc_optdebug_flags='-g -xs'
bgcc_optdebug_flags='-g'
;;
*)
fatal_error "build_shell: Illegal optimiser flag \"${buildmode}\"."
;;
esac
# Sun Studio flags
bsuncc_app_ccflags_sparc='-xpagesize_stack=64K' # use bsuncc_app_ccflags_sparc only for final executables
bsuncc_ccflags="${bon_flags} -KPIC ${bsuncc_optdebug_flags} -xspace -Xa -xstrconst -z combreloc -xildoff -xcsi -errtags=yes ${bast_flags} -D_lib_socket=1 -lsocket -lnsl"
# gcc flags
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'
bgcc_ccflags="${bon_flags} ${bgcc_optdebug_flags} ${bgcc_warnflags} ${bast_flags} -D_lib_socket=1 -lsocket -lnsl"
# for -m32/-m64 flags see usr/src/Makefile.master, makefile symbols *_XARCH/co.
*.i386.32bit.suncc*) HOSTTYPE='sol11.i386' CC="${bsunc99} -m32" cc_sharedlib='-G' CCFLAGS="${bsuncc_ccflags}" ;;
*.i386.64bit.suncc*) HOSTTYPE='sol11.i386' CC="${bsunc99} -m64 -KPIC" cc_sharedlib='-G' CCFLAGS="${bsuncc_ccflags}" ;;
*.sparc.32bit.suncc*) HOSTTYPE='sol11.sun4' CC="${bsunc99} -m32" cc_sharedlib='-G' CCFLAGS="${bsuncc_ccflags}" bsuncc_app_ccflags="${bsuncc_app_ccflags_sparc}" ;;
*.sparc.64bit.suncc*) HOSTTYPE='sol11.sun4' CC="${bsunc99} -m64 -dalign -KPIC" cc_sharedlib='-G' CCFLAGS="${bsuncc_ccflags}" bsuncc_app_ccflags="${bsuncc_app_ccflags_sparc}" ;;
*.i386.32bit.gcc*) HOSTTYPE='sol11.i386' CC="${bgcc99} -fPIC" cc_sharedlib='-shared' CCFLAGS="${bgcc_ccflags}" ;;
*.i386.64bit.gcc*) HOSTTYPE='sol11.i386' CC="${bgcc99} -m64 -mtune=opteron -Ui386 -U__i386 -fPIC" cc_sharedlib='-shared' CCFLAGS="${bgcc_ccflags}" ;;
*.sparc.32bit.gcc*) HOSTTYPE='sol11.sun4' CC="${bgcc99} -m32 -mcpu=v8 -fPIC" cc_sharedlib='-shared' CCFLAGS="${bgcc_ccflags}" ;;
*.sparc.64bit.gcc*) HOSTTYPE='sol11.sun4' CC="${bgcc99} -m64 -mcpu=v9 -fPIC" cc_sharedlib='-shared' CCFLAGS="${bgcc_ccflags}" ;;
*.s390.32bit.gcc*) HOSTTYPE='sol11.s390' CC="${bgcc99} -m32 -fPIC" cc_sharedlib='-shared' CCFLAGS="${bgcc_ccflags}" ;;
*.s390.64bit.gcc*) HOSTTYPE='sol11.s390' CC="${bgcc99} -m64 -fPIC" cc_sharedlib='-shared' CCFLAGS="${bgcc_ccflags}" ;;
*)
fatal_error "build_shell: Illegal Solaris type/compiler build mode \"${buildmode}\"."
;;
esac
;;
*)
fatal_error "Illegal OS build mode \"${buildmode}\"."
;;
esac
# some prechecks
# build ksh93
SHELL='/bin/ksh' /bin/ksh ./bin/package make PACKAGE_OPTIONS='map-libc' CCFLAGS="${CCFLAGS}" CC="${CC}" HOSTTYPE="${HOSTTYPE}" SHELL='/bin/ksh'
root="${PWD}/arch/${HOSTTYPE}"
if [[ -f "${root}/lib/libcoshell-g.a" ]] then link_libcoshell='coshell-g' ; else link_libcoshell='coshell' ; fi
if [[ -f "${root}/lib/libshell-g.a" ]] then link_libshell='shell-g' ; else link_libshell='shell' ; fi
# libcmd causes some trouble since there is a squatter in solaris
# This has been fixed in Solaris 11/B48 but may require adjustments
# for older Solaris releases
'libshell')
vers=1
link="-L${root}/lib/ -l${link_libcmd} -l${link_libcoshell} -l${link_libsum} -l${link_libdll} -l${link_libast} -lm"
;;
'libdll')
vers=1
link='-ldl'
;;
'libast')
vers=1
link='-lm'
;;
*)
vers=1
link="-L${root}/lib/ -l${link_libast} -lm"
;;
esac
(
cd "${root}/${base}"
${CC} ${cc_sharedlib} ${CCFLAGS} -Bdirect -Wl,-zallextract -Wl,-zmuldefs -o "${root}/lib/${lib}.so.${vers}" "${lib_a}" ${link}
else
${CC} ${cc_sharedlib} ${CCFLAGS} -Wl,--whole-archive -Wl,-zmuldefs "${lib_a}" -Wl,--no-whole-archive -o "${root}/lib/${lib}.so.${vers}" ${link}
fi
#rm ${lib}.a
mv "${lib_a}" "disabled_${lib_a}_"
cd "${root}/lib"
)
done
(
cd "${root}/${base}"
rm -f \
"${root}/lib/libast.a" "${root}/lib/libast-g.a"
${CC} ${CCFLAGS} ${bsuncc_app_ccflags} -L${root}/lib/ -Bdirect -o ksh pmain.o -lshell -Bstatic -l${link_libcmd} -Bdynamic -lsum -lcoshell -ldll -last -lm -lmd -lsecdb
else
${CC} ${CCFLAGS} ${bsuncc_app_ccflags} -L${root}/lib/ -o ksh pmain.o -lshell -lcmd -lcoshell -lsum -ldll -last -lm
fi
file 'ksh'
file 'shcomp'
export LD_LIBRARY_PATH="${root}/lib:${LD_LIBRARY_PATH}"
export LD_LIBRARY_PATH_32="${root}/lib:${LD_LIBRARY_PATH_32}"
export LD_LIBRARY_PATH_64="${root}/lib:${LD_LIBRARY_PATH_64}"
ldd 'ksh'
)
fi
return 0
}
function test_builtin_getconf
{
(
print '# testing getconf builtin...'
set +o errexit
(
while read i ; do
done'
)
done
print '# testing getconf done.'
)
return 0
}
function test_shell
{
set -o errexit
set -o xtrace
ulimit -s 65536 # need larger stack on 64bit SPARC to pass all tests
${SHELL} -c 'printf "ksh version is %s\n" "${.sh.version}"'
(
rm -f "${bc_logfile}"
"$i"
cat "${bc_logfile}"
done
)
done
;;
;;
'testshell')
(
"$i"
done
)
done
;;
esac
return 0
}
# main
case "${buildmode}" in
build.*) build_shell ;;
testshell*) test_shell ;;
*) fatal_error "Illegal build mode \"${buildmode}\"." ;;
esac
exit $?
# EOF.