From dae4f47f2b80c7ea7b1df0f713efe79a8a50c69f Mon Sep 17 00:00:00 2001 From: Björn Persson Date: Mon, 18 Jan 2016 11:59:31 +0100 Subject: Added Library_Type to help with building libraries as shared or static. --- INSTALL | 17 ++++++--- comfignat.gpr.gp | 18 +++++++++- comfignat.mk | 17 +++++---- manual.en.html | 42 ++++++++++++++++++++-- testsuite/inputs/build_static | 18 ++++++++++ testsuite/sources/dual_library/Makefile | 20 +++++++++++ .../sources/dual_library/build_testcase.gpr.gp | 28 +++++++++++++++ testsuite/sources/dual_library/generated_files | 8 +++++ testsuite/sources/dual_library/testcase.adb | 24 +++++++++++++ testsuite/sources/dual_library/testcase.ads | 18 ++++++++++ testsuite/sources/dual_library/testcase.gpr.gp | 27 ++++++++++++++ testsuite/sources/library_2/Makefile | 4 +-- testsuite/sources/library_2/build_testcase.gpr | 6 ++-- testsuite/sources/library_2/generated_files | 4 +-- testsuite/sources/library_2/intermediate.gpr.gp | 3 +- testsuite/sources/library_2/testcase.gpr.gp | 4 +-- 16 files changed, 235 insertions(+), 23 deletions(-) create mode 100644 testsuite/inputs/build_static create mode 100644 testsuite/sources/dual_library/Makefile create mode 100644 testsuite/sources/dual_library/build_testcase.gpr.gp create mode 100644 testsuite/sources/dual_library/generated_files create mode 100644 testsuite/sources/dual_library/testcase.adb create mode 100644 testsuite/sources/dual_library/testcase.ads create mode 100644 testsuite/sources/dual_library/testcase.gpr.gp diff --git a/INSTALL b/INSTALL index 4a33eb2..9d4e002 100644 --- a/INSTALL +++ b/INSTALL @@ -209,6 +209,15 @@ invoke Gnatprep. You may need to define them if you run Gnatprep manually. above will be used if the symbols are undefined. +Building a Shared or Static Library +----------------------------------- + +If the software is a library that can be built as either shared or static, then +the Make variable library_type controls which kind of library is built. The +valid values are "dynamic", "static", and "relocatable" which is an alias for +"dynamic". The default is to build a shared library, that is "dynamic". + + Optional Features ----------------- @@ -220,12 +229,12 @@ The developers really should have listed those options here, or deleted this section if there are none. -Build Tools and Options ------------------------ +Build Tools and their Arguments +------------------------------- The following variables, which may be set in the environment or on the Make command line, control which programs are invoked to do the build and which -options are passed to them: +arguments are passed to them: GNATPREP The command for invoking Gnatprep, in case you want to use a nondefault @@ -287,7 +296,7 @@ options are passed to them: Copyright of This File ---------------------- -Copyright 2013 B. Persson, Bjorn@Rombobeorn.se +Copyright 2013 - 2016 B. Persson, Bjorn@Rombobeorn.se This material is provided as is, with absolutely no warranty expressed or implied. Any use is at your own risk. diff --git a/comfignat.gpr.gp b/comfignat.gpr.gp index b9ea446..0f2179e 100644 --- a/comfignat.gpr.gp +++ b/comfignat.gpr.gp @@ -1,5 +1,5 @@ -- Comfignat configuration variables for GNAT project files --- Copyright 2013 - 2015 B. Persson, Bjorn@Rombobeorn.se +-- Copyright 2013 - 2016 B. Persson, Bjorn@Rombobeorn.se -- -- This material is provided as is, with absolutely no warranty expressed -- or implied. Any use is at your own risk. @@ -313,4 +313,20 @@ abstract project Comfignat is Stage_Alidir := Stagedir & Alidir; #end if; + + -- + -- Other configuration than directories: + -- + + -- If a library can be built as either shared or static, then Library_Type + -- shall be used to set the attribute Library_Kind. It can be overridden on + -- the builder command line, which makes it possible to write a makefile + -- that builds both a shared and a static library. + type Library_Kind is ("dynamic", "relocatable", "static"); + #if Library_Type'Defined then + Library_Type : Library_Kind := external("LIBRARY_TYPE", $Library_Type); + #else + Library_Type : Library_Kind := external("LIBRARY_TYPE", "dynamic"); + #end if; + end Comfignat; diff --git a/comfignat.mk b/comfignat.mk index a9847a8..c355a7d 100644 --- a/comfignat.mk +++ b/comfignat.mk @@ -148,6 +148,10 @@ relocatable_package = false # breaking the project files. # dirgpr takes precedence over relocatable_package. +library_type = dynamic +# If a library can be built as either shared or static, then library_type shall +# be used to set the attribute Library_Kind in the project files. + prefix = /usr/local exec_prefix = ${prefix} datarootdir = ${prefix}/share @@ -268,14 +272,14 @@ Make_miscdocdir = ${call Make_pathname,stage_miscdocdir} preprocess_file = "${GNATPREP}" ${firstword ${filter %.gp,$^}} $@ \ ${options_preprocessing} ${Gnatprep_arguments} \ ${if ${filter ${notdir $@},${notdir ${usage_GPRs}}}, \ - ${usage_directories}, \ + ${usage_directories} '-DLibrary_Type="${library_type}"', \ '-DSrcdir="${srcdir}"'} \ ${GNATPREPFLAGS} # preprocess_file is a command for use in recipes. It runs the first .gp file # among the rule's prerequisites through Gnatprep to produce the target. If the -# target is a usage project, then the usage-relevant directory variables are -# conveyed to it as Gnatprep symbols. Otherwise srcdir is conveyed, as it's -# needed by preprocessed build projects. +# target is a usage project, then the usage-relevant variables are conveyed to +# it as Gnatprep symbols. Otherwise srcdir is conveyed, as it's needed by +# preprocessed build projects. build_GPR = "${GNAT_BUILDER}" -P ${firstword ${filter %.gpr,$^}} \ ${addprefix -aP,${VPATH}} -p \ @@ -407,7 +411,7 @@ configuration_variables += \ GNATPREPFLAGS GNAT_BUILDER_FLAGS ADAFLAGS CPPFLAGS CFLAGS CXXFLAGS FFLAGS \ GNATBINDFLAGS GNATLINKFLAGS LDFLAGS GNATFLAGS \ DESTDIR \ - dirgpr relocatable_package \ + dirgpr relocatable_package library_type \ prefix exec_prefix datarootdir localstatedir \ bindir libexecdir \ datadir sysconfdir statedir cachedir logdir runstatedir lockdir \ @@ -692,7 +696,8 @@ show_configuration:: # How to preprocess the project Comfignat: ${Make_builddir}/comfignat.gpr: comfignat.gpr.gp | ${Make_builddir}/ - "${GNATPREP}" $< $@ -DInvoked_By_Makefile ${all_directories} ${GNATPREPFLAGS} + "${GNATPREP}" $< $@ -DInvoked_By_Makefile ${all_directories} \ + '-DLibrary_Type="${library_type}"' ${GNATPREPFLAGS} # How to preprocess files that are needed during the build: ${Make_builddir}/%: %.gp | ${Make_builddir}/ diff --git a/manual.en.html b/manual.en.html index 3d25fc2..9910afb 100755 --- a/manual.en.html +++ b/manual.en.html @@ -112,7 +112,7 @@ and is also

