Skip to content

Commit

Permalink
Fix release and standards build flags (re: 3567220, aa4669a)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
McDutchie committed Jan 18, 2021
1 parent e25d9f4 commit 580ff61
Show file tree
Hide file tree
Showing 14 changed files with 925 additions and 922 deletions.
77 changes: 34 additions & 43 deletions bin/package
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,40 @@ case $CC in
*) export CC ;;
esac

# Add build type flags via KSH_RELFLAGS, which is used in src/cmd/ksh93/Mamfile.
# (Avoid using CCFLAGS; setting it would overwrite autodetected optimization flags.)
ksh_relflags=
case `git branch 2>/dev/null` in
'' | *\*\ [0-9]*.[0-9]*)
# If we're not on a git branch (tarball) or on a branch that starts
# with a number (release branch), then compile as a release version
ksh_relflags="${ksh_relflags:+$ksh_relflags }-D_AST_ksh_release" ;;
*) # Otherwise, add 8-character git commit hash if available, and if the working dir is clean
git_commit=`git status >/dev/null 2>&1 && git diff-index --quiet HEAD && git rev-parse --short=8 HEAD`
case $git_commit in
????????)
ksh_relflags="${ksh_relflags:+$ksh_relflags }-D_AST_git_commit=\\\"$git_commit\\\"" ;;
esac
unset git_commit ;;
esac
case $ksh_relflags in
?*) # add the extra flags as an argument to mamake
assign="${assign:+$assign }KSH_RELFLAGS=\"\$ksh_relflags\"" ;;
esac

# Hack to build on some systems that need an explicit link with libm due to a bug in the build system
case `uname` in
NetBSD | SunOS)
case " $LDFLAGS " in
*" -m "*)
;;
*) LDFLAGS="-lm${LDFLAGS:+ $LDFLAGS}"
export LDFLAGS
;;
esac
;;
esac

# grab action specific args

case $action in
Expand Down Expand Up @@ -5402,49 +5436,6 @@ license)# all work in $PACKAGESRC/LICENSES
;;

make|view)
# Add flags for build type
case `git branch 2>/dev/null` in
'' | *\*\ [0-9]*.[0-9]*)
# If we're not on a git branch (tarball) or on a branch that starts
# with a number (release branch), then compile as a release version
CCFLAGS="-D_AST_ksh_release${CCFLAGS:+ $CCFLAGS}" # prefix it to allow override with -U
export CCFLAGS
;;
*) # Otherwise, add 8-character git commit hash if available, and if the working dir is clean
git_commit=`git status >/dev/null 2>&1 && git diff-index --quiet HEAD && git rev-parse --short=8 HEAD`
case $git_commit in
????????)
CCFLAGS="-D_AST_git_commit=\\\"$git_commit\\\"${CCFLAGS:+ $CCFLAGS}"
export CCFLAGS
;;
esac
unset git_commit
;;
esac
# Hack to build on some systems that need an explicit link with libm due to a bug in the build system
case `uname` in
NetBSD | SunOS)
case " $LDFLAGS " in
*" -m "*)
;;
*) LDFLAGS="-lm${LDFLAGS:+ $LDFLAGS}"
export LDFLAGS
;;
esac
;;
esac
# Hack for Solaris gcc, which needs -D_XPG6 in C flags to not segfault
case `uname` in
SunOS) case "$CC, $CCFLAGS " in
*" -D_XPG6 "*)
;;
*gcc,*) CCFLAGS="-D_XPG6${CCFLAGS:+ $CCFLAGS}"
export CCFLAGS
;;
esac
;;
esac

