Add getenv macro, use instead of $(echo $HOME) for defauls
authorPanu Matilainen <pmatilai@redhat.com>
Fri, 16 Jan 2009 07:09:40 +0000 (09:09 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Fri, 16 Jan 2009 07:09:40 +0000 (09:09 +0200)
- inspired by http://lists.rpm.org/pipermail/rpm-maint/2009-January/002332.html

lib/rpmrc.c
macros.in
rpmio/macro.c

index f478a24..b7fdd2c 100644 (file)
@@ -475,7 +475,7 @@ static void setDefaults(void)
     addMacro(NULL, "_preScriptEnvironment",NULL, prescriptenviron,RMIL_DEFAULT);
 
     addMacroDefault("_topdir",
-               "/usr/src/packages",            "%(echo $HOME)/rpmbuild");
+               "/usr/src/packages",            "%{getenv:HOME}/rpmbuild");
     addMacroDefault("_tmppath",
                LOCALSTATEDIR "/tmp",           "%{_var}/tmp");
     addMacroDefault("_dbpath",
index c3c5025..c597399 100644 (file)
--- a/macros.in
+++ b/macros.in
@@ -229,7 +229,7 @@ package or when debugging this package.\
 %_tmppath              %{_var}/tmp
 
 #      Path to top of build area.
-%_topdir               %(echo $HOME)/rpmbuild
+%_topdir               %{getenv:HOME}/rpmbuild
 
 #      The path to the unzip executable (legacy, use %{__unzip} instead).
 %_unzipbin             %{__unzip}
index afe41cb..c9b6259 100644 (file)
@@ -983,6 +983,8 @@ doFoo(MacroBuf mb, int negate, const char * f, size_t fn,
             break;
        }
        b = be;
+    } else if (STREQ("getenv", f, fn)) {
+       b = getenv(buf);
     } else if (STREQ("S", f, fn)) {
        for (b = buf; (c = *b) && risdigit(c);)
            b++;
@@ -1253,6 +1255,7 @@ expandMacro(MacroBuf mb)
            STREQ("uncompress", f, fn) ||
            STREQ("url2path", f, fn) ||
            STREQ("u2p", f, fn) ||
+           STREQ("getenv", f, fn) ||
            STREQ("S", f, fn) ||
            STREQ("P", f, fn) ||
            STREQ("F", f, fn)) {