Skip to content

Commit 580ff61

Browse files
committed
Fix release and standards build flags (re: 3567220, aa4669a)
bin/package, src/cmd/INIT/package.sh: - CCFLAGS overwrites the autodetected optimisation flags (e.g. -Os) if set. Unfortunately, that also happened when we added something to CCFLAGS for a release build or to add an extra flag needed by Solaris. The fix is to use a new flags variable (KSH_RELFLAGS) instead. This needs to be done in a different place as it needs to be added to the mamake command as an assignment argument. - Remove the Solaris CCFLAGS hack; see features/common below. src/*/*/Mamfile: - Add ${KSH_RELFLAGS} to all the compiler commands. src/lib/libast/features/common: - Enable POSIX standard on Solaris (i.e.: if __sun is defined) by defining _XPG6 directly in the feature test that generates ast_std.h, which is indirectly included by everything. This removes the need to pass -D_XPG6 via CCFLAGS. (Doing so automatically with gcc was not otherwise possible.) src/cmd/INIT/cc.sol11.*: - No longer pass -D_XPG6, as per above.
1 parent e25d9f4 commit 580ff61

File tree

14 files changed

+925
-922
lines changed

14 files changed

+925
-922
lines changed

bin/package

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,40 @@ case $CC in
13841384
*) export CC ;;
13851385
esac
13861386

1387+
# Add build type flags via KSH_RELFLAGS, which is used in src/cmd/ksh93/Mamfile.
1388+
# (Avoid using CCFLAGS; setting it would overwrite autodetected optimization flags.)
1389+
ksh_relflags=
1390+
case `git branch 2>/dev/null` in
1391+
'' | *\*\ [0-9]*.[0-9]*)
1392+
# If we're not on a git branch (tarball) or on a branch that starts
1393+
# with a number (release branch), then compile as a release version
1394+
ksh_relflags="${ksh_relflags:+$ksh_relflags }-D_AST_ksh_release" ;;
1395+
*) # Otherwise, add 8-character git commit hash if available, and if the working dir is clean
1396+
git_commit=`git status >/dev/null 2>&1 && git diff-index --quiet HEAD && git rev-parse --short=8 HEAD`
1397+
case $git_commit in
1398+
????????)
1399+
ksh_relflags="${ksh_relflags:+$ksh_relflags }-D_AST_git_commit=\\\"$git_commit\\\"" ;;
1400+
esac
1401+
unset git_commit ;;
1402+
esac
1403+
case $ksh_relflags in
1404+
?*) # add the extra flags as an argument to mamake
1405+
assign="${assign:+$assign }KSH_RELFLAGS=\"\$ksh_relflags\"" ;;
1406+
esac
1407+
1408+
# Hack to build on some systems that need an explicit link with libm due to a bug in the build system
1409+
case `uname` in
1410+
NetBSD | SunOS)
1411+
case " $LDFLAGS " in
1412+
*" -m "*)
1413+
;;
1414+
*) LDFLAGS="-lm${LDFLAGS:+ $LDFLAGS}"
1415+
export LDFLAGS
1416+
;;
1417+
esac
1418+
;;
1419+
esac
1420+
13871421
# grab action specific args
13881422

13891423
case $action in
@@ -5402,49 +5436,6 @@ license)# all work in $PACKAGESRC/LICENSES
54025436
;;
54035437