cd $PACKAGEROOT
case $package in
'') lic="lib/package/*.lic"
Expand Down
17 changes: 9 additions & 8 deletions src/cmd/INIT/Mamfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ setv AS as
setv ASFLAGS
setv CC cc
setv mam_cc_FLAGS
setv KSH_RELFLAGS
setv CCFLAGS ${-debug-symbols?1?${mam_cc_DEBUG} -D_BLD_DEBUG?${mam_cc_OPTIMIZE}?}
setv CCLDFLAGS ${-strip-symbols?1?${mam_cc_LD_STRIP}??}
setv COTEMP $$
Expand Down Expand Up @@ -532,19 +533,19 @@ done ast.h dontcare virtual
done mamake.c
meta mamake.o %.c>%.o mamake.c mamake
prev mamake.c
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
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
done mamake.o generated
exec - ${CC} ${CCLDFLAGS} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS} -o mamake mamake.o
exec - ${CC} ${CCLDFLAGS} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} ${LDFLAGS} -o mamake mamake.o
done mamake generated
make proto
make proto.o
make proto.c
done proto.c
meta proto.o %.c>%.o proto.c proto
prev proto.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -c proto.c
exec - ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} -c proto.c
done proto.o generated
exec - ${CC} ${CCLDFLAGS} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS} -o proto proto.o
exec - ${CC} ${CCLDFLAGS} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} ${LDFLAGS} -o proto proto.o
done proto generated
make ratz
make ratz.o
Expand All @@ -567,9 +568,9 @@ prev ast.h implicit
done ratz.c
meta ratz.o %.c>%.o ratz.c ratz
prev ratz.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -c ratz.c
exec - ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} -c ratz.c
done ratz.o generated
exec - ${CC} ${CCLDFLAGS} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS} -o ratz ratz.o
exec - ${CC} ${CCLDFLAGS} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} ${LDFLAGS} -o ratz ratz.o
done ratz generated
make release
make release.o
Expand All @@ -578,9 +579,9 @@ prev ast.h implicit
done release.c
meta release.o %.c>%.o release.c release
prev release.c
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
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
done release.o generated
exec - ${CC} ${CCLDFLAGS} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS} -o release release.o
exec - ${CC} ${CCLDFLAGS} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} ${LDFLAGS} -o release release.o
done release generated
make mprobe
make mprobe.sh
Expand Down
6 changes: 4 additions & 2 deletions src/cmd/INIT/cc.sol11.i386
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
: solaris.i386 cc wrapper for reasonable ansi C defaults and 32 bit : 2021-01-16 :
: solaris.i386 cc wrapper for reasonable ansi C defaults and 32 bit : 2021-01-17 :

HOSTTYPE=sol11.i386

Expand All @@ -13,4 +13,6 @@ case ${CC_EXPLICIT:=$CC} in
CC_EXPLICIT=cc
esac

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

$CC_EXPLICIT -m32 -xc99 "$@"
6 changes: 4 additions & 2 deletions src/cmd/INIT/cc.sol11.i386-64
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
: solaris.i386-64 cc wrapper for reasonable ansi C defaults and 64 bit : 2021-01-16 :
: solaris.i386-64 cc wrapper for reasonable ansi C defaults and 64 bit : 2021-01-17 :

HOSTTYPE=sol11.i386-64

Expand All @@ -13,4 +13,6 @@ case ${CC_EXPLICIT:=$CC} in
CC_EXPLICIT=cc
esac

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

$CC_EXPLICIT -m64 -xc99 "$@"
6 changes: 4 additions & 2 deletions src/cmd/INIT/cc.sol11.sparc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
: solaris.sparc cc wrapper for reasonable ansi C defaults and 32 bit : 2021-01-16 :
: solaris.sparc cc wrapper for reasonable ansi C defaults and 32 bit : 2021-01-17 :

HOSTTYPE=sol11.sparc

Expand All @@ -13,4 +13,6 @@ case ${CC_EXPLICIT:=$CC} in
CC_EXPLICIT=cc
esac

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

$CC_EXPLICIT -m32 -xc99 "$@"
6 changes: 4 additions & 2 deletions src/cmd/INIT/cc.sol11.sparc-64
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
: solaris.sparc-64 cc wrapper for reasonable ansi C defaults and 64 bit : 2021-01-16 :
: solaris.sparc-64 cc wrapper for reasonable ansi C defaults and 64 bit : 2021-01-17 :

HOSTTYPE=sol11.sparc-64

Expand All @@ -13,4 +13,6 @@ case ${CC_EXPLICIT:=$CC} in
CC_EXPLICIT=cc
esac

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

$CC_EXPLICIT -m64 -xc99 "$@"
77 changes: 34 additions & 43 deletions src/cmd/INIT/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,40 @@ case $CC in
*) export CC ;;
esac

# Add build type flags via KSH_RELFLAGS, which is used in src/cmd/ksh93/Mamfile.
# (Avoid using CCFLAGS; setting it would overwrite autodetected optimization flags.)
ksh_relflags=
case `git branch 2>/dev/null` in
'' | *\*\ [0-9]*.[0-9]*)
# If we're not on a git branch (tarball) or on a branch that starts
# with a number (release branch), then compile as a release version
ksh_relflags="${ksh_relflags:+$ksh_relflags }-D_AST_ksh_release" ;;
*) # Otherwise, add 8-character git commit hash if available, and if the working dir is clean
git_commit=`git status >/dev/null 2>&1 && git diff-index --quiet HEAD && git rev-parse --short=8 HEAD`
case $git_commit in
????????)
ksh_relflags="${ksh_relflags:+$ksh_relflags }-D_AST_git_commit=\\\"$git_commit\\\"" ;;
esac
unset git_commit ;;
esac
case $ksh_relflags in
?*) # add the extra flags as an argument to mamake
assign="${assign:+$assign }KSH_RELFLAGS=\"\$ksh_relflags\"" ;;
esac

# Hack to build on some systems that need an explicit link with libm due to a bug in the build system
case `uname` in
NetBSD | SunOS)
case " $LDFLAGS " in
*" -m "*)
;;
*) LDFLAGS="-lm${LDFLAGS:+ $LDFLAGS}"
export LDFLAGS
;;
esac
;;
esac

# grab action specific args

case $action in
Expand Down Expand Up @@ -5401,49 +5435,6 @@ license)# all work in $PACKAGESRC/LICENSES
;;

make|view)
# Add flags for build type
case `git branch 2>/dev/null` in
'' | *\*\ [0-9]*.[0-9]*)
# If we're not on a git branch (tarball) or on a branch that starts
# with a number (release branch), then compile as a release version
CCFLAGS="-D_AST_ksh_release${CCFLAGS:+ $CCFLAGS}" # prefix it to allow override with -U
export CCFLAGS
;;
*) # Otherwise, add 8-character git commit hash if available, and if the working dir is clean
git_commit=`git status >/dev/null 2>&1 && git diff-index --quiet HEAD && git rev-parse --short=8 HEAD`
case $git_commit in
????????)
CCFLAGS="-D_AST_git_commit=\\\"$git_commit\\\"${CCFLAGS:+ $CCFLAGS}"
export CCFLAGS
;;
esac
unset git_commit
;;
esac
# Hack to build on some systems that need an explicit link with libm due to a bug in the build system
case `uname` in
NetBSD | SunOS)
case " $LDFLAGS " in
*" -m "*)
;;
*) LDFLAGS="-lm${LDFLAGS:+ $LDFLAGS}"
export LDFLAGS
;;
esac
;;
esac
# Hack for Solaris gcc, which needs -D_XPG6 in C flags to not segfault
case `uname` in
SunOS) case "$CC, $CCFLAGS " in
*" -D_XPG6 "*)
;;
*gcc,*) CCFLAGS="-D_XPG6${CCFLAGS:+ $CCFLAGS}"
export CCFLAGS
;;
esac
;;
esac

cd $PACKAGEROOT
case $package in
'') lic="lib/package/*.lic"
Expand Down
7 changes: 4 additions & 3 deletions src/cmd/builtin/Mamfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ setv AS as
setv ASFLAGS
setv CC cc
setv mam_cc_FLAGS
setv KSH_RELFLAGS
setv CCFLAGS ${-debug-symbols?1?${mam_cc_DEBUG} -D_BLD_DEBUG?${mam_cc_OPTIMIZE}?}
setv CCLDFLAGS ${-strip-symbols?1?${mam_cc_LD_STRIP}??}
setv COTEMP $$
Expand Down Expand Up @@ -55,7 +56,7 @@ make FEATURE/pty implicit
meta FEATURE/pty features/%>FEATURE/% features/pty pty
make features/pty
done features/pty
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
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
done FEATURE/pty generated
make ${PACKAGE_ast_INCLUDE}/ast_time.h implicit
done ${PACKAGE_ast_INCLUDE}/ast_time.h
Expand All @@ -72,11 +73,11 @@ meta pty.o %.c>%.o pty.c pty
prev pty.c
setv CMD_STANDALONE -DCMD_STANDALONE="b_pty"
setv LICENSE -DLICENSE="since=2001,author=gsf+dgk"
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
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
done pty.o generated
bind -lutil dontcare
setv CMD_STANDALONE -DCMD_STANDALONE="b_pty"
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}
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}
done pty generated
make ${INSTALLROOT}/bin
exec - if silent test ! -d ${INSTALLROOT}/bin
Expand Down
Loading

0 comments on commit 580ff61

Please sign in to comment.