2 # (note we use "/bin/ksh -p" for Linux/pdksh support in this script)
7 # The contents of this file are subject to the terms of the
8 # Common Development and Distribution License (the "License").
9 # You may not use this file except in compliance with the License.
11 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
12 # or http://www.opensolaris.org/os/licensing.
13 # See the License for the specific language governing permissions
14 # and limitations under the License.
16 # When distributing Covered Code, include this CDDL HEADER in each
17 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
18 # If applicable, add the following below this CDDL HEADER, with the
19 # fields enclosed by brackets "[]" replaced with your own identifying
20 # information: Portions Copyright [yyyy] [name of copyright owner]
26 # Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
30 # buildksh93.sh - ast-ksh standalone build script for the
31 # OpenSolaris ksh93-integration project
34 # ksh93t sources can be downloaded like this from the AT&T site:
35 # wget --http-user="I accept www.opensource.org/licenses/cpl" --http-passwd="." 'http://www.research.att.com/~gsf/download/tgz/INIT.2010-03-09.tgz'
36 # wget --http-user="I accept www.opensource.org/licenses/cpl" --http-passwd="." 'http://www.research.att.com/~gsf/download/tgz/ast-ksh.2010-03-09.tgz'
40 print
-u2 "${progname}: $*"
47 typeset progname
="$(basename "${0}")"
48 typeset buildmode
="$1"
50 if [[ "${buildmode}" == "" ]] ; then
51 fatal_error
"buildmode required."
54 # Make sure we use the C locale during building to avoid any unintended
57 export LC_ALL
=$LANG LC_MONETARY
=$LANG LC_NUMERIC
=$LANG LC_MESSAGES
=$LANG LC_COLLATE
=$LANG LC_CTYPE
=$LANG
58 # Make sure the POSIX/XPG6 tools are in front of /usr/bin (/bin is needed for Linux after /usr/bin)
59 export PATH
=/usr
/xpg
6/bin
:/usr
/xpg
4/bin
:/usr
/ccs
/bin
:/usr
/bin
:/bin
:/opt
/SUNWspro
/bin
61 # Make sure the POSIX/XPG6 packages are installed (mandatory for building
62 # our version of ksh93 correctly).
63 if [[ "$(uname -s)" == "SunOS" ]] ; then
64 if [[ ! -x "/usr/xpg6/bin/tr" ]] ; then
65 fatal_error
"XPG6/4 packages (SUNWxcu6,SUNWxcu4) not installed."
69 function print_solaris_builtin_header
71 # Make sure to use \\ instead of \ for continuations
76 * The contents of this file are subject to the terms of the
77 * Common Development and Distribution License (the "License").
78 * You may not use this file except in compliance with the License.
80 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
81 * or http://www.opensolaris.org/os/licensing.
82 * See the License for the specific language governing permissions
83 * and limitations under the License.
85 * When distributing Covered Code, include this CDDL HEADER in each
86 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
87 * If applicable, add the following below this CDDL HEADER, with the
88 * fields enclosed by brackets "[]" replaced with your own identifying
89 * information: Portions Copyright [yyyy] [name of copyright owner]
95 * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
98 #ifndef _SOLARIS_KSH_CMDLIST_H
99 #define _SOLARIS_KSH_CMDLIST_H
106 * List builtins for Solaris.
107 * The list here is partially autogenerated and partially hand-picked
108 * based on compatibility with the native Solaris versions of these
113 * Commands which are 100% compatible with native Solaris versions (/bin is
114 * a softlink to ./usr/bin, ksh93 takes care about the lookup)
116 #define BINCMDLIST(f) \\
117 { "/bin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
118 #define USRBINCMDLIST(f) \\
119 { "/usr/bin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
120 #define SBINCMDLIST(f) \\
121 { "/sbin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
122 #define SUSRBINCMDLIST(f) \\
123 { "/usr/sbin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
124 /* POSIX compatible commands */
125 #define XPG6CMDLIST(f) \\
126 { "/usr/xpg6/bin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
127 #define XPG4CMDLIST(f) \\
128 { "/usr/xpg4/bin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
129 #ifdef SHOPT_USR_GNU_BIN_BUILTINS
130 /* GNU coreutils compatible commands */
131 #define GNUCMDLIST(f) \\
132 { "/usr/gnu/bin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
134 #define GNUCMDLIST(f)
137 * Make all ksh93 builtins accessible when /usr/ast/bin was added to
138 * /usr/xpg6/bin:/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:/bin:/opt/SUNWspro/bin
140 #define ASTCMDLIST(f) \\
141 { "/usr/ast/bin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
143 /* undo ast_map.h #defines to avoid collision */
148 /* Generated data, do not edit. */
151 XPG4CMDLIST(basename)
155 // XPG4CMDLIST(chgrp)
158 // XPG4CMDLIST(chown)
179 // XPG4CMDLIST(egrep)
185 // XPG4CMDLIST(fgrep)
222 // ASTCMDLIST(readlink)
259 /* Mandatory for ksh93 test suite and AST scripts */
265 #endif /* !_SOLARIS_KSH_CMDLIST_H */
275 # OS.cputype.XXbit.compiler
276 case "${buildmode}" in
278 # ksh93+AST config flags
279 bast_flags
="-DSHOPT_CMDLIB_BLTIN=0 -DSH_CMDLIB_DIR=\\\"/usr/ast/bin\\\" -DSHOPT_SYSRC -D_map_libc=1"
282 bgcc99
="gcc -std=gnu99 "
283 bgcc_ccflags
="${bon_flags} ${bast_flags} -g"
285 case "${buildmode}" in
287 *.i386.32bit.gcc
*) HOSTTYPE
="linux.i386" CC
="${bgcc99} -fPIC" cc_sharedlib
="-shared" CCFLAGS
="${bgcc_ccflags}"
290 fatal_error
"build_shell: Illegal Linux type/compiler build mode \"${buildmode}\"."
296 # 1. Do not remove/modify these flags or their order before either
297 # asking the project leads at
298 # http://www.opensolaris.org/os/project/ksh93-integration/
299 # These flags all have a purpose, even if they look
300 # weird/redundant/etc. at the first look.
302 # 2. We use -KPIC here since -Kpic is too small on 64bit sparc and
303 # on 32bit it's close to the barrier so we use it for both 32bit and
304 # 64bit to avoid later suprises when people update libast in the
307 # 3. "-D_map_libc=1" is needed to force map.c to add a "_ast_" prefix to all
308 # AST symbol names which may otherwise collide with Solaris/Linux libc
310 # 4. "-DSHOPT_SYSRC" enables /etc/ksh.kshrc support (AST default is currently
311 # to enable it if /etc/ksh.kshrc or /etc/bash.bashrc are available on the
314 # 5. -D_lib_socket=1 -lsocket -lnsl" was added to make sure ksh93 is compiled
315 # with networking support enabled, the current AST build infratructure has
316 # problems with detecting networking support in Solaris.
318 # 6. "-xc99=%all -D_XOPEN_SOURCE=600 -D__EXTENSIONS__=1" is used to force
319 # the compiler into C99 mode. Otherwise ksh93 will be much slower and lacks
320 # lots of arithmethic functions.
322 # 7. "-D_TS_ERRNO -D_REENTRANT" are flags taken from the default OS/Net
325 # 8. "-xpagesize_stack=64K is used on SPARC to enhance the performace
327 # 9. -DSHOPT_CMDLIB_BLTIN=0 -DSH_CMDLIB_DIR=\\\"/usr/ast/bin\\\" -DSHOPT_CMDLIB_HDR=\\\"/home/test001/ksh93/ast_ksh_20070322/solaris_cmdlist.h\\\"
328 # is used to bind all ksh93 builtins to a "virtual" directory
329 # called "/usr/ast/bin/" and to adjust the list of builtins
330 # enabled by default to those defined by PSARC 2006/550
332 solaris_builtin_header
="${PWD}/tmp_solaris_builtin_header.h"
333 print_solaris_builtin_header
>"${solaris_builtin_header}"
336 bon_flags
="-D_TS_ERRNO -D_REENTRANT"
338 # ksh93+AST config flags
339 bast_flags
="-DSHOPT_CMDLIB_BLTIN=0 -DSH_CMDLIB_DIR=\\\"/usr/ast/bin\\\" -DSHOPT_CMDLIB_HDR=\\\"${solaris_builtin_header}\\\" -DSHOPT_SYSRC -D_map_libc=1"
342 bsunc99
="/opt/SUNWspro/bin/cc -xc99=%all -D_XOPEN_SOURCE=600 -D__EXTENSIONS__=1"
343 bsuncc_app_ccflags_sparc
="-xpagesize_stack=64K" # use bsuncc_app_ccflags_sparc only for final executables
344 bsuncc_ccflags
="${bon_flags} -KPIC -g -xs -xspace -Xa -xstrconst -z combreloc -xildoff -xcsi -errtags=yes ${bast_flags} -D_lib_socket=1 -lsocket -lnsl"
347 bgcc99
="/usr/sfw/bin/gcc -std=gnu99 -D_XOPEN_SOURCE=600 -D__EXTENSIONS__=1"
348 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"
349 bgcc_ccflags
="${bon_flags} ${bgcc_warnflags} ${bast_flags} -D_lib_socket=1 -lsocket -lnsl"
351 case "${buildmode}" in
352 # for -m32/-m64 flags see usr/src/Makefile.master, makefile symbols *_XARCH/co.
353 *.i386.32bit.suncc
*) HOSTTYPE
="sol11.i386" CC
="${bsunc99} -m32" cc_sharedlib
="-G" CCFLAGS
="${bsuncc_ccflags}" ;;
354 *.i386.64bit.suncc
*) HOSTTYPE
="sol11.i386" CC
="${bsunc99} -m64 -KPIC" cc_sharedlib
="-G" CCFLAGS
="${bsuncc_ccflags}" ;;
355 *.sparc
.32bit.suncc
*) HOSTTYPE
="sol11.sun4" CC
="${bsunc99} -m32" cc_sharedlib="-G" CCFLAGS="${bsuncc_ccflags}" bsuncc_app_ccflags="${bsuncc_app_ccflags_sparc}" ;;
356 *.sparc
.64bit.suncc
*) HOSTTYPE
="sol11.sun4" CC
="${bsunc99} -m64 -dalign -KPIC" cc_sharedlib="-G" CCFLAGS="${bsuncc_ccflags}" bsuncc_app_ccflags="${bsuncc_app_ccflags_sparc}" ;;
358 *.i386.32bit.gcc
*) HOSTTYPE
="sol11.i386" CC
="${bgcc99} -fPIC" cc_sharedlib
="-shared" CCFLAGS
="${bgcc_ccflags}" ;;
359 *.i386.64bit.gcc
*) HOSTTYPE
="sol11.i386" CC
="${bgcc99} -m64 -mtune=opteron -Ui386 -U__i386 -fPIC" cc_sharedlib
="-shared" CCFLAGS
="${bgcc_ccflags}" ;;
360 *.sparc
.32bit.gcc
*) HOSTTYPE
="sol11.sun4" CC
="${bgcc99} -m32 -mcpu=v8 -fPIC" cc_sharedlib
="-shared" CCFLAGS
="${bgcc_ccflags}" ;;
361 *.sparc
.64bit.gcc
*) HOSTTYPE
="sol11.sun4" CC
="${bgcc99} -m64 -mcpu=v9 -fPIC" cc_sharedlib
="-shared" CCFLAGS
="${bgcc_ccflags}" ;;
362 *.s390.32bit.gcc
*) HOSTTYPE
="sol11.s390" CC
="${bgcc99} -m32 -fPIC" cc_sharedlib
="-shared" CCFLAGS
="${bgcc_ccflags}" ;;
363 *.s390.64bit.gcc
*) HOSTTYPE
="sol11.s390" CC
="${bgcc99} -m64 -fPIC" cc_sharedlib
="-shared" CCFLAGS
="${bgcc_ccflags}" ;;
366 fatal_error
"build_shell: Illegal Solaris type/compiler build mode \"${buildmode}\"."
371 fatal_error
"Illegal OS build mode \"${buildmode}\"."
376 [[ -z "${CCFLAGS}" ]] && fatal_error
"build_shell: CCFLAGS is empty."
377 [[ -z "${CC}" ]] && fatal_error
"build_shell: CC is empty."
378 [[ -z "${HOSTTYPE}" ]] && fatal_error
"build_shell: HOSTTYPE is empty."
379 [[ ! -f "bin/package" ]] && fatal_error
"build_shell: bin/package missing."
380 [[ ! -x "bin/package" ]] && fatal_error
"build_shell: bin/package not executable."
382 export CCFLAGS CC HOSTTYPE
385 bin
/package
make CCFLAGS
="${CCFLAGS}" CC="${CC}" HOSTTYPE="${HOSTTYPE}"
387 root
="${PWD}/arch/${HOSTTYPE}"
388 [[ -d "$root" ]] || fatal_error
"build_shell: directory ${root} not found."
389 log
="${root}/lib/package/gen/make.out"
391 [[ -s $log ]] || fatal_error
"build_shell: no make.out log found."
393 if [[ -f ${root}/lib
/libast-g.a
]] then link_libast
="ast-g" ; else link_libast
="ast" ; fi
394 if [[ -f ${root}/lib
/libdll-g.a
]] then link_libdll
="dll-g" ; else link_libdll
="dll" ; fi
395 if [[ -f ${root}/lib
/libsum-g.a
]] then link_libsum
="sum-g" ; else link_libsum
="sum" ; fi
396 if [[ -f ${root}/lib
/libcmd-g.a
]] then link_libcmd
="cmd-g" ; else link_libcmd
="cmd" ; fi
397 if [[ -f ${root}/lib
/libshell-g.a
]] then link_libshell
="shell-g" ; else link_libshell
="shell" ; fi
399 if [[ "${buildmode}" != *.staticshell
* ]] ; then
400 # libcmd causes some trouble since there is a squatter in solaris
401 # This has been fixed in Solaris 11/B48 but may require adjustments
402 # for older Solaris releases
403 for lib
in libast libdll libsum libcmd libshell
; do
406 base
="src/cmd/ksh93/"
408 link
="-L${root}/lib/ -l${link_libcmd} -l${link_libsum} -l${link_libdll} -l${link_libast} -lm"
411 base
="src/lib/${lib}"
416 base
="src/lib/${lib}"
421 base
="src/lib/${lib}"
423 link
="-L${root}/lib/ -l${link_libast} -lm"
430 if [[ -f ${lib}-g.a ]] ; then lib_a="${lib}-g.a" ; else lib_a="${lib}.a
" ; fi
432 if [[ "${buildmode}" == *solaris* ]] ; then
433 ${CC} ${cc_sharedlib} ${CCFLAGS} -Bdirect -Wl,-zallextract -Wl,-zmuldefs -o "${root}/lib/${lib}.so.${vers}" "${lib_a}" $link
435 ${CC} ${cc_sharedlib} ${CCFLAGS} -Wl,--whole-archive -Wl,-zmuldefs "${lib_a}" -Wl,--no-whole-archive -o "${root}/lib/${lib}.so.${vers}" $link
439 mv "${lib_a}" "disabled_
${lib_a}_
"
442 ln -sf "${lib}.so.${vers}" "${lib}.so
"
450 "${root}/lib
/libshell.a
" "${root}/lib
/libshell-g.a
" \
451 "${root}/lib
/libsum.a
" "${root}/lib
/libsum-g.a
" \
452 "${root}/lib
/libdll.a
" "${root}/lib
/libdll-g.a
" \
453 "${root}/lib
/libast.a
" "${root}/lib
/libast-g.a
"
455 if [[ "${buildmode}" == *solaris* ]] ; then
456 ${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
458 ${CC} ${CCFLAGS} ${bsuncc_app_ccflags} -L${root}/lib/ -o ksh pmain.o -lshell -lcmd -lsum -ldll -last -lm
464 export LD_LIBRARY_PATH="${root}/lib
:${LD_LIBRARY_PATH}"
465 export LD_LIBRARY_PATH_32="${root}/lib
:${LD_LIBRARY_PATH_32}"
466 export LD_LIBRARY_PATH_64="${root}/lib
:${LD_LIBRARY_PATH_64}"
472 function test_builtin_getconf
475 print "# testing getconf builtin..."
477 export PATH
=/bin
:/usr
/bin
478 for lang
in ${TEST_LANG} ; do
480 printf "## testing LANG=%s\n" "${lang}"
481 export LC_ALL
="${lang}" LANG
="${lang}"
482 ${SHELL} -c '/usr/bin/getconf -a |
484 t="${i%:*}" ; a="$(getconf "$t" 2>/dev/null)" ;
485 b="$(/usr/bin/getconf "$t" 2>/dev/null)" ; [ "$a" != "$b" ] && print "# |$t|:|$a| != |$b|" ;
489 print
"# testing getconf done."
498 ulimit -s 65536 # need larger stack on 64bit SPARC to pass all tests
500 export SHELL
="$(ls -1 $PWD/arch/*/src/cmd/ksh93/ksh)"
501 export LD_LIBRARY_PATH
="$(ls -1ad $PWD/arch/*/lib):${LD_LIBRARY_PATH}"
502 export LD_LIBRARY_PATH_32
="$(ls -1ad $PWD/arch/*/lib):${LD_LIBRARY_PATH_32}"
503 export LD_LIBRARY_PATH_64
="$(ls -1ad $PWD/arch/*/lib):${LD_LIBRARY_PATH_64}"
504 printf "## SHELL is |%s|\n" "${SHELL}"
505 printf "## LD_LIBRARY_PATH is |%s|\n" "${LD_LIBRARY_PATH}"
507 [[ ! -f "${SHELL}" ]] && fatal_error
"test_shell: |${SHELL}| is not a file."
508 [[ ! -x "${SHELL}" ]] && fatal_error
"test_shell: |${SHELL}| is not executable."
510 [[ "${TEST_LANG}" == "" ]] && TEST_LANG
="C zh_CN.GB18030 en_US.UTF-8"
512 case "${buildmode}" in
514 for lang
in ${TEST_LANG} ; do
516 export LC_ALL
="${lang}" LANG
="${lang}"
517 for i
in .
/src
/cmd
/ksh93
/tests
/*.sh
; do
518 bc_logfile
="$(basename "$i").$$.bcheck"
519 rm -f "${bc_logfile}"
520 /opt
/SUNWspro
/bin
/bcheck
-q -access -o "${bc_logfile}" ${SHELL} .
/src
/cmd
/ksh93
/tests
/shtests \
521 LD_LIBRARY_PATH_64
="$LD_LIBRARY_PATH_64" \
522 LD_LIBRARY_PATH
="$LD_LIBRARY_PATH" \
523 LD_LIBRARY_PATH_32
="$LD_LIBRARY_PATH_32"\
524 LC_ALL
="${lang}" LANG
="${lang}" \
525 VMALLOC_OPTIONS
=abort \
532 testshell.
builtin.getconf
)
536 for lang
in ${TEST_LANG} ; do
538 export LC_ALL
="${lang}" LANG
="${lang}"
539 for i
in .
/src
/cmd
/ksh93
/tests
/*.sh
; do
540 ${SHELL} .
/src
/cmd
/ksh93
/tests
/shtests
-a \
541 LD_LIBRARY_PATH_64
="$LD_LIBRARY_PATH_64" \
542 LD_LIBRARY_PATH
="$LD_LIBRARY_PATH" \
543 LD_LIBRARY_PATH_32
="$LD_LIBRARY_PATH_32" \
544 LC_ALL
="${lang}" LANG
="${lang}" \
545 VMALLOC_OPTIONS
=abort \
546 SHCOMP
=$PWD/arch
/*/bin
/shcomp \
557 case "${buildmode}" in
558 build.
*) build_shell
;;
559 testshell
*) test_shell
;;
560 *) fatal_error
"Illegal build mode \"${buildmode}\"." ;;