Rework handling Ada and C compiler flags

Pass Ada and C flags to every gprbuild command. Each run may detect that
the library must be updated and recompile Ada or C files. Add missing C
flags when building tests.

Put Adaflags after default options to allow overriding. Only parse
environment once for these flags. Handle CPPFLAGS as well as CFLAGS.
Avoid mixing command line options with project compiler_switches, as the
precedence is not well defined. Use package renamings or extensions
instead of variables to reduce boilerplate.
This commit is contained in:
Nicolas Boulenguez 2017-09-12 14:26:26 +02:00 committed by Adrian-Ken Rueegsegger
parent 222e19fc68
commit 814d0283ae
6 changed files with 30 additions and 23 deletions

View File

@ -49,10 +49,10 @@ NUM_CPUS ?= 1
# environment or on the command line.
CFLAGS ?= -W -Wall -Werror -O3
GNAT_BUILDER_FLAGS ?= -R -j$(NUM_CPUS)
GNATFLAGS ?= ${GNAT_BUILDER_FLAGS} -cargs ${ADAFLAGS}
GNATFLAGS ?= ${GNAT_BUILDER_FLAGS}
# GMAKE_OPTS should not be overridden because -p is essential.
GMAKE_OPTS = -g -p ${GNATFLAGS} -margs \
$(foreach v,LDFLAGS,"-X$(v)=$($(v))")
GMAKE_OPTS = -g -p ${GNATFLAGS} \
$(foreach v,ADAFLAGS CFLAGS CPPFLAGS LDFLAGS,"-X$(v)=$($(v))")
all: build_lib
@ -61,8 +61,7 @@ tests: build_tests
build_lib:
@gprbuild $(GMAKE_OPTS) -Palog -XALOG_VERSION="$(VERSION)" \
-XLIBRARY_KIND="$(LIBRARY_KIND)" -XCFLAGS="$(CFLAGS)" \
-cargs $(ADAFLAGS)
-XLIBRARY_KIND="$(LIBRARY_KIND)"
build_tests:
@gprbuild $(GMAKE_OPTS) -Palog_tests -XALOG_BUILD="tests"

View File

@ -40,9 +40,9 @@ library project Alog is
for Leading_Library_Options use Alog_Common.Ldflags;
end case;
package Compiler is
for Default_Switches ("C") use External_As_List ("CFLAGS", " ");
for Default_Switches ("ada") use Alog_Common.Compiler_Switches & "-gnatwe";
package Compiler extends Alog_Common.Compiler is
for Default_Switches ("Ada") use
Alog_Common.Compiler'Default_Switches ("Ada") & "-gnatwe";
end Compiler;
end Alog;

View File

@ -29,17 +29,25 @@ abstract project Alog_Common is
type Lib_Type is ("static", "dynamic");
Libtype : Lib_Type := external ("LIBRARY_KIND", "static");
Adaflags := External_As_List ("ADAFLAGS", " ");
Cflags := External_As_List ("CFLAGS", " ");
Cppflags := External_As_List ("CPPFLAGS", " ");
Ldflags := External_As_List ("LDFLAGS", " ");
Languages := ("Ada", "C");
Compiler_Switches := ("-gnatygAdISuxo",
"-gnatVa",
"-gnat05",
"-gnatwal",
"-gnatf",
"-fstack-check",
"-gnato");
package Compiler is
for Default_Switches ("Ada") use
("-gnatygAdISuxo",
"-gnatVa",
"-gnat05",
"-gnatwal",
"-gnatf",
"-fstack-check",
"-gnato")
& Adaflags;
for Default_Switches ("C") use Cflags & Cppflags;
end Compiler;
package Binder is
for Default_Switches ("Ada") use ("-E");

View File

@ -31,7 +31,7 @@ project Alog_Tests is
for Languages use Alog_Common.Languages;
for Source_Dirs use ("src", "tests");
Compiler_Switches := Alog_Common.Compiler_Switches;
Compiler_Switches := ();
Linker_Switches := ();
case Build is
@ -53,8 +53,9 @@ project Alog_Tests is
end case;
package Compiler is
for Default_Switches ("ada") use Compiler_Switches;
package Compiler extends Alog_Common.Compiler is
for Default_Switches ("Ada") use
Alog_Common.Compiler'Default_Switches ("Ada") & Compiler_Switches;
end Compiler;
package Linker extends Alog_Common.Linker is

View File

@ -22,8 +22,10 @@
all: build_examples
# C compilations may happen if the library is updated.
build_examples:
@gprbuild -p -Palog_examples $(foreach v,LDFLAGS,"-X$(v)=$($(v))")
@gprbuild -p -Palog_examples \
$(foreach v,ADAFLAGS CFLAGS CPPFLAGS LDFLAGS,"-X$(v)=$($(v))")
clean:
@rm -rf obj

View File

@ -29,10 +29,7 @@ project Alog_Examples is
for Object_Dir use "obj";
for Main use ("logger_example1.adb", "facility_example1.adb", "policy_example1.adb", "policy_example2.adb", "syslog_example1.adb");
package Compiler is
for Default_Switches ("ada") use Alog_Common.Compiler_Switches;
end Compiler;
package Compiler renames Alog_Common.Compiler;
package Binder renames Alog_Common.Binder;
package Linker renames Alog_Common.Linker;