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 export PATH
=/usr
/ccs
/bin
:/usr
/bin
:/bin
:/opt
/SUNWspro
/bin
60 function print_solaris_builtin_header
62 # Make sure to use \\ instead of \ for continuations
67 * The contents of this file are subject to the terms of the
68 * Common Development and Distribution License (the "License").
69 * You may not use this file except in compliance with the License.
71 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
72 * or http://www.opensolaris.org/os/licensing.
73 * See the License for the specific language governing permissions
74 * and limitations under the License.
76 * When distributing Covered Code, include this CDDL HEADER in each
77 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
78 * If applicable, add the following below this CDDL HEADER, with the
79 * fields enclosed by brackets "[]" replaced with your own identifying
80 * information: Portions Copyright [yyyy] [name of copyright owner]
86 * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
89 #ifndef _SOLARIS_KSH_CMDLIST_H
90 #define _SOLARIS_KSH_CMDLIST_H
97 * List builtins for Solaris.
98 * The list here is partially autogenerated and partially hand-picked
99 * based on compatibility with the native Solaris versions of these
104 * Commands which are 100% compatible with native Solaris versions (/bin is
105 * a softlink to ./usr/bin, ksh93 takes care about the lookup)
107 #define BINCMDLIST(f) \\
108 { "/bin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
109 #define USRBINCMDLIST(f) \\
110 { "/usr/bin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
111 #define SBINCMDLIST(f) \\
112 { "/sbin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
113 #define SUSRBINCMDLIST(f) \\
114 { "/usr/sbin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
115 #ifdef SHOPT_USR_GNU_BIN_BUILTINS
116 /* GNU coreutils compatible commands */
117 #define GNUCMDLIST(f) \\
118 { "/usr/gnu/bin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
120 #define GNUCMDLIST(f)
123 * Make all ksh93 builtins accessible when /usr/ast/bin was added to
124 * /usr/ccs/bin:/usr/bin:/bin:/opt/SUNWspro/bin
126 #define ASTCMDLIST(f) \\
127 { "/usr/ast/bin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
129 /* undo ast_map.h #defines to avoid collision */
134 /* Generated data, do not edit. */
196 // ASTCMDLIST(readlink)
230 /* Mandatory for ksh93 test suite and AST scripts */
236 #endif /* !_SOLARIS_KSH_CMDLIST_H */
246 # OS.cputype.XXbit.compiler
247 case "${buildmode}" in
249 # ksh93+AST config flags
250 bast_flags
="-DSHOPT_CMDLIB_BLTIN=0 -DSH_CMDLIB_DIR=\\\"/usr/ast/bin\\\" -DSHOPT_SYSRC -D_map_libc=1"
253 bgcc99
="gcc -std=gnu99 "
254 bgcc_ccflags
="${bon_flags} ${bast_flags} -g"
256 case "${buildmode}" in
258 *.i386.32bit.gcc
*) HOSTTYPE
="linux.i386" CC
="${bgcc99} -fPIC" cc_sharedlib
="-shared" CCFLAGS
="${bgcc_ccflags}"
261 fatal_error
"build_shell: Illegal Linux type/compiler build mode \"${buildmode}\"."
267 # 1. Do not remove/modify these flags or their order before either
268 # asking the project leads at
269 # http://www.opensolaris.org/os/project/ksh93-integration/
270 # These flags all have a purpose, even if they look
271 # weird/redundant/etc. at the first look.
273 # 2. We use -KPIC here since -Kpic is too small on 64bit sparc and
274 # on 32bit it's close to the barrier so we use it for both 32bit and
275 # 64bit to avoid later suprises when people update libast in the
278 # 3. "-D_map_libc=1" is needed to force map.c to add a "_ast_" prefix to all
279 # AST symbol names which may otherwise collide with Solaris/Linux libc
281 # 4. "-DSHOPT_SYSRC" enables /etc/ksh.kshrc support (AST default is currently
282 # to enable it if /etc/ksh.kshrc or /etc/bash.bashrc are available on the
285 # 6. "-xc99=%all -D_XOPEN_SOURCE=600 -D__EXTENSIONS__=1" is used to force
286 # the compiler into C99 mode. Otherwise ksh93 will be much slower and lacks
287 # lots of arithmethic functions.
289 # 7. bon_flags are flags taken from the default OS/Net
292 # 8. "-xpagesize_stack=64K is used on SPARC to enhance the performace
294 # 9. -DSHOPT_CMDLIB_BLTIN=0 -DSH_CMDLIB_DIR=\\\"/usr/ast/bin\\\" -DSHOPT_CMDLIB_HDR=\\\"/home/test001/ksh93/ast_ksh_20070322/solaris_cmdlist.h\\\"
295 # is used to bind all ksh93 builtins to a "virtual" directory
296 # called "/usr/ast/bin/" and to adjust the list of builtins
297 # enabled by default to those defined by PSARC 2006/550
299 solaris_builtin_header
="${PWD}/tmp_solaris_builtin_header.h"
300 print_solaris_builtin_header
>"${solaris_builtin_header}"
305 # ksh93+AST config flags
306 bast_flags
="-DSHOPT_CMDLIB_BLTIN=0 -DSH_CMDLIB_DIR=\\\"/usr/ast/bin\\\" -DSHOPT_CMDLIB_HDR=\\\"${solaris_builtin_header}\\\" -DSHOPT_SYSRC -D_map_libc=1"
309 bsunc99
="/opt/SUNWspro/bin/cc -xc99=%all -D_XOPEN_SOURCE=600 -D__EXTENSIONS__=1"
310 bsuncc_app_ccflags_sparc
="-xpagesize_stack=64K" # use bsuncc_app_ccflags_sparc only for final executables
311 bsuncc_ccflags
="${bon_flags} -KPIC -g -xs -Xa -z combreloc -xcsi -errtags=yes ${bast_flags}"
314 bgcc99
="/usr/sfw/bin/gcc -std=gnu99 -D_XOPEN_SOURCE=600 -D__EXTENSIONS__=1"
315 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"
316 bgcc_ccflags
="${bon_flags} ${bgcc_warnflags} ${bast_flags}"
318 case "${buildmode}" in
319 # for -m32/-m64 flags see usr/src/Makefile.master, makefile symbols *_XARCH/co.
320 *.i386.32bit.suncc
*) HOSTTYPE
="sol11.i386" CC
="${bsunc99} -m32" cc_sharedlib
="-G" CCFLAGS
="${bsuncc_ccflags}" ;;
321 *.i386.64bit.suncc
*) HOSTTYPE
="sol11.i386" CC
="${bsunc99} -m64 -KPIC" cc_sharedlib
="-G" CCFLAGS
="${bsuncc_ccflags}" ;;
322 *.sparc
.32bit.suncc
*) HOSTTYPE
="sol11.sun4" CC
="${bsunc99} -m32" cc_sharedlib="-G" CCFLAGS="${bsuncc_ccflags}" bsuncc_app_ccflags="${bsuncc_app_ccflags_sparc}" ;;
323 *.sparc
.64bit.suncc
*) HOSTTYPE
="sol11.sun4" CC
="${bsunc99} -m64 -KPIC" cc_sharedlib="-G" CCFLAGS="${bsuncc_ccflags}" bsuncc_app_ccflags="${bsuncc_app_ccflags_sparc}" ;;
325 *.i386.32bit.gcc
*) HOSTTYPE
="sol11.i386" CC
="${bgcc99} -fPIC" cc_sharedlib
="-shared" CCFLAGS
="${bgcc_ccflags}" ;;
326 *.i386.64bit.gcc
*) HOSTTYPE
="sol11.i386" CC
="${bgcc99} -m64 -mtune=opteron -Ui386 -U__i386 -fPIC" cc_sharedlib
="-shared" CCFLAGS
="${bgcc_ccflags}" ;;
327 *.sparc
.32bit.gcc
*) HOSTTYPE
="sol11.sun4" CC
="${bgcc99} -m32 -mcpu=v8 -fPIC" cc_sharedlib
="-shared" CCFLAGS
="${bgcc_ccflags}" ;;
328 *.sparc
.64bit.gcc
*) HOSTTYPE
="sol11.sun4" CC
="${bgcc99} -m64 -mcpu=v9 -fPIC" cc_sharedlib
="-shared" CCFLAGS
="${bgcc_ccflags}" ;;
329 *.s390.32bit.gcc
*) HOSTTYPE
="sol11.s390" CC
="${bgcc99} -m32 -fPIC" cc_sharedlib
="-shared" CCFLAGS
="${bgcc_ccflags}" ;;
330 *.s390.64bit.gcc
*) HOSTTYPE
="sol11.s390" CC
="${bgcc99} -m64 -fPIC" cc_sharedlib
="-shared" CCFLAGS
="${bgcc_ccflags}" ;;
333 fatal_error
"build_shell: Illegal Solaris type/compiler build mode \"${buildmode}\"."
338 fatal_error
"Illegal OS build mode \"${buildmode}\"."
343 [[ -z "${CCFLAGS}" ]] && fatal_error
"build_shell: CCFLAGS is empty."
344 [[ -z "${CC}" ]] && fatal_error
"build_shell: CC is empty."
345 [[ -z "${HOSTTYPE}" ]] && fatal_error
"build_shell: HOSTTYPE is empty."
346 [[ ! -f "bin/package" ]] && fatal_error
"build_shell: bin/package missing."
347 [[ ! -x "bin/package" ]] && fatal_error
"build_shell: bin/package not executable."
349 export CCFLAGS CC HOSTTYPE
352 bin
/package
make CCFLAGS
="${CCFLAGS}" CC="${CC}" HOSTTYPE="${HOSTTYPE}"
354 root
="${PWD}/arch/${HOSTTYPE}"
355 [[ -d "$root" ]] || fatal_error
"build_shell: directory ${root} not found."
356 log
="${root}/lib/package/gen/make.out"
358 [[ -s $log ]] || fatal_error
"build_shell: no make.out log found."
360 if [[ -f ${root}/lib
/libast-g.a
]] then link_libast
="ast-g" ; else link_libast
="ast" ; fi
361 if [[ -f ${root}/lib
/libdll-g.a
]] then link_libdll
="dll-g" ; else link_libdll
="dll" ; fi
362 if [[ -f ${root}/lib
/libsum-g.a
]] then link_libsum
="sum-g" ; else link_libsum
="sum" ; fi
363 if [[ -f ${root}/lib
/libcmd-g.a
]] then link_libcmd
="cmd-g" ; else link_libcmd
="cmd" ; fi
364 if [[ -f ${root}/lib
/libshell-g.a
]] then link_libshell
="shell-g" ; else link_libshell
="shell" ; fi
366 if [[ "${buildmode}" != *.staticshell
* ]] ; then
367 # libcmd causes some trouble since there is a squatter in solaris
368 # This has been fixed in Solaris 11/B48 but may require adjustments
369 # for older Solaris releases
370 for lib
in libast libdll libsum libcmd libshell
; do
373 base
="src/cmd/ksh93/"
375 link
="-L${root}/lib/ -l${link_libcmd} -l${link_libsum} -l${link_libdll} -l${link_libast} -lm"
378 base
="src/lib/${lib}"
383 base
="src/lib/${lib}"
388 base
="src/lib/${lib}"
390 link
="-L${root}/lib/ -l${link_libast} -lm"
397 if [[ -f ${lib}-g.a ]] ; then lib_a="${lib}-g.a" ; else lib_a="${lib}.a
" ; fi
399 if [[ "${buildmode}" == *solaris* ]] ; then
400 ${CC} ${cc_sharedlib} ${CCFLAGS} -Bdirect -Wl,-zallextract -Wl,-zmuldefs -o "${root}/lib/${lib}.so.${vers}" "${lib_a}" $link
402 ${CC} ${cc_sharedlib} ${CCFLAGS} -Wl,--whole-archive -Wl,-zmuldefs "${lib_a}" -Wl,--no-whole-archive -o "${root}/lib/${lib}.so.${vers}" $link
406 mv "${lib_a}" "disabled_
${lib_a}_
"
409 ln -sf "${lib}.so.${vers}" "${lib}.so
"
417 "${root}/lib
/libshell.a
" "${root}/lib
/libshell-g.a
" \
418 "${root}/lib
/libsum.a
" "${root}/lib
/libsum-g.a
" \
419 "${root}/lib
/libdll.a
" "${root}/lib
/libdll-g.a
" \
420 "${root}/lib
/libast.a
" "${root}/lib
/libast-g.a
"
422 if [[ "${buildmode}" == *solaris* ]] ; then
423 ${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
425 ${CC} ${CCFLAGS} ${bsuncc_app_ccflags} -L${root}/lib/ -o ksh pmain.o -lshell -lcmd -lsum -ldll -last -lm
431 export LD_LIBRARY_PATH="${root}/lib
:${LD_LIBRARY_PATH}"
432 export LD_LIBRARY_PATH_32="${root}/lib
:${LD_LIBRARY_PATH_32}"
433 export LD_LIBRARY_PATH_64="${root}/lib
:${LD_LIBRARY_PATH_64}"
439 function test_builtin_getconf
442 print "# testing getconf builtin..."
444 export PATH
=/bin
:/usr
/bin
445 for lang
in ${TEST_LANG} ; do
447 printf "## testing LANG=%s\n" "${lang}"
448 export LC_ALL
="${lang}" LANG
="${lang}"
449 ${SHELL} -c '/usr/bin/getconf -a |
451 t="${i%:*}" ; a="$(getconf "$t" 2>/dev/null)" ;
452 b="$(/usr/bin/getconf "$t" 2>/dev/null)" ; [ "$a" != "$b" ] && print "# |$t|:|$a| != |$b|" ;
456 print
"# testing getconf done."
465 ulimit -s 65536 # need larger stack on 64bit SPARC to pass all tests
467 export SHELL
="$(ls -1 $PWD/arch/*/src/cmd/ksh93/ksh)"
468 export LD_LIBRARY_PATH
="$(ls -1ad $PWD/arch/*/lib):${LD_LIBRARY_PATH}"
469 export LD_LIBRARY_PATH_32
="$(ls -1ad $PWD/arch/*/lib):${LD_LIBRARY_PATH_32}"
470 export LD_LIBRARY_PATH_64
="$(ls -1ad $PWD/arch/*/lib):${LD_LIBRARY_PATH_64}"
471 printf "## SHELL is |%s|\n" "${SHELL}"
472 printf "## LD_LIBRARY_PATH is |%s|\n" "${LD_LIBRARY_PATH}"
474 [[ ! -f "${SHELL}" ]] && fatal_error
"test_shell: |${SHELL}| is not a file."
475 [[ ! -x "${SHELL}" ]] && fatal_error
"test_shell: |${SHELL}| is not executable."
477 [[ "${TEST_LANG}" == "" ]] && TEST_LANG
="C zh_CN.GB18030 en_US.UTF-8"
479 case "${buildmode}" in
481 for lang
in ${TEST_LANG} ; do
483 export LC_ALL
="${lang}" LANG
="${lang}"
484 for i
in .
/src
/cmd
/ksh93
/tests
/*.sh
; do
485 bc_logfile
="$(basename "$i").$$.bcheck"
486 rm -f "${bc_logfile}"
487 /opt
/SUNWspro
/bin
/bcheck
-q -access -o "${bc_logfile}" ${SHELL} .
/src
/cmd
/ksh93
/tests
/shtests \
488 LD_LIBRARY_PATH_64
="$LD_LIBRARY_PATH_64" \
489 LD_LIBRARY_PATH
="$LD_LIBRARY_PATH" \
490 LD_LIBRARY_PATH_32
="$LD_LIBRARY_PATH_32"\
491 LC_ALL
="${lang}" LANG
="${lang}" \
492 VMALLOC_OPTIONS
=abort \
499 testshell.
builtin.getconf
)
503 for lang
in ${TEST_LANG} ; do
505 export LC_ALL
="${lang}" LANG
="${lang}"
506 for i
in .
/src
/cmd
/ksh93
/tests
/*.sh
; do
507 ${SHELL} .
/src
/cmd
/ksh93
/tests
/shtests
-a \
508 LD_LIBRARY_PATH_64
="$LD_LIBRARY_PATH_64" \
509 LD_LIBRARY_PATH
="$LD_LIBRARY_PATH" \
510 LD_LIBRARY_PATH_32
="$LD_LIBRARY_PATH_32" \
511 LC_ALL
="${lang}" LANG
="${lang}" \
512 VMALLOC_OPTIONS
=abort \
513 SHCOMP
=$PWD/arch
/*/bin
/shcomp \
524 case "${buildmode}" in
525 build.
*) build_shell
;;
526 testshell
*) test_shell
;;
527 *) fatal_error
"Illegal build mode \"${buildmode}\"." ;;