54045438
make|view)
5405-
# Add flags for build type
5406-
case `git branch 2>/dev/null` in
5407-
'' | *\*\ [0-9]*.[0-9]*)
5408-
# If we're not on a git branch (tarball) or on a branch that starts
5409-
# with a number (release branch), then compile as a release version
5410-
CCFLAGS="-D_AST_ksh_release${CCFLAGS:+ $CCFLAGS}" # prefix it to allow override with -U
5411-
export CCFLAGS
5412-
;;
5413-
*) # Otherwise, add 8-character git commit hash if available, and if the working dir is clean
5414-
git_commit=`git status >/dev/null 2>&1 && git diff-index --quiet HEAD && git rev-parse --short=8 HEAD`
5415-
case $git_commit in
5416-
????????)
5417-
CCFLAGS="-D_AST_git_commit=\\\"$git_commit\\\"${CCFLAGS:+ $CCFLAGS}"
5418-
export CCFLAGS
5419-
;;
5420-
esac
5421-
unset git_commit
5422-
;;
5423-
esac
5424-
# Hack to build on some systems that need an explicit link with libm due to a bug in the build system
5425-
case `uname` in
5426-
NetBSD | SunOS)
5427-
case " $LDFLAGS " in
5428-
*" -m "*)
5429-
;;
5430-
*) LDFLAGS="-lm${LDFLAGS:+ $LDFLAGS}"
5431-
export LDFLAGS
5432-
;;
5433-
esac
5434-
;;
5435-
esac
5436-
# Hack for Solaris gcc, which needs -D_XPG6 in C flags to not segfault
5437-
case `uname` in
5438-
SunOS) case "$CC, $CCFLAGS " in
5439-
*" -D_XPG6 "*)
5440-
;;
5441-
*gcc,*) CCFLAGS="-D_XPG6${CCFLAGS:+ $CCFLAGS}"
5442-
export CCFLAGS
5443-
;;
5444-
esac
5445-
;;
5446-
esac
5447-
54485439
cd $PACKAGEROOT
54495440
case $package in
54505441
'') lic="lib/package/*.lic"

src/cmd/INIT/Mamfile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ setv AS as
77
setv ASFLAGS
88
setv CC cc
99
setv mam_cc_FLAGS
10+
setv KSH_RELFLAGS
1011
setv CCFLAGS ${-debug-symbols?1?${mam_cc_DEBUG} -D_BLD_DEBUG?${mam_cc_OPTIMIZE}?}
1112
setv CCLDFLAGS ${-strip-symbols?1?${mam_cc_LD_STRIP}??}
1213
setv COTEMP $$
@@ -532,19 +533,19 @@ done ast.h dontcare virtual
532533
done mamake.c
533534
meta mamake.o %.c>%.o mamake.c mamake
534535
prev mamake.c
535-
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -DUSAGE_LICENSE=\""[-author?Glenn Fowler <gsf@research.att.com>][-copyright?Copyright (c) 1994-2012 AT&T Intellectual Property][-license?http://www.eclipse.org/org/documents/epl-v10.html]"\" -c mamake.c
536+
exec - ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} -DUSAGE_LICENSE=\""[-author?Glenn Fowler <gsf@research.att.com>][-copyright?Copyright (c) 1994-2012 AT&T Intellectual Property][-license?http://www.eclipse.org/org/documents/epl-v10.html]"\" -c mamake.c
536537
done mamake.o generated
537-
exec - ${CC} ${CCLDFLAGS} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS} -o mamake mamake.o
538+
exec - ${CC} ${CCLDFLAGS} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} ${LDFLAGS} -o mamake mamake.o
538539
done mamake generated
539540
make proto
540541
make proto.o
541542
make proto.c
542543
done proto.c
543544
meta proto.o %.c>%.o proto.c proto
544545
prev proto.c
545-
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -c proto.c
546+
exec - ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} -c proto.c
546547
done proto.o generated
547-
exec - ${CC} ${CCLDFLAGS} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS} -o proto proto.o
548+
exec - ${CC} ${CCLDFLAGS} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} ${LDFLAGS} -o proto proto.o
548549
done proto generated
549550
make ratz
550551
make ratz.o
@@ -567,9 +568,9 @@ prev ast.h implicit
567568
done ratz.c
568569
meta ratz.o %.c>%.o ratz.c ratz
569570
prev ratz.c
570-
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -c ratz.c
571+
exec - ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} -c ratz.c
571572
done ratz.o generated
572-
exec - ${CC} ${CCLDFLAGS} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS} -o ratz ratz.o
573+
exec - ${CC} ${CCLDFLAGS} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} ${LDFLAGS} -o ratz ratz.o
573574
done ratz generated
574575
make release
575576
make release.o
@@ -578,9 +579,9 @@ prev ast.h implicit
578579
done release.c
579580
meta release.o %.c>%.o release.c release
580581
prev release.c
581-
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -DUSAGE_LICENSE=\""[-author?Glenn Fowler <gsf@research.att.com>][-copyright?Copyright (c) 1994-2012 AT&T Intellectual Property][-license?http://www.eclipse.org/org/documents/epl-v10.html]"\" -c release.c
582+
exec - ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} -DUSAGE_LICENSE=\""[-author?Glenn Fowler <gsf@research.att.com>][-copyright?Copyright (c) 1994-2012 AT&T Intellectual Property][-license?http://www.eclipse.org/org/documents/epl-v10.html]"\" -c release.c
582583
done release.o generated
583-
exec - ${CC} ${CCLDFLAGS} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS} -o release release.o
584+
exec - ${CC} ${CCLDFLAGS} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} ${LDFLAGS} -o release release.o
584585
done release generated
585586
make mprobe
586587
make mprobe.sh