The following applies to all of Comfignat including this document:

-

Copyright 2013 - 2015 Björn Persson, Bjorn@Rombobjörn.se

+

Copyright 2013 - 2016 Björn Persson, Bjorn@Rombobjörn.se

This material is provided as is, with absolutely no warranty expressed or implied. Any use is at your own risk.

@@ -456,6 +456,43 @@ project will therefore automatically adapt to the current target architecture, so that 32-bit and 64-bit instances of the library can be installed in parallel and the right library will be used in every build.

+

Shared and Static Libraries

+ +

Many libraries can be built either as a shared library or as a static +library. To enable this, use the variable Comfignat.Library_Type for +Library_Kind in the build-controlling project file, and the +preprocessor symbol Library_Type in the usage project file. The +default will then be to build a shared library, but installing users and +distributions can build a static library instead by setting +library_type to “static” on the Make command line. +The possible values of Library_Type are the same as for +Library_Kind: “dynamic”, “static”, and +“relocatable” which is an alias for “dynamic”.

+ +

It may be necessary to also use Comfignat.Library_Type in a case +construction to set certain attributes only for one kind of library. It may for +example be desirable to set Library_Interface for a shared library +but not for a static library, to get the best automatic elaboration in both +cases. Here's a project file fragment that sets Library_Version and +Library_Interface only when building a shared library:

+ +
   for Library_Kind      use Comfignat.Library_Type;
+   case Comfignat.Library_Type is
+      when "dynamic" | "relocatable" =>
+         for Library_Version   use "libexample.so.1";
+         for Library_Interface use ("Example");
+      when "static" =>
+         null;
+   end case;
+ +

It is also possible to build both a shared and a static library in the same +Make invocation by overriding LIBRARY_TYPE on the builder command +line:

+ +
base: build_example.gpr
+	${build_GPR} -margs -XLIBRARY_TYPE=dynamic
+	${build_GPR} -margs -XLIBRARY_TYPE=static
+

Options

Your software may have optional features or properties that can be enabled @@ -510,7 +547,8 @@ have its own runstatedir.

There are several options variables that let installing users and distributions control which arguments the build tools are invoked with. They have names that end with “FLAGS”, and are documented in -INSTALL. The value of GNATFLAGS is a combination of the +INSTALL. +The value of GNATFLAGS is a combination of the other options variables and must not be modified in a way that disregards the other variables. Apart from that restriction you can assign default values to optional arguments in these variables, but be sure to do the assignments with diff --git a/testsuite/inputs/build_static b/testsuite/inputs/build_static new file mode 100644 index 0000000..30a0fa7 --- /dev/null +++ b/testsuite/inputs/build_static @@ -0,0 +1,18 @@ +# part of Comfignat's testsuite +# Copyright 2016 B. Persson, Bjorn@Rombobeorn.se +# +# This material is provided as is, with absolutely no warranty expressed +# or implied. Any use is at your own risk. +# +# Permission is hereby granted to use or copy this testsuite +# for any purpose, provided the above notices are retained on all copies. +# Permission to modify the code and to distribute modified code is granted, +# provided the above notices are retained, and a notice that the code was +# modified is included with the above copyright notice. + + +static=true +expect_configuration +expect_generated_files +common_setup +make library_type=static diff --git a/testsuite/sources/dual_library/Makefile b/testsuite/sources/dual_library/Makefile new file mode 100644 index 0000000..aa57d84 --- /dev/null +++ b/testsuite/sources/dual_library/Makefile @@ -0,0 +1,20 @@ +# part of Comfignat's testsuite +# Copyright 2016 B. Persson, Bjorn@Rombobeorn.se +# +# This material is provided as is, with absolutely no warranty expressed +# or implied. Any use is at your own risk. +# +# Permission is hereby granted to use or copy this testsuite +# for any purpose, provided the above notices are retained on all copies. +# Permission to modify the code and to distribute modified code is granted, +# provided the above notices are retained, and a notice that the code was +# modified is included with the above copyright notice. + + +include comfignat.mk + +usage_GPRs = testcase.gpr + +base: build_testcase.gpr + ${build_GPR} -margs -XLIBRARY_TYPE=dynamic + ${build_GPR} -margs -XLIBRARY_TYPE=static diff --git a/testsuite/sources/dual_library/build_testcase.gpr.gp b/testsuite/sources/dual_library/build_testcase.gpr.gp new file mode 100644 index 0000000..1c39659 --- /dev/null +++ b/testsuite/sources/dual_library/build_testcase.gpr.gp @@ -0,0 +1,28 @@ +-- part of Comfignat's testsuite +-- Copyright 2016 B. Persson, Bjorn@Rombobeorn.se +-- +-- This material is provided as is, with absolutely no warranty expressed +-- or implied. Any use is at your own risk. +-- +-- Permission is hereby granted to use or copy this testsuite +-- for any purpose, provided the above notices are retained on all copies. +-- Permission to modify the code and to distribute modified code is granted, +-- provided the above notices are retained, and a notice that the code was +-- modified is included with the above copyright notice. + + +with "comfignat.gpr"; + +library project Build_Testcase is + + for Library_Name use "testcase"; + for Library_Kind use Comfignat.Library_Type; + for Library_Version use "libtestcase.so.1"; + for Library_Interface use ("Testcase"); + for Source_Dirs use ($Srcdir); + for Object_Dir use Comfignat.Objdir; + for Library_Src_Dir use Comfignat.Stage_Includedir & "/testcase"; + for Library_Dir use Comfignat.Stage_Libdir; + for Library_ALI_Dir use Comfignat.Stage_Alidir & "/testcase"; + +end Build_Testcase; diff --git a/testsuite/sources/dual_library/generated_files b/testsuite/sources/dual_library/generated_files new file mode 100644 index 0000000..45a5035 --- /dev/null +++ b/testsuite/sources/dual_library/generated_files @@ -0,0 +1,8 @@ +build_testcase.gpr +comfignat.gpr +${stage_includedir}/testcase/testcase.ads +${stage_libdir}/libtestcase.so.1 +${stage_libdir}/libtestcase.so +${stage_libdir}/libtestcase.a +${stage_alidir}/testcase/testcase.ali +${stage_gprdir}/testcase.gpr diff --git a/testsuite/sources/dual_library/testcase.adb b/testsuite/sources/dual_library/testcase.adb new file mode 100644 index 0000000..df96cc3 --- /dev/null +++ b/testsuite/sources/dual_library/testcase.adb @@ -0,0 +1,24 @@ +-- part of Comfignat's testsuite +-- Copyright 2014 B. Persson, Bjorn@Rombobeorn.se +-- +-- This material is provided as is, with absolutely no warranty expressed +-- or implied. Any use is at your own risk. +-- +-- Permission is hereby granted to use or copy this testsuite +-- for any purpose, provided the above notices are retained on all copies. +-- Permission to modify the code and to distribute modified code is granted, +-- provided the above notices are retained, and a notice that the code was +-- modified is included with the above copyright notice. + + +with Ada.Calendar; use Ada.Calendar; +with Ada.Text_IO; use Ada.Text_IO; + +package body Testcase is + + function Year return String is + begin + return Year(Clock)'Img; + end Year; + +end Testcase; diff --git a/testsuite/sources/dual_library/testcase.ads b/testsuite/sources/dual_library/testcase.ads new file mode 100644 index 0000000..d2646b8 --- /dev/null +++ b/testsuite/sources/dual_library/testcase.ads @@ -0,0 +1,18 @@ +-- part of Comfignat's testsuite +-- Copyright 2014 B. Persson, Bjorn@Rombobeorn.se +-- +-- This material is provided as is, with absolutely no warranty expressed +-- or implied. Any use is at your own risk. +-- +-- Permission is hereby granted to use or copy this testsuite +-- for any purpose, provided the above notices are retained on all copies. +-- Permission to modify the code and to distribute modified code is granted, +-- provided the above notices are retained, and a notice that the code was +-- modified is included with the above copyright notice. + + +package Testcase is + + function Year return String; + +end Testcase; diff --git a/testsuite/sources/dual_library/testcase.gpr.gp b/testsuite/sources/dual_library/testcase.gpr.gp new file mode 100644 index 0000000..e2833c1 --- /dev/null +++ b/testsuite/sources/dual_library/testcase.gpr.gp @@ -0,0 +1,27 @@ +-- part of Comfignat's testsuite +-- Copyright 2016 B. Persson, Bjorn@Rombobeorn.se +-- +-- This material is provided as is, with absolutely no warranty expressed +-- or implied. Any use is at your own risk. +-- +-- Permission is hereby granted to use or copy this testsuite +-- for any purpose, provided the above notices are retained on all copies. +-- Permission to modify the code and to distribute modified code is granted, +-- provided the above notices are retained, and a notice that the code was +-- modified is included with the above copyright notice. + + +#if Directories_GPR'Defined then +with $Directories_GPR; +#end if; + +library project Testcase is + + for Library_Name use "testcase"; + for Library_Kind use external("testcase_library_type", $Library_Type); + for Source_Dirs use ($Includedir & "/testcase"); + for Library_Dir use $Libdir; + for Library_ALI_Dir use $Alidir & "/testcase"; + for Externally_Built use "true"; + +end Testcase; diff --git a/testsuite/sources/library_2/Makefile b/testsuite/sources/library_2/Makefile index 63d47ef..9341253 100644 --- a/testsuite/sources/library_2/Makefile +++ b/testsuite/sources/library_2/Makefile @@ -1,5 +1,5 @@ # part of Comfignat's testsuite -# Copyright 2014 B. Persson, Bjorn@Rombobeorn.se +# Copyright 2014 - 2016 B. Persson, Bjorn@Rombobeorn.se # # This material is provided as is, with absolutely no warranty expressed # or implied. Any use is at your own risk. @@ -16,5 +16,5 @@ include comfignat.mk build_GPRs = build_testcase.gpr usage_GPRs = testcase.gpr other.gpr -Gnatprep_arguments = -Dkind='"dynamic"' +Gnatprep_arguments = -Dkind=Comfignat.Library_Type -Dslash='"/"' builder_arguments = -Xname=testcase diff --git a/testsuite/sources/library_2/build_testcase.gpr b/testsuite/sources/library_2/build_testcase.gpr index 29c62b9..c157484 100644 --- a/testsuite/sources/library_2/build_testcase.gpr +++ b/testsuite/sources/library_2/build_testcase.gpr @@ -1,5 +1,5 @@ -- part of Comfignat's testsuite --- Copyright 2014 B. Persson, Bjorn@Rombobeorn.se +-- Copyright 2014 - 2016 B. Persson, Bjorn@Rombobeorn.se -- -- This material is provided as is, with absolutely no warranty expressed -- or implied. Any use is at your own risk. @@ -19,7 +19,7 @@ library project Build_Testcase is for Library_Version use Intermediate.Soname; for Library_Interface use (Intermediate.Package_Name); for Object_Dir use Intermediate.Objdir; - for Library_Src_Dir use Intermediate.Includedir & "/" & Intermediate.Name; + for Library_Src_Dir use Intermediate.Includedir & Intermediate.Slash_Name; for Library_Dir use Intermediate.Libdir; - for Library_ALI_Dir use Intermediate.Alidir & "/" & Intermediate.Name; + for Library_ALI_Dir use Intermediate.Alidir & Intermediate.Slash_Name; end Build_Testcase; diff --git a/testsuite/sources/library_2/generated_files b/testsuite/sources/library_2/generated_files index 015651b..595ef75 100644 --- a/testsuite/sources/library_2/generated_files +++ b/testsuite/sources/library_2/generated_files @@ -1,8 +1,8 @@ intermediate.gpr comfignat.gpr ${stage_includedir}/testcase/testcase.ads -${stage_libdir}/libtestcase.so.1 -${stage_libdir}/libtestcase.so +${stage_libdir}/libtestcase.`if [ -n "${static}" ]; then echo a; else echo so.1; fi` +`if [ -z "${static}" ]; then echo ${stage_libdir}/libtestcase.so; fi` ${stage_alidir}/testcase/testcase.ali ${stage_gprdir}/testcase.gpr ${stage_gprdir}/other.gpr diff --git a/testsuite/sources/library_2/intermediate.gpr.gp b/testsuite/sources/library_2/intermediate.gpr.gp index 6d6b8f2..9af9a4e 100644 --- a/testsuite/sources/library_2/intermediate.gpr.gp +++ b/testsuite/sources/library_2/intermediate.gpr.gp @@ -1,5 +1,5 @@ -- part of Comfignat's testsuite --- Copyright 2014 B. Persson, Bjorn@Rombobeorn.se +-- Copyright 2014 - 2016 B. Persson, Bjorn@Rombobeorn.se -- -- This material is provided as is, with absolutely no warranty expressed -- or implied. Any use is at your own risk. @@ -16,6 +16,7 @@ with "comfignat.gpr"; abstract project Intermediate is Name := Names.Name; + Slash_Name := $Slash & Name; Kind := $Kind; Soname := Names.Soname; Package_Name := Names.Package_Name; diff --git a/testsuite/sources/library_2/testcase.gpr.gp b/testsuite/sources/library_2/testcase.gpr.gp index de4645c..7c4d945 100644 --- a/testsuite/sources/library_2/testcase.gpr.gp +++ b/testsuite/sources/library_2/testcase.gpr.gp @@ -1,5 +1,5 @@ -- part of Comfignat's testsuite --- Copyright 2014 B. Persson, Bjorn@Rombobeorn.se +-- Copyright 2014 - 2016 B. Persson, Bjorn@Rombobeorn.se -- -- This material is provided as is, with absolutely no warranty expressed -- or implied. Any use is at your own risk. @@ -18,7 +18,7 @@ with $Directories_GPR; library project Testcase is for Library_Name use "testcase"; - for Library_Kind use "dynamic"; + for Library_Kind use $Library_Type; for Source_Dirs use ($Includedir & "/testcase"); for Library_Dir use $Libdir; for Library_ALI_Dir use $Alidir & "/testcase"; -- cgit v1.2.3