[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 9272322 2/2: BuildProgram with Debug, Optimiza
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 9272322 2/2: BuildProgram with Debug, Optimization and Warning options |
Date: |
Mon, 22 May 2017 09:18:38 -0400 (EDT) |
branch: master
commit 927232280386a13210174de2b4630916e6b5cc5f
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>
BuildProgram with Debug, Optimization and Warning options
Besides raw compilation, it is sometimes necessary to write compile with
debugging or optimization. Also, it is good practice to allow for warning
messages. So BuildProgram now accepts these options and will pass them onto
Libtool (and the compiler).
---
bin/buildprog/args.h | 39 +++++++++++++++++++++++++++++++++++++++
bin/buildprog/astbuildprog.conf | 5 +++++
bin/buildprog/buildprog.c | 24 +++++++++++++++++++-----
bin/buildprog/main.h | 4 ++++
bin/buildprog/ui.h | 7 +++++--
doc/gnuastro.texi | 39 +++++++++++++++++++++++++++++++++++++++
6 files changed, 111 insertions(+), 7 deletions(-)
diff --git a/bin/buildprog/args.h b/bin/buildprog/args.h
index be00c71..6d4f9fd 100644
--- a/bin/buildprog/args.h
+++ b/bin/buildprog/args.h
@@ -75,6 +75,45 @@ struct argp_option program_options[] =
{
+ "debug",
+ UI_KEY_DEBUG,
+ 0,
+ 0,
+ "Debugging information in compiled binary.",
+ GAL_OPTIONS_GROUP_OUTPUT,
+ &p->debug,
+ GAL_OPTIONS_NO_ARG_TYPE,
+ GAL_OPTIONS_RANGE_ANY,
+ GAL_OPTIONS_NOT_MANDATORY,
+ GAL_OPTIONS_NOT_SET
+ },
+ {
+ "optimize",
+ UI_KEY_OPTIMIZE,
+ "INT",
+ 0,
+ "Optimization level: 0, 1, 2, 3.",
+ GAL_OPTIONS_GROUP_OUTPUT,
+ &p->optimize,
+ GAL_TYPE_STRING,
+ GAL_OPTIONS_RANGE_ANY,
+ GAL_OPTIONS_NOT_MANDATORY,
+ GAL_OPTIONS_NOT_SET
+ },
+ {
+ "warning",
+ UI_KEY_WARNING,
+ "STR",
+ 0,
+ "Compilation warnings on command-line.",
+ GAL_OPTIONS_GROUP_OUTPUT,
+ &p->warning,
+ GAL_TYPE_STRING,
+ GAL_OPTIONS_RANGE_ANY,
+ GAL_OPTIONS_NOT_MANDATORY,
+ GAL_OPTIONS_NOT_SET
+ },
+ {
"onlybuild",
UI_KEY_ONLYBUILD,
0,
diff --git a/bin/buildprog/astbuildprog.conf b/bin/buildprog/astbuildprog.conf
index 2ac1edf..253158a 100644
--- a/bin/buildprog/astbuildprog.conf
+++ b/bin/buildprog/astbuildprog.conf
@@ -16,3 +16,8 @@
# permitted in any medium without royalty provided the copyright notice and
# this notice are preserved. This file is offered as-is, without any
# warranty.
+
+
+# Output
+ optimize 3
+ warning all
\ No newline at end of file
diff --git a/bin/buildprog/buildprog.c b/bin/buildprog/buildprog.c
index 13673e1..b5d7363 100644
--- a/bin/buildprog/buildprog.c
+++ b/bin/buildprog/buildprog.c
@@ -71,7 +71,7 @@ buildprog(struct buildprogparams *p)
/* Note that the first node of `sourceargs' is the acutal source and the
rest are arguments to be run later. */
int retval;
- char *command;
+ char *command, *optimize, *warning;
char *include = buildprog_as_one_string("-I", p->include);
char *linkdir = buildprog_as_one_string("-L", p->linkdir);
char *linklib = buildprog_as_one_string("-l", p->linklib);
@@ -84,11 +84,23 @@ buildprog(struct buildprogparams *p)
printf("---------------------------------\n");
}
+ /* Compiler options with values: */
+ if(p->warning) asprintf(&warning, "-W%s", p->warning);
+ if(p->optimize) asprintf(&optimize, "-O%s", p->optimize);
+
/* Put the command to run into a string. */
- asprintf(&command, "libtool %s --mode=link gcc %s %s %s %s "
- "%s/libgnuastro.la -o %s", p->cp.quiet?"--quiet":"",
- include?include:"", linkdir?linkdir:"", p->sourceargs->v,
- linklib?linklib:"", LIBDIR, p->cp.output);
+ asprintf(&command, "libtool %s --mode=link gcc %s %s %s %s %s %s %s "
+ "%s/libgnuastro.la -o %s",
+ p->cp.quiet ? "--quiet" : "",
+ warning ? warning : "",
+ p->debug ? "-g" : "",
+ optimize ? optimize : "",
+ include ? include : "",
+ linkdir ? linkdir : "",
+ p->sourceargs->v,
+ linklib ?linklib : "",
+ LIBDIR,
+ p->cp.output);
/* Compile (and link): */
retval=system(command);
@@ -126,5 +138,7 @@ buildprog(struct buildprogparams *p)
free(linkdir);
free(linklib);
free(command);
+ if(warning) free(warning);
+ if(optimize) free(optimize);
return retval;
}
diff --git a/bin/buildprog/main.h b/bin/buildprog/main.h
index 56ea2e2..56a9eed 100644
--- a/bin/buildprog/main.h
+++ b/bin/buildprog/main.h
@@ -48,6 +48,10 @@ struct buildprogparams
gal_list_str_t *include; /* Libraries to link against. */
gal_list_str_t *linkdir; /* Libraries to link against. */
gal_list_str_t *linklib; /* Libraries to link against. */
+
+ char *optimize; /* Optimization level. */
+ char *debug; /* Keep debugging information. */
+ char *warning; /* Compiler warnings. */
uint8_t onlybuild; /* Don't run the compiled program. */
/* Output: */
diff --git a/bin/buildprog/ui.h b/bin/buildprog/ui.h
index 326fda6..7adccb3 100644
--- a/bin/buildprog/ui.h
+++ b/bin/buildprog/ui.h
@@ -29,8 +29,8 @@ along with Gnuastro. If not, see
<http://www.gnu.org/licenses/>.
/* Available letters for short options:
- a c d e f g i j k l n p r s t u v w x y z
- A B C E G H J Q R W X Y
+ a c d e f i j k l n p r s t u v w x y z
+ A B C E G H J Q R X Y
*/
enum option_keys_enum
{
@@ -39,6 +39,9 @@ enum option_keys_enum
UI_KEY_LINKDIR = 'L',
UI_KEY_LINKLIB = 'l',
UI_KEY_ONLYBUILD = 'b',
+ UI_KEY_DEBUG = 'g',
+ UI_KEY_OPTIMIZE = 'O',
+ UI_KEY_WARNING = 'W',
/* 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 946bae5..d4c485b 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -16689,6 +16689,45 @@ directories. Multiple calls to this option are
possible and order
matters. This library will be linked before Gnuastro's library or its
dependencies. See @ref{Linking} for a thorough introduction.
address@hidden -O INT
address@hidden --optimize=INT
address@hidden Optimization
address@hidden GNU Compiler Collection
+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 breakpoint 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. Turning on optimization flags makes the compiler attempt to improve
+the performance and/or code size at the expense of compilation time and
+possibly the ability to debug the program.'' See there for the full list of
+acceptable values to this option (also standard among other compilers).
+
address@hidden -g
address@hidden --debug
address@hidden Debug
+Emit extra information in the compiled binary for use by a debugger. When
+calling this option, it is best to explicitly disable optimization with
address@hidden To combine both options you can run @option{-gO0} (see
address@hidden for how short options can be merged into one).
+
address@hidden -W STR
address@hidden --warning=STR
+Print compiler warnings on command-line during compilation. ``Warnings are
+diagnostic messages that report constructions that are not inherently
+erroneous but that are risky or suggest there may have been an error.''
+(from the GCC manual). It is always recommended to compile your programs
+with warnings enabled.
+
+All compiler warning options that start with @option{W} are usable by this
+option in BuildProgram also, see your compiler's manual for the full
+list. Some of the most common values to this option are: @option{pedantic}
+(Warnings related to standard C), @option{all} (all issues the compiler
+confronts).
+
@item -b
@itemx --onlybuild
Only build the program, don't run it. By default, the built program is