[PATCH 1/3] build: handle standard LDFLAGS variable
This changes LFLAGS to the more standard LDFLAGS (while preserving backwards compatibility). It also adds the missing $(LDFLAGS) usage when linking `date`. Signed-off-by: Mike Frysinger <vapier@gentoo.org> --- Makefile | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index ab0f54b..625c6b2 100644 --- a/Makefile +++ b/Makefile @@ -224,6 +224,10 @@ GCC_DEBUG_FLAGS = -Dlint -g3 -O3 -fno-common -fstrict-aliasing \ CFLAGS= +# Linker flags. + +LDFLAGS= $(LFLAGS) + # If you want zic's -s option used when installing, uncomment the next line # ZFLAGS= -s @@ -338,10 +342,10 @@ version.h: 'static char const TZVERSION[]="tz$(VERSION)";' zdump: $(TZDOBJS) - $(CC) $(CFLAGS) $(LFLAGS) $(TZDOBJS) $(LDLIBS) -o $@ + $(CC) $(CFLAGS) $(LDFLAGS) $(TZDOBJS) $(LDLIBS) -o $@ zic: $(TZCOBJS) yearistype - $(CC) $(CFLAGS) $(LFLAGS) $(TZCOBJS) $(LDLIBS) -o $@ + $(CC) $(CFLAGS) $(LDFLAGS) $(TZCOBJS) $(LDLIBS) -o $@ yearistype: yearistype.sh cp yearistype.sh yearistype @@ -380,8 +384,8 @@ $(TZLIB): $(LIBOBJS) then ranlib $@ ; fi date: $(DATEOBJS) - $(CC) $(CFLAGS) date.o localtime.o asctime.o strftime.o \ - $(LDLIBS) -lc -o $@ + $(CC) $(CFLAGS) $(LDFLAGS) date.o localtime.o asctime.o \ + strftime.o $(LDLIBS) -lc -o $@ tzselect: tzselect.ksh sed \ -- 1.7.12
It's much more common to have `awk` available on the system than `nawk`. So default it that way. This also matches tzselect.ksh behavior. Signed-off-by: Mike Frysinger <vapier@gentoo.org> --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 625c6b2..000d3f4 100644 --- a/Makefile +++ b/Makefile @@ -235,7 +235,7 @@ zic= ./zic ZIC= $(zic) $(ZFLAGS) # The name of a Posix-compliant `awk' on your system. -AWK= nawk +AWK= awk # The path where SGML DTDs are kept. # The default is appropriate for Ubuntu. -- 1.7.12
In looking through tzselect, I can't see any functionality that isn't covered by the POSIX shell spec. Since we're modernizing, change this to use /bin/sh by default. Signed-off-by: Mike Frysinger <vapier@gentoo.org> --- Makefile | 4 ++-- tzselect.ksh => tzselect.sh | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) rename tzselect.ksh => tzselect.sh (98%) mode change 100644 => 100755 diff --git a/Makefile b/Makefile index 000d3f4..25110b8 100644 --- a/Makefile +++ b/Makefile @@ -283,7 +283,7 @@ LIBOBJS= localtime.o asctime.o difftime.o HEADERS= tzfile.h private.h NONLIBSRCS= zic.c zdump.c scheck.c ialloc.c NEWUCBSRCS= date.c strftime.c -SOURCES= $(HEADERS) $(LIBSRCS) $(NONLIBSRCS) $(NEWUCBSRCS) tzselect.ksh +SOURCES= $(HEADERS) $(LIBSRCS) $(NONLIBSRCS) $(NEWUCBSRCS) tzselect.sh MANS= newctime.3 newstrftime.3 newtzset.3 time2posix.3 \ tzfile.5 tzselect.8 zic.8 zdump.8 COMMON= Makefile @@ -387,7 +387,7 @@ date: $(DATEOBJS) $(CC) $(CFLAGS) $(LDFLAGS) date.o localtime.o asctime.o \ strftime.o $(LDLIBS) -lc -o $@ -tzselect: tzselect.ksh +tzselect: tzselect.sh sed \ -e 's|AWK=[^}]*|AWK=$(AWK)|g' \ -e 's|TZDIR=[^}]*|TZDIR=$(TZDIR)|' \ diff --git a/tzselect.ksh b/tzselect.sh old mode 100644 new mode 100755 similarity index 98% rename from tzselect.ksh rename to tzselect.sh index 9e8ceea..40134d8 --- a/tzselect.ksh +++ b/tzselect.sh @@ -1,4 +1,4 @@ -#! /bin/ksh +#! /bin/sh TZVERSION=see_Makefile @@ -9,8 +9,8 @@ TZVERSION=see_Makefile # Porting notes: # -# This script requires several features of the Korn shell. -# If your host lacks the Korn shell, +# This script requires several features of modern shells. +# If your host lacks such a shell, # you can use either of the following free programs instead: # # <a href=ftp://ftp.gnu.org/pub/gnu/> -- 1.7.12
On Sat, 27 Oct 2012, Mike Frysinger wrote:
In looking through tzselect, I can't see any functionality that isn't covered by the POSIX shell spec. Since we're modernizing, change this to use /bin/sh by default.
The "select" builtin is not POSIX. -- Joseph S. Myers jsm@polyomino.org.uk
On Saturday 27 October 2012 04:29:57 Joseph S. Myers wrote:
On Sat, 27 Oct 2012, Mike Frysinger wrote:
In looking through tzselect, I can't see any functionality that isn't covered by the POSIX shell spec. Since we're modernizing, change this to use /bin/sh by default.
The "select" builtin is not POSIX.
hmm, so it isn't. would people be against re-using $@ and manually outputting the list ? here's a quick hack. it could be made simpler if we set clear limits on what is fair game ... would be SuSv3 be asking too much ? -mike diff --git a/tzselect.sh b/tzselect.sh index 40134d8..73fa1ff 100755 --- a/tzselect.sh +++ b/tzselect.sh @@ -82,6 +82,21 @@ case $(echo 1 | (select x in x; do break; done) 2>/dev/null) in esac +# Set up the continent choices. +set -- \ + Africa \ + Americas \ + Antarctica \ + 'Arctic Ocean' \ + Asia \ + 'Atlantic Ocean' \ + Australia \ + Europe \ + 'Indian Ocean' \ + 'Pacific Ocean' \ + 'none - I want to specify the time zone using the Posix TZ format.' + + # Begin the main loop. We come back here if the user wants to retry. while @@ -97,30 +112,36 @@ while echo >&2 'Please select a continent or ocean.' - select continent in \ - Africa \ - Americas \ - Antarctica \ - 'Arctic Ocean' \ - Asia \ - 'Atlantic Ocean' \ - Australia \ - Europe \ - 'Indian Ocean' \ - 'Pacific Ocean' \ - 'none - I want to specify the time zone using the Posix TZ format.' + while :; do + + c=1 + while [ $c -le $# ] do - case $continent in - '') - echo >&2 'Please enter a number in range.';; - ?*) + [ $c -lt 10 ] && b=' ' || b= + eval echo \""$b$c) \${$c}"\" >&2 + c=$(expr $c + 1) + done + echo '#?' | tr '\n' ' ' + read continent + case $(echo "$continent" | tr -d '[0-9]') in + '') + if [ $continent -gt 0 -a $continent -le $# ]; then + eval continent=\""\${$continent}"\" case $continent in Americas) continent=America;; *' '*) continent=$(expr "$continent" : '\([^ ]*\)') esac break - esac + else + echo >&2 'Please enter a number in range.' + fi + ;; + *) + echo >&2 'Please enter a valid number.' + esac + done + case $continent in '') exit 1;;
Mike Frysinger <vapier@gentoo.org> writes:
+ case $(echo "$continent" | tr -d '[0-9]') in case $continent in ''|*[!0-9]*) + echo >&2 'Please enter a valid number.'
Andreas. -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
On 10/27/2012 02:06 AM, Mike Frysinger wrote:
+ eval echo \""$b$c) \${$c}"\" >&2
That looks pretty tricky. How about if we just default to Bash instead? Pretty much everybody has Bash if they don't have ksh, and if they're on a platform that's likely to want to run this script. Another possibility is an early part of the script that looks for a shell where 'select' works, and then reexecutes the script with that shell.
On Saturday 27 October 2012 15:29:43 Paul Eggert wrote:
On 10/27/2012 02:06 AM, Mike Frysinger wrote:
+ eval echo \""$b$c) \${$c}"\" >&2
That looks pretty tricky.
How about if we just default to Bash instead? Pretty much everybody has Bash if they don't have ksh, and if they're on a platform that's likely to want to run this script.
Another possibility is an early part of the script that looks for a shell where 'select' works, and then reexecutes the script with that shell.
i can live with bash -mike
On 10/27/2012 12:35 PM, Mike Frysinger wrote:
i can live with bash
OK, how about this?
From 6daf83cd406f0c5453d53a65d663e20668491381 Mon Sep 17 00:00:00 2001 From: Paul Eggert <eggert@cs.ucla.edu> Date: Sat, 27 Oct 2012 13:54:13 -0700 Subject: [PATCH] Have tzselect.ksh use Bash by default; this can be overridden.
* Makefile (KSHELL): New macro. (tzselect): Use it. * tzselect.ksh: Use "#!/bin/bash", not "#! /bin/ksh". The Makefile can override this. No need for a space after "!'; that was put in years ago only because of an urban legend. --- Makefile | 5 +++++ tzselect.ksh | 31 ++++++++++++------------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 8b539c1..c8150ba 100644 --- a/Makefile +++ b/Makefile @@ -238,6 +238,10 @@ ZIC= $(zic) $(ZFLAGS) # The name of a Posix-compliant `awk' on your system. AWK= awk +# The full path name of a Posix-compliant shell that supports the Korn shell's +# 'select' statement, as an extension. These days, Bash is the most popular. +KSHELL= /bin/bash + # The path where SGML DTDs are kept. # The default is appropriate for Ubuntu. SGML_TOPDIR= /usr @@ -389,6 +393,7 @@ date: $(DATEOBJS) tzselect: tzselect.ksh sed \ + -e 's|#!/bin/bash|#!$(KSHELL)|g' \ -e 's|AWK=[^}]*|AWK=$(AWK)|g' \ -e 's|TZDIR=[^}]*|TZDIR=$(TZDIR)|' \ -e 's|\(TZVERSION\)=.*|\1=tz$(VERSION)|' \ diff --git a/tzselect.ksh b/tzselect.ksh index 9e8ceea..4fe5d02 100644 --- a/tzselect.ksh +++ b/tzselect.ksh @@ -1,4 +1,4 @@ -#! /bin/ksh +#!/bin/bash TZVERSION=see_Makefile @@ -9,29 +9,22 @@ TZVERSION=see_Makefile # Porting notes: # -# This script requires several features of the Korn shell. -# If your host lacks the Korn shell, -# you can use either of the following free programs instead: -# -# <a href=ftp://ftp.gnu.org/pub/gnu/> -# Bourne-Again shell (bash) -# </a> +# This script requires a Posix-like shell with the extension of a +# 'select' statement. The 'select' statement was introduced in the +# Korn shell and is available in Bash and other shell implementations. +# If your host lacks both Bash and the Korn shell, you can get their +# source from one of these locations: # -# <a href=ftp://ftp.cs.mun.ca/pub/pdksh/pdksh.tar.gz> -# Public domain ksh -# </a> +# Bash <http://www.gnu.org/software/bash/bash.html> +# Korn Shell <http://www.kornshell.com/> +# Public Domain Korn Shell <http://www.cs.mun.ca/~michael/pdksh/> # # This script also uses several features of modern awk programs. -# If your host lacks awk, or has an old awk that does not conform to Posix.2, +# If your host lacks awk, or has an old awk that does not conform to Posix, # you can use either of the following free programs instead: # -# <a href=ftp://ftp.gnu.org/pub/gnu/> -# GNU awk (gawk) -# </a> -# -# <a href=ftp://ftp.whidbey.net/pub/brennan/> -# mawk -# </a> +# Gawk (GNU awk) <http://www.gnu.org/software/gawk/> +# mawk <http://invisible-island.net/mawk/> # Specify default values for environment variables if they are unset. -- 1.7.9.5
On Sat, Oct 27, 2012 at 12:29:43PM -0700, Paul Eggert wrote:
How about if we just default to Bash instead?
I'd prefer not to default to bash. However, there are workarounds, such as moving part of processing to a system that has bash. In case you're interested, here's why I prefer not doing bashisms: My bias comes from trying to use multiple platforms, not just Linux, and having repeated problems with what we call the gnu hairball of dependency hell. bash is OK if you're on a Linux system where you need, and have, the entire gnu hairball already as part of your install. Building bash requires too much additional hairball on *bsd systems, so we most often do not. Sometimes, the systems don't have the horsepower to complete the hairball in a reasonable time. Importing pre-built packages then sometimes requires cross-compiling, which brings its own pitfalls. Even on those that can build the hairball, we often don't want the parts around after the build, as upgrades across large and unauditable dependencies like the notorious gettext are often quite problematic. We thus prefer standard /bin/sh use via the likes of ksh instead in our scripts. That said, we also run Linux systems where package maintainer teams have embraced the hairball and have polished it well, so there are workarounds if bashisms must be used. Richard
On 10/27/2012 02:38 PM, SM wrote:
Most platforms have /bin/sh. Bash is not in base on BSD.
Sorry, I guess I should have written something more like "These days Bash is installed on more systems than the Korn Shell is", or something like that. A plain POSIX shell is not an option here, since the script uses 'select' and it's too much of a pain to change that.
[Resend, had a bug in my folder-hook setting my from address] On Sat, Oct 27, 2012 at 12:29:43PM -0700, Paul Eggert wrote:
How about if we just default to Bash instead?
I'd prefer not to default to bash. However, there are workarounds, such as moving part of processing to a system that has bash. In case you're interested, here's why I prefer not doing bashisms: My bias comes from trying to use multiple platforms, not just Linux, and having repeated problems with what we call the gnu hairball of dependency hell. bash is OK if you're on a Linux system where you need, and have, the entire gnu hairball already as part of your install. Building bash requires too much additional hairball on *bsd systems, so we most often do not. Sometimes, the systems don't have the horsepower to complete the hairball in a reasonable time. Importing pre-built packages then sometimes requires cross-compiling, which brings its own pitfalls. Even on those that can build the hairball, we often don't want the parts around after the build, as upgrades across large and unauditable dependencies like the notorious gettext are often quite problematic. We thus prefer standard /bin/sh use via the likes of ksh instead in our scripts. That said, we also run Linux systems where package maintainer teams have embraced the hairball and have polished it well, so there are workarounds if bashisms must be used. Richard
On Oct 27, 2012, at 3:27 PM, Richard Johnson <rjohnson+tz@ucar.edu> wrote:
We thus prefer standard /bin/sh use via the likes of ksh instead in our scripts.
Unfortunately, tzselect isn't a standard /bin/sh script; to quote an earlier message:
The "select" builtin is not POSIX.
and the script uses "select", so, whilst it can be a /bin/ksh script or a /bin/bash script, it would have to be changed to be a /bin/sh script.
Richard Johnson <rjohnson+tz@ucar.edu> writes:
Building bash requires too much additional hairball on *bsd systems, so we most often do not.
If cc and make is too much hairball, then you won't get far on *bsd systems either. Andreas. -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
On Sat, 27 Oct 2012, Paul Eggert wrote:
On 10/27/2012 02:06 AM, Mike Frysinger wrote:
+ eval echo \""$b$c) \${$c}"\" >&2
That looks pretty tricky.
Yes, and there's no reason for $b$c to be expanded twice. But it's easy to make it clearer: eval continent=\"\${$c}\" echo "$b$c) ${continent}" >&2
How about if we just default to Bash instead?
If portable /bin/sh is not feasible, then please use the intersection of ksh and bash syntax, and make it easy for the choice between ksh and bash to be made at install time. (I have a minor preference for ksh over bash, because it's more likely to be available on non-linux systems, but if the choice is configurable then that's no big deal.) --apb (Alan Barrett)
On 10/28/2012 12:15 AM, Alan Barrett wrote:
please use the intersection of ksh and bash syntax, and make it easy for the choice between ksh and bash to be made at install time
Yes, that's the basic idea of the patch in <http://mm.icann.org/pipermail/tz/2012-October/018410.html>.
On Sun, 28 Oct 2012, Paul Eggert wrote:
On 10/28/2012 12:15 AM, Alan Barrett wrote:
please use the intersection of ksh and bash syntax, and make it easy for the choice between ksh and bash to be made at install time
Yes, that's the basic idea of the patch in <http://mm.icann.org/pipermail/tz/2012-October/018410.html>.
Thanks. That looks OK. --apb (Alan Barrett)
Thanks, I pushed the following slightly-more-elaborate patch. * Makefile (LDFLAGS): Rename from LFLAGS, with backwards compatibility. All uses changed. Suggested by Mike Frysinger in <http://mm.icann.org/pipermail/tz/2012-October/018396.html>. (zdump, zic, date): Use $(CC) -o $@ ... rather than $(CC) ... -o $@, for portability to strict older POSIX hosts. ($(TZLIB)): Don't use [ ... -o ... ], as it's not portable. --- Makefile | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 19616ef..8b539c1 100644 --- a/Makefile +++ b/Makefile @@ -224,6 +224,11 @@ GCC_DEBUG_FLAGS = -Dlint -g3 -O3 -fno-common -fstrict-aliasing \ CFLAGS= +# Linker flags. Default to $(LFLAGS) for backwards compatibility +# to tzcode2012h and earlier. + +LDFLAGS= $(LFLAGS) + # If you want zic's -s option used when installing, uncomment the next line # ZFLAGS= -s @@ -338,10 +343,10 @@ version.h: 'static char const TZVERSION[]="tz$(VERSION)";' zdump: $(TZDOBJS) - $(CC) $(CFLAGS) $(LFLAGS) $(TZDOBJS) $(LDLIBS) -o $@ + $(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(TZDOBJS) $(LDLIBS) zic: $(TZCOBJS) yearistype - $(CC) $(CFLAGS) $(LFLAGS) $(TZCOBJS) $(LDLIBS) -o $@ + $(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(TZCOBJS) $(LDLIBS) yearistype: yearistype.sh cp yearistype.sh yearistype @@ -376,12 +381,11 @@ zones: $(REDO) $(TZLIB): $(LIBOBJS) -mkdir $(TOPDIR) $(LIBDIR) ar ru $@ $(LIBOBJS) - if [ -x /usr/ucb/ranlib -o -x /usr/bin/ranlib ] ; \ + if [ -x /usr/ucb/ranlib ] || [ -x /usr/bin/ranlib ]; \ then ranlib $@ ; fi date: $(DATEOBJS) - $(CC) $(CFLAGS) date.o localtime.o asctime.o strftime.o \ - $(LDLIBS) -lc -o $@ + $(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(DATEOBJS) $(LDLIBS) tzselect: tzselect.ksh sed \ -- 1.7.9.5
participants (9)
-
Alan Barrett -
Andreas Schwab -
Guy Harris -
Joseph S. Myers -
Mike Frysinger -
Paul Eggert -
Richard Johnson -
Richard Johnson -
SM