[pacman-dev] [PATCH] makepkg: make in-place sed portable

Kevin Barry barryk at gmail.com
Sun Apr 26 10:59:34 EDT 2009


Could the variable point to the full path (/usr/bin/sed)? It's quiet
possible for a Mac user to also install GNU/sed and put it in their
path before BSD sed to avoid compiling issues with other programs.

On Sun, Apr 26, 2009 at 10:22 AM, Dan McGee <dpmcgee at gmail.com> wrote:
> On Sun, Apr 26, 2009 at 6:13 AM, Allan McRae <allan at archlinux.org> wrote:
>> Do a sed replacement in-place is not very portable.  On Mac OSX and
>> BSDs, the syntax is "sed -i ''" where as with GNU sed the command is
>> "sed -i''" or just "sed -i".  This patch detects which command should
>> be used during configure.
>>
>> Credit to Kevin Barry who researched this issue and provided a patch
>> to work around this using temporary backup files.
>>
>> Signed-off-by: Allan McRae <allan at archlinux.org>
> Signed-off-by: Dan McGee <dan at archlinux.org>
>
> Of course I didn't test it too extensively, but the concept looks just fine.
>
>> ---
>>  configure.ac          |    5 +++++
>>  scripts/Makefile.am   |    1 +
>>  scripts/makepkg.sh.in |    4 ++--
>>  3 files changed, 8 insertions(+), 2 deletions(-)
>>
>> diff --git a/configure.ac b/configure.ac
>> index 5dcbe79..a83d5e4 100644
>> --- a/configure.ac
>> +++ b/configure.ac
>> @@ -180,9 +180,11 @@ GCC_GNU89_INLINE_CC
>>
>>  # Host-dependant definitions
>>  SIZECMD="stat -c %s"
>> +SEDINPLACE="sed -i"
>>  case "${host_os}" in
>>        *bsd*)
>>                SIZECMD="stat -f %z"
>> +               SEDINPLACE="sed -i ''"
>>                ;;
>>        cygwin*)
>>                host_os_cygwin=yes
>> @@ -191,12 +193,14 @@ case "${host_os}" in
>>        darwin*)
>>                host_os_darwin=yes
>>                SIZECMD="/usr/bin/stat -f %z"
>> +               SEDINPLACE="sed -i ''"
>>                ;;
>>  esac
>>
>>  AM_CONDITIONAL([CYGWIN], test "x$host_os_cygwin" = "xyes")
>>  AM_CONDITIONAL([DARWIN], test "x$host_os_darwin" = "xyes")
>>  AC_SUBST(SIZECMD)
>> +AC_SUBST(SEDINPLACE)
>>
>>  # Check for architecture, used in default makepkg.conf
>>  # (Note single space left after CARCHFLAGS)
>> @@ -356,6 +360,7 @@ ${PACKAGE_NAME}:
>>     Architecture flags     : ${CARCHFLAGS}
>>     Host Type              : ${CHOST}
>>     Filesize command       : ${SIZECMD}
>> +    In-place sed command   : ${SEDINPLACE}
>>
>>     libalpm version        : ${LIB_VERSION}
>>     libalpm version info   : ${LIB_VERSION_INFO}
>> diff --git a/scripts/Makefile.am b/scripts/Makefile.am
>> index 5a2b780..5d65653 100644
>> --- a/scripts/Makefile.am
>> +++ b/scripts/Makefile.am
>> @@ -41,6 +41,7 @@ edit = sed \
>>        -e 's|@DBEXT[@]|$(DBEXT)|g' \
>>        -e 's|@BUILDSCRIPT[@]|$(BUILDSCRIPT)|g' \
>>        -e 's|@SIZECMD[@]|$(SIZECMD)|g' \
>> +       -e 's|@SEDINPLACE[@]|$(SEDINPLACE)|g' \
>>        -e 's|@configure_input[@]|Generated from $@.in; do not edit by hand.|g'
>>
>>  ## All the scripts depend on Makefile so that they are rebuilt when the
>> diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
>> index c97eff2..ca25fbb 100644
>> --- a/scripts/makepkg.sh.in
>> +++ b/scripts/makepkg.sh.in
>> @@ -1171,8 +1171,8 @@ devel_update() {
>>        if [ -n "$newpkgver" ]; then
>>                if [ "$newpkgver" != "$pkgver" ]; then
>>                        if [ -f "./$BUILDSCRIPT" ]; then
>> -                               sed -i "s/^pkgver=[^ ]*/pkgver=$newpkgver/" "./$BUILDSCRIPT"
>> -                               sed -i "s/^pkgrel=[^ ]*/pkgrel=1/" "./$BUILDSCRIPT"
>> +                               @SEDINPLACE@ "s/^pkgver=[^ ]*/pkgver=$newpkgver/" "./$BUILDSCRIPT"
>> +                               @SEDINPLACE@ "s/^pkgrel=[^ ]*/pkgrel=1/" "./$BUILDSCRIPT"
>>                                source "$BUILDSCRIPT"
>>                        fi
>>                fi
>> --
>> 1.6.2.4
>>
>> _______________________________________________
>> pacman-dev mailing list
>> pacman-dev at archlinux.org
>> http://www.archlinux.org/mailman/listinfo/pacman-dev
>>
> _______________________________________________
> pacman-dev mailing list
> pacman-dev at archlinux.org
> http://www.archlinux.org/mailman/listinfo/pacman-dev
>


More information about the pacman-dev mailing list