src/cmd/INIT/cc.sol11.i386

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
: solaris.i386 cc wrapper for reasonable ansi C defaults and 32 bit : 2021-01-16 :
1+
: solaris.i386 cc wrapper for reasonable ansi C defaults and 32 bit : 2021-01-17 :
22

33
HOSTTYPE=sol11.i386
44

@@ -13,4 +13,6 @@ case ${CC_EXPLICIT:=$CC} in
1313
CC_EXPLICIT=cc
1414
esac
1515

16-
$CC_EXPLICIT -m32 -xc99 -D_XPG6 "$@"
16+
# Note: the _XPG6 macro is now defined in src/lib/libast/features/common
17+
18+
$CC_EXPLICIT -m32 -xc99 "$@"

src/cmd/INIT/cc.sol11.i386-64

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
: solaris.i386-64 cc wrapper for reasonable ansi C defaults and 64 bit : 2021-01-16 :
1+
: solaris.i386-64 cc wrapper for reasonable ansi C defaults and 64 bit : 2021-01-17 :
22

33
HOSTTYPE=sol11.i386-64
44

@@ -13,4 +13,6 @@ case ${CC_EXPLICIT:=$CC} in
1313
CC_EXPLICIT=cc
1414
esac
1515

16-
$CC_EXPLICIT -m64 -xc99 -D_XPG6 "$@"
16+
# Note: the _XPG6 macro is now defined in src/lib/libast/features/common
17+
18+
$CC_EXPLICIT -m64 -xc99 "$@"

src/cmd/INIT/cc.sol11.sparc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
: solaris.sparc cc wrapper for reasonable ansi C defaults and 32 bit : 2021-01-16 :
1+
: solaris.sparc cc wrapper for reasonable ansi C defaults and 32 bit : 2021-01-17 :
22

33
HOSTTYPE=sol11.sparc
44

@@ -13,4 +13,6 @@ case ${CC_EXPLICIT:=$CC} in
1313
CC_EXPLICIT=cc
1414
esac
1515

16-
$CC_EXPLICIT -m32 -xc99 -D_XPG6 "$@"
16+
# Note: the _XPG6 macro is now defined in src/lib/libast/features/common
17+
18+
$CC_EXPLICIT -m32 -xc99 "$@"

src/cmd/INIT/cc.sol11.sparc-64

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
: solaris.sparc-64 cc wrapper for reasonable ansi C defaults and 64 bit : 2021-01-16 :
1+
: solaris.sparc-64 cc wrapper for reasonable ansi C defaults and 64 bit : 2021-01-17 :
22

33
HOSTTYPE=sol11.sparc-64
44

@@ -13,4 +13,6 @@ case ${CC_EXPLICIT:=$CC} in
1313
CC_EXPLICIT=cc
1414
esac
1515

