gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master 1d4043f: BuildProgram: reading LDFLAGS and CPP


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 1d4043f: BuildProgram: reading LDFLAGS and CPPFLAGS env for customization
Date: Mon, 14 Oct 2019 09:43:17 -0400 (EDT)

branch: master
commit 1d4043f333efca15f77921f5b36403bf03e98439
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    BuildProgram: reading LDFLAGS and CPPFLAGS env for customization
    
    Until now, BuildProgram's compilation was only configured through options
    (and just recently the `CC' and `GCC' environment variables). But in some
    scenarios, the user may want better control of the build and the default
    `-L' and `-I' options of BuildProgram (same as the linking and include
    options of the C compiler) may not be enough.
    
    We recently came up with such a scenario when trying to build Gnuastro
    through Conda on macOS. It added several linking flags through `-Wl' that
    BuildProgram ignores.
    
    With this commit, by default BuildProgram will use the `CPPFLAGS' and
    `LDFLAGS' environment variables also. But their checking can be disabled
    with the new `--noenv' option.
---
 NEWS                      |  4 ++++
 bin/buildprog/Makefile.am |  2 ++
 bin/buildprog/args.h      | 14 ++++++++++++++
 bin/buildprog/buildprog.c | 12 +++++++++++-
 bin/buildprog/main.h      |  1 +
 bin/buildprog/ui.c        |  8 ++++++--
 bin/buildprog/ui.h        |  3 ++-
 doc/gnuastro.texi         | 19 ++++++++++++++++---
 8 files changed, 56 insertions(+), 7 deletions(-)

diff --git a/NEWS b/NEWS
index 40b9cf8..ae4a2ed 100644
--- a/NEWS
+++ b/NEWS
@@ -12,8 +12,11 @@ See the end of the file for license conditions.
      the standard output, not into a file.
 
   BuildProgram:
+   - Will use common environment variables like LDFLAGS, CPPFLAGS and CC to
+     help in customizing the build of your program.
    --cc: custom C compiler to use. Until now, `gcc' was hard-coded into the
      source and there was no way to choose a custom C compiler.
+   --noenv: With this option, no environment variables will be read.
 
   ConvertType:
    - New `viridis' colormap (value for the `--colormap' option). This is
@@ -54,6 +57,7 @@ See the end of the file for license conditions.
   bug #56747: ConvertType's SLS colormap has black pixels which should be 
orange.
   bug #56754: Wrong sigma clipping output when many values are equal.
   bug #56999: Compilation error on macOS 10.9 not recognizing AT_FDCWD.
+  bug #57057: BuildProgram not using environment LDFLAGS or CPPFLAGS.
 
 
 
diff --git a/bin/buildprog/Makefile.am b/bin/buildprog/Makefile.am
index e8ea17d..fd3f917 100644
--- a/bin/buildprog/Makefile.am
+++ b/bin/buildprog/Makefile.am
@@ -87,6 +87,8 @@ astbuildprog.conf: 
$(top_srcdir)/bin/buildprog/astbuildprog.conf.in
            echo " linkdir $$v" >> $@;                 \
          fi;                                          \
        done
+       echo "# Build-time LDFLAGS: $(LDFLAGS)" >> $@
+       echo "# Build-time CPPFLAGS: $(CPPFLAGS)" >> $@
 
 
 
diff --git a/bin/buildprog/args.h b/bin/buildprog/args.h
index 49d6c030..87872e9 100644
--- a/bin/buildprog/args.h
+++ b/bin/buildprog/args.h
@@ -115,6 +115,20 @@ struct argp_option program_options[] =
       GAL_OPTIONS_NOT_SET
     },
 
+    {
+      "noenv",
+      UI_KEY_NOENV,
+      0,
+      0,
+      "No env. (e.g., LDFLAGS or CPPFLAGS) in build.",
+      GAL_OPTIONS_GROUP_INPUT,
+      &p->noenv,
+      GAL_OPTIONS_NO_ARG_TYPE,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
+    },
+
 
 
 
diff --git a/bin/buildprog/buildprog.c b/bin/buildprog/buildprog.c
index 0a29cd7..8a67871 100644
--- a/bin/buildprog/buildprog.c
+++ b/bin/buildprog/buildprog.c
@@ -75,6 +75,7 @@ buildprog(struct buildprogparams *p)
      rest are arguments to be run later. */
   int retval;
   char *fullla;
+  char *ldflags=NULL, *cppflags=NULL;
   char *command, *optimize=NULL, *warning=NULL;
   char *include   = buildprog_as_one_string("-I", p->include);
   char *linkdir   = buildprog_as_one_string("-L", p->linkdir);
@@ -88,6 +89,13 @@ buildprog(struct buildprogparams *p)
       printf("---------------------------------\n");
     }
 
+  /* If environment should be read, read it. */
+  if(p->noenv==0)
+    {
+      ldflags=getenv("LDFLAGS");
+      cppflags=getenv("CPPFLAGS");
+    }
+
   /* Compiler options with values: */
   if(p->warning)
     if( asprintf(&warning,  "-W%s", p->warning)<0 )
@@ -104,7 +112,7 @@ buildprog(struct buildprogparams *p)
 
   /* Write the full Libtool command into a string (to run afterwards). */
   if( asprintf(&command, "%s -c \"%s %s %s%s --mode=link %s %s %s "
-               "%s %s %s %s %s -I%s %s -o %s\"",
+               "%s %s %s %s %s %s %s -I%s %s -o %s\"",
                GAL_CONFIG_GNULIBTOOL_SHELL,
                GAL_CONFIG_GNULIBTOOL_EXEC,
                p->cp.quiet ? "--quiet" : "",
@@ -114,7 +122,9 @@ buildprog(struct buildprogparams *p)
                warning     ? warning   : "",
                p->debug    ? "-g"      : "",
                optimize    ? optimize  : "",
+               cppflags    ? cppflags  : "",
                include     ? include   : "",
+               ldflags     ? ldflags   : "",
                linkdir     ? linkdir   : "",
                p->sourceargs->v,
                linklib     ?linklib    : "",
diff --git a/bin/buildprog/main.h b/bin/buildprog/main.h
index e5d5438..0a43dc0 100644
--- a/bin/buildprog/main.h
+++ b/bin/buildprog/main.h
@@ -50,6 +50,7 @@ struct buildprogparams
   gal_list_str_t     *linklib;    /* Libraries to link against.         */
   char                    *la;    /* Libtool `.la' instead of default.  */
   char                    *cc;    /* C compiler to use.                 */
+  uint8_t               noenv;
 
   char                   *tag;    /* Libtool tag (programming language).*/
   char              *optimize;    /* Optimization level.                */
diff --git a/bin/buildprog/ui.c b/bin/buildprog/ui.c
index 8b106f9..83e2ef4 100644
--- a/bin/buildprog/ui.c
+++ b/bin/buildprog/ui.c
@@ -289,8 +289,12 @@ ui_preparations(struct buildprogparams *p)
      actually in the PATH. */
   if(p->cc==NULL)
     {                                        /* No C compiler chosen. */
-      p->cc=getenv("CC");                    /* First check for `CC'. */
-      if(p->cc==NULL) p->cc=getenv("GCC");   /* Then check for `GCC'. */
+      if(p->noenv==0)
+        {
+          p->cc=getenv("CC");                /* First check for `CC'. */
+          if(p->cc==NULL)
+            p->cc=getenv("GCC");             /* Then check for `GCC'. */
+        }
       if(p->cc==NULL) p->cc="gcc";           /* Default: `gcc'.       */
     }
 }
diff --git a/bin/buildprog/ui.h b/bin/buildprog/ui.h
index 5cbfc67..53d9f64 100644
--- a/bin/buildprog/ui.h
+++ b/bin/buildprog/ui.h
@@ -32,7 +32,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 /* Available letters for short options:
 
-   e f i j k n p r s u v w x y z
+   f i j k n p r s u v w x y z
    A B C E G H J Q R X Y
 */
 enum option_keys_enum
@@ -49,6 +49,7 @@ enum option_keys_enum
   UI_KEY_TAG            = 't',
   UI_KEY_DETELECOMPILED = 'd',
   UI_KEY_LA             = 'a',
+  UI_KEY_NOENV          = 'e',
 
   /* Only with long version (start with a value 1000, the rest will be set
      automatically). */
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 233ba84..693ed79 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -17497,14 +17497,18 @@ $ astbuildprog --onlybuild myprogram.c
 @end example
 
 If BuildProgram is to run, it needs a C programming language source file as 
input.
-By default it will compile and link the program to build the a final 
executable file and run it.
-The C compiler can be chosen with the @option{--cc} option, or environment 
variables, please see the description of @option{--cc} for more.
+By default it will compile and link the given source into a final executable 
program and run it.
 The built executable name can be set with the optional @option{--output} 
option.
-When no output name is set, BuildProgram will use Gnuastro's @ref{Automatic 
output}, and remove the suffix of the input and use that as the output name.
+When no output name is set, BuildProgram will use Gnuastro's @ref{Automatic 
output} system to remove the suffix of the input source file (usually 
@file{.c}) and use the resulting name as the built program name.
 
 For the full list of options that BuildProgram shares with other Gnuastro 
programs, see @ref{Common options}.
 You may also use Gnuastro's @ref{Configuration files} to specify other 
libraries/headers to use for special directories and not have to type them in 
every time.
 
+The C compiler can be chosen with the @option{--cc} option, or environment 
variables, please see the description of @option{--cc} for more.
+The two common @code{LDFLAGS} and @code{CPPFLAGS} environment variables are 
also checked and used in the build by default.
+Using environment variables can be disabled with the @option{--noenv} option.
+Just note that BuildProgram also keeps the important flags in these 
environment variables in its configuration file, so in many cases, when you 
needed them to build Gnuastro, you won't need them in BuildProgram.
+
 The first argument is considered to be the C source file that must be compiled 
and linked.
 Any other arguments (non-option tokens on the command-line) will be passed 
onto the program when BuildProgram wants to run it.
 Recall that by default BuildProgram will run the program after building it.
@@ -17614,6 +17618,15 @@ Use the given @file{.la} file (Libtool control file) 
instead of the one that was
 The Libtool control file keeps all the necessary information for building and 
linking a program with a library built by Libtool.
 The default @file{prefix/lib/libgnuastro.la} keeps all the information 
necessary to build a program using the Gnuastro library gathered during 
configure time (see @ref{Installation directory} for prefix).
 This option is useful when you prefer to use another Libtool control file.
+
+@item -e
+@itemx --noenv
+@cindex @code{CC}
+@cindex @code{GCC}
+@cindex @code{LDFLAGS}
+@cindex @code{CPPFLAGS}
+Don't use environment variables in the build, just use the values given to the 
options.
+As described above, environment variables like @code{CC}, @code{GCC}, 
@code{LDFLAGS},  @code{CPPFLAGS} will be read by default and used in the build 
if they have been defined.
 @end table
 
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]