gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 3fa6512: BuildProgram: --cc option allows usin


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 3fa6512: BuildProgram: --cc option allows using custom C compiler
Date: Mon, 7 Oct 2019 08:57:08 -0400 (EDT)

branch: master
commit 3fa6512537ea1905583cf2b7dff45d174260c4c3
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    BuildProgram: --cc option allows using custom C compiler
    
    Until now `gcc' was hard-coded into BuildProgram, so a GCC that is in the
    search path was the only way to run BuildProgram. This would cause a crash
    cases when there is no `gcc' in the PATH.
    
    With this commit, BuildProgram has the new `--cc' option to let the user
    explicitly set the compiler. If `--cc' hasn't been used, then it will look
    into the `CC' and `GCC' environment variables and ultimately, if it can't
    find anything in them, it will use `gcc'. This gives the users much greater
    
    This was reported by Sebastián Luna Valero, while attempting to package
    Gnuastro for conda-forge.
---
 NEWS                         |  4 ++++
 THANKS                       |  1 +
 bin/buildprog/args.h         | 14 ++++++++++++++
 bin/buildprog/buildprog.c    |  5 +++--
 bin/buildprog/main.h         |  1 +
 bin/buildprog/ui.c           |  9 +++++++++
 bin/buildprog/ui.h           |  3 ++-
 doc/announce-acknowledge.txt |  1 +
 doc/gnuastro.texi            | 28 +++++++++++++++++++++++-----
 9 files changed, 58 insertions(+), 8 deletions(-)

diff --git a/NEWS b/NEWS
index 1a4e90c..c801b25 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,10 @@ See the end of the file for license conditions.
    --onedonstdout: when the output is one-dimensional, print the values on
      the standard output, not into a file.
 
+  BuildProgram:
+   --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.
+
   ConvertType:
    - New `viridis' colormap (value for the `--colormap' option). This is
      the default colormap of Python's Matplotlib, and is available in many
diff --git a/THANKS b/THANKS
index 0420e36..96f0efe 100644
--- a/THANKS
+++ b/THANKS
@@ -53,6 +53,7 @@ support in Gnuastro. The list is ordered alphabetically (by 
family name).
     Geoffry Krouchi                      address@hidden
     Floriane Leclercq                    address@hidden
     Alan Lefor                           address@hidden
+    Sebastián Luna Valero                address@hidden
     Guillaume Mahler                     address@hidden
     Juan Molina Tobar                    address@hidden
     Francesco Montanari                  address@hidden
diff --git a/bin/buildprog/args.h b/bin/buildprog/args.h
index 8607f4f..49d6c030 100644
--- a/bin/buildprog/args.h
+++ b/bin/buildprog/args.h
@@ -32,6 +32,20 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 struct argp_option program_options[] =
   {
     {
+      "cc",
+      UI_KEY_CC,
+      "STR",
+      0,
+      "Name of C compiler's executable.",
+      GAL_OPTIONS_GROUP_INPUT,
+      &p->cc,
+      GAL_TYPE_STRING,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
+    },
+
+    {
       "includedir",
       UI_KEY_INCLUDE,
       "STR",
diff --git a/bin/buildprog/buildprog.c b/bin/buildprog/buildprog.c
index ef706a8..0a29cd7 100644
--- a/bin/buildprog/buildprog.c
+++ b/bin/buildprog/buildprog.c
@@ -103,13 +103,14 @@ buildprog(struct buildprogparams *p)
       error(EXIT_FAILURE, 0, "%s: asprintf allocation", __func__);
 
   /* Write the full Libtool command into a string (to run afterwards). */
-  if( asprintf(&command, "%s -c \"%s %s %s%s --mode=link gcc %s %s "
+  if( asprintf(&command, "%s -c \"%s %s %s%s --mode=link %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" : "",
-               p->tag      ? "--tag="   : "",
+               p->tag      ? "--tag="  : "",
                p->tag      ? p->tag    : "",
+               p->cc,
                warning     ? warning   : "",
                p->debug    ? "-g"      : "",
                optimize    ? optimize  : "",
diff --git a/bin/buildprog/main.h b/bin/buildprog/main.h
index eb3ee1e..e5d5438 100644
--- a/bin/buildprog/main.h
+++ b/bin/buildprog/main.h
@@ -49,6 +49,7 @@ struct buildprogparams
   gal_list_str_t     *linkdir;    /* Libraries to link against.         */
   gal_list_str_t     *linklib;    /* Libraries to link against.         */
   char                    *la;    /* Libtool `.la' instead of default.  */
+  char                    *cc;    /* C compiler to use.                 */
 
   char                   *tag;    /* Libtool tag (programming language).*/
   char              *optimize;    /* Optimization level.                */
diff --git a/bin/buildprog/ui.c b/bin/buildprog/ui.c
index 6db0d66..8b106f9 100644
--- a/bin/buildprog/ui.c
+++ b/bin/buildprog/ui.c
@@ -284,6 +284,15 @@ ui_preparations(struct buildprogparams *p)
   if(p->cp.output==NULL)
     p->cp.output=gal_checkset_automatic_output(&p->cp, p->sourceargs->v,
                                                EXEEXT);
+
+  /* Set the C compiler. Later we can add a check to make sure that `cc' is
+     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->cc==NULL) p->cc="gcc";           /* Default: `gcc'.       */
+    }
 }
 
 
diff --git a/bin/buildprog/ui.h b/bin/buildprog/ui.h
index 0415117..5cbfc67 100644
--- a/bin/buildprog/ui.h
+++ b/bin/buildprog/ui.h
@@ -32,12 +32,13 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 /* Available letters for short options:
 
-   c e f i j k n p r s u v w x y z
+   e 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
 {
   /* With short-option version. */
+  UI_KEY_CC             = 'c',
   UI_KEY_INCLUDE        = 'I',
   UI_KEY_LINKDIR        = 'L',
   UI_KEY_LINKLIB        = 'l',
diff --git a/doc/announce-acknowledge.txt b/doc/announce-acknowledge.txt
index 1f9dc27..dc0de6f 100644
--- a/doc/announce-acknowledge.txt
+++ b/doc/announce-acknowledge.txt
@@ -1,6 +1,7 @@
 Alphabetically ordered list to acknowledge in the next release.
 
 Raúl Infante Sainz
+Sebastián Luna Valero
 
 
 
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 16a9e99..64b0505 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -1097,7 +1097,8 @@ Please take the time to have a look at the following 
essays and FAQs for a compl
 @cindex Linux
 @cindex GNU/Linux
 @cindex GNU C library
-@cindex GNU Compiler Collection
+@cindex GCC: GNU Compiler Collection
+@cindex GNU Compiler Collection (GCC)
 In short, the Linux kernel@footnote{In Unix-like operating systems, the kernel 
connects software and hardware worlds.} is built using the GNU C library 
(glibc) and GNU compiler collection (gcc).
 The Linux kernel software alone is just a means for other software to access 
the hardware resources, it is useless alone: to say ``running Linux'', is like 
saying ``driving your carburetor''.
 
@@ -17380,8 +17381,8 @@ When the unified product has a @code{main} function, 
this function is the produc
 When the product doesn't have a @code{main} function, the linker's product is 
a library and its exported functions can be linked to other executables (it has 
many entry points).
 @end enumerate
 
-@cindex GCC
-@cindex GNU Compiler Collection
+@cindex GCC: GNU Compiler Collection
+@cindex GNU Compiler Collection (GCC)
 The GNU Compiler Collection (or GCC for short) will do all three steps.
 So as a first example, from Gnuastro's source, go to @file{tests/lib/}.
 This directory contains the library tests, you can use these as some simple 
tutorials.
@@ -17476,8 +17477,10 @@ $ astbuildprog --onlybuild myprogram.c
 
 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.
 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.
+
 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.
 
@@ -17491,6 +17494,19 @@ When the @option{--quiet} option (see @ref{Operating 
mode options}) is not calle
 Once your program grows and you break it up into multiple files (which are 
much more easily managed with Make), you can use the linking flags of the 
non-quiet output in your @code{Makefile}.
 
 @table @option
+@item -c STR
+@itemx --cc=STR
+@cindex C compiler
+@cindex Compiler, C
+@cindex GCC: GNU Compiler Collection
+@cindex GNU Compiler Collection (GCC)
+C compiler to use for the compilation, if not given environment variables will 
be used as described in the next paragraph.
+If the compiler is in your systems's search path, you can simply give its 
name, for example @option{--cc=gcc}.
+If its not in your system's search path, you can give its full path, for 
example @option{--cc=/path/to/your/custom/cc}.
+
+If this option has no value after parsing the command-line and all 
configuration files (see @ref{Configuration file precedence}), then 
BuildProgram will look into the following environment variables in the given 
order @code{CC} and @code{GCC}.
+If they are also not defined, BuildProgram will ultimately default to the 
@command{gcc} command which is present in many systems (sometimes as a link to 
other compilers).
+
 @item -I STR
 @itemx --includedir=STR
 @cindex GNU CPP
@@ -17528,7 +17544,8 @@ See @ref{Linking} for a thorough introduction.
 @item -O INT/STR
 @itemx --optimize=INT/STR
 @cindex Optimization
-@cindex GNU Compiler Collection
+@cindex GCC: GNU Compiler Collection
+@cindex GNU Compiler Collection (GCC)
 Compiler optimization level: 0 (for no optimization, good debugging), 1, 2, 3 
(for the highest level of optimizations).
 From the GNU Compiler Collection (GCC) manual: ``Without any optimization 
option, the compiler's goal is to reduce the cost of compilation and to make 
debugging produce the expected results.
 Statements are independent: if you stop the program with a break point between 
statements, you can then assign a new value to any variable or change the 
program counter to any other statement in the function and get exactly the 
results you expect from the source code.
@@ -25021,7 +25038,8 @@ functions that don't define too many variables and 
whose only purpose is to
 run the lower-level functions in a specific order and with checks.
 
 @cindex Optimization flag
-@cindex GNU Compiler Collection
+@cindex GCC: GNU Compiler Collection
+@cindex GNU Compiler Collection (GCC)
 In general you can be very liberal in breaking up the functions into
 smaller parts, the GNU Compiler Collection (GCC) will automatically compile
 the functions as inline functions when the optimizations are turned on. So



reply via email to

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