16-
$CC_EXPLICIT -m64 -xc99 -D_XPG6 "$@"
16+
# Note: the _XPG6 macro is now defined in src/lib/libast/features/common
17+
18+
$CC_EXPLICIT -m64 -xc99 "$@"

src/cmd/INIT/package.sh

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,6 +1383,40 @@ case $CC in
13831383
*) export CC ;;
13841384
esac
13851385

1386+
# Add build type flags via KSH_RELFLAGS, which is used in src/cmd/ksh93/Mamfile.
1387+
# (Avoid using CCFLAGS; setting it would overwrite autodetected optimization flags.)
1388+
ksh_relflags=
1389+
case `git branch 2>/dev/null` in
1390+
'' | *\*\ [0-9]*.[0-9]*)
1391+
# If we're not on a git branch (tarball) or on a branch that starts
1392+
# with a number (release branch), then compile as a release version
1393+
ksh_relflags="${ksh_relflags:+$ksh_relflags }-D_AST_ksh_release" ;;
1394+
*) # Otherwise, add 8-character git commit hash if available, and if the working dir is clean
1395+
git_commit=`git status >/dev/null 2>&1 && git diff-index --quiet HEAD && git rev-parse --short=8 HEAD`
1396+
case $git_commit in
1397+
????????)
1398+
ksh_relflags="${ksh_relflags:+$ksh_relflags }-D_AST_git_commit=\\\"$git_commit\\\"" ;;
1399+
esac
1400+
unset git_commit ;;
1401+
esac
1402+
case $ksh_relflags in
1403+
?*) # add the extra flags as an argument to mamake
1404+
assign="${assign:+$assign }KSH_RELFLAGS=\"\$ksh_relflags\"" ;;
1405+
esac
1406+
1407+
# Hack to build on some systems that need an explicit link with libm due to a bug in the build system
1408+
case `uname` in
1409+
NetBSD | SunOS)
1410+
case " $LDFLAGS " in
1411+
*" -m "*)
1412+
;;
1413+
*) LDFLAGS="-lm${LDFLAGS:+ $LDFLAGS}"
1414+
export LDFLAGS
1415+
;;
1416+
esac
1417+
;;
1418+
esac
1419+
13861420
# grab action specific args
13871421

13881422
case $action in
@@ -5401,49 +5435,6 @@ license)# all work in $PACKAGESRC/LICENSES
54015435
;;
54025436

54035437
make|view)
5404-
# Add flags for build type
5405-
case `git branch 2>/dev/null` in
5406-
'' | *\*\ [0-9]*.[0-9]*)
5407-
# If we're not on a git branch (tarball) or on a branch that starts
5408-
# with a number (release branch), then compile as a release version
5409-
CCFLAGS="-D_AST_ksh_release${CCFLAGS:+ $CCFLAGS}" # prefix it to allow override with -U
5410-
export CCFLAGS
5411-
;;
5412-
*) # Otherwise, add 8-character git commit hash if available, and if the working dir is clean
5413-
git_commit=`git status >/dev/null 2>&1 && git diff-index --quiet HEAD && git rev-parse --short=8 HEAD`
5414-
case $git_commit in
5415-
????????)
5416-
CCFLAGS="-D_AST_git_commit=\\\"$git_commit\\\"${CCFLAGS:+ $CCFLAGS}"
5417-
export CCFLAGS
5418-
;;
5419-
esac
5420-
unset git_commit
5421-
;;
5422-
esac
5423-
# Hack to build on some systems that need an explicit link with libm due to a bug in the build system
5424-
case `uname` in
5425-
NetBSD | SunOS)
5426-
case " $LDFLAGS " in
5427-
*" -m "*)
5428-
;;
5429-
*) LDFLAGS="-lm${LDFLAGS:+ $LDFLAGS}"
5430-
export LDFLAGS
5431-
;;
5432-
esac
5433-
;;
5434-
esac
5435-
# Hack for Solaris gcc, which needs -D_XPG6 in C flags to not segfault
5436-
case `uname` in
5437-
SunOS) case "$CC, $CCFLAGS " in
5438-
*" -D_XPG6 "*)
5439-
;;
5440-
*gcc,*) CCFLAGS="-D_XPG6${CCFLAGS:+ $CCFLAGS}"
5441-
export CCFLAGS
5442-
;;
5443-
esac
5444-
;;
5445-
esac
5446-
54475438
cd $PACKAGEROOT
54485439
case $package in
54495440
'') lic="lib/package/*.lic"

src/cmd/builtin/Mamfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ setv AS as
1212
setv ASFLAGS
1313
setv CC cc
1414
setv mam_cc_FLAGS
15+
setv KSH_RELFLAGS
1516
setv CCFLAGS ${-debug-symbols?1?${mam_cc_DEBUG} -D_BLD_DEBUG?${mam_cc_OPTIMIZE}?}
1617
setv CCLDFLAGS ${-strip-symbols?1?${mam_cc_LD_STRIP}??}
1718
setv COTEMP $$
@@ -55,7 +56,7 @@ make FEATURE/pty implicit
5556
meta FEATURE/pty features/%>FEATURE/% features/pty pty
5657
make features/pty
5758
done features/pty
58-
exec - iffe -v -c '${CC} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS} ' ref ${mam_cc_L+-L${INSTALLROOT}/lib} -I${PACKAGE_ast_INCLUDE} -I${INSTALLROOT}/include ${mam_libast} ${mam_libcmd} : run features/pty
59+
exec - iffe -v -c '${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} ${LDFLAGS} ' ref ${mam_cc_L+-L${INSTALLROOT}/lib} -I${PACKAGE_ast_INCLUDE} -I${INSTALLROOT}/include ${mam_libast} ${mam_libcmd} : run features/pty
5960
done FEATURE/pty generated
6061
make ${PACKAGE_ast_INCLUDE}/ast_time.h implicit
6162
done ${PACKAGE_ast_INCLUDE}/ast_time.h
@@ -72,11 +73,11 @@ meta pty.o %.c>%.o pty.c pty
7273
prev pty.c
7374
setv CMD_STANDALONE -DCMD_STANDALONE="b_pty"
7475
setv LICENSE -DLICENSE="since=2001,author=gsf+dgk"
75-
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -DERROR_CATALOG=\""builtin"\" -D_PACKAGE_ast -DCMD_STANDALONE=b_pty -DUSAGE_LICENSE=\""[-author?Glenn Fowler <gsf@research.att.com>][-author?David Korn <dgk@research.att.com>][-copyright?Copyright (c) 2001-2012 AT&T Intellectual Property][-license?http://www.eclipse.org/org/documents/epl-v10.html][--catalog?builtin]"\" -c pty.c
76+
exec - ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -DERROR_CATALOG=\""builtin"\" -D_PACKAGE_ast -DCMD_STANDALONE=b_pty -DUSAGE_LICENSE=\""[-author?Glenn Fowler <gsf@research.att.com>][-author?David Korn <dgk@research.att.com>][-copyright?Copyright (c) 2001-2012 AT&T Intellectual Property][-license?http://www.eclipse.org/org/documents/epl-v10.html][--catalog?builtin]"\" -c pty.c
7677
done pty.o generated
7778
bind -lutil dontcare
7879
setv CMD_STANDALONE -DCMD_STANDALONE="b_pty"
79-
exec - ${CC} ${CCLDFLAGS} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS} ${mam_cc_L+-L.} ${mam_cc_L+-L${INSTALLROOT}/lib} -o pty pty.o ${mam_libutil} ${mam_libast} ${mam_libcmd}
80+
exec - ${CC} ${CCLDFLAGS} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} ${LDFLAGS} ${mam_cc_L+-L.} ${mam_cc_L+-L${INSTALLROOT}/lib} -o pty pty.o ${mam_libutil} ${mam_libast} ${mam_libcmd}
8081
done pty generated
8182
make ${INSTALLROOT}/bin
8283
exec - if silent test ! -d ${INSTALLROOT}/bin

0 commit comments

Comments
 (0)