Rombobjörn

summaryrefslogtreecommitdiff
path: root/comfignat.mk
diff options
context:
space:
mode:
Diffstat (limited to 'comfignat.mk')
-rw-r--r--comfignat.mk161
1 files changed, 96 insertions, 65 deletions
diff --git a/comfignat.mk b/comfignat.mk
index 9bc4f7b..f2a9955 100644
--- a/comfignat.mk
+++ b/comfignat.mk
@@ -317,6 +317,21 @@ endif
# build projects:
#
+# First define some functions and constants for processing directory variables.
+
+usage_directory_variables = includedir archincludedir libdir alidir
+# These are the usage-relevant directory variables. They are needed in usage
+# projects after installation.
+
+builder_directory_variables = bindir libexecdir ${usage_directory_variables}
+# These are the builder-relevant directory variables. They control where the
+# GNAT tools write files to be installed.
+
+usage_relevant = ${filter ${usage_directory_variables},${1}}
+# usage_relevant returns a list of the words in the input list that are usage-
+# relevant directory variables. If given a single variable name, it returns
+# that name if the variable is usage-relevant, or an empty string if it isn't.
+
nil =
inert_space = _Comfignat_magic_protective_space_character_substitute_
inert_percent = _Comfignat_magic_protective_percent_character_substitute_
@@ -382,33 +397,81 @@ maybe_relative_to = \
# Then, if relocatable_package is "true", let relative_to convert the pathname,
# otherwise return parameter 1 unchanged.
-embed_pathname = ${call maybe_relative_to,${1},${bindir}}
-# embed_pathname converts an absolute pathname into the right form for
-# inclusion in a program, which means that it is made relative to bindir if a
+embed_pathname = ${call maybe_relative_to,${${1}},${if ${filter bindir,${1}} \
+ ,${libexecdir},${bindir}}}
+# embed_pathname takes the name of a variable whose value is an absolute
+# pathname, and converts that pathname into the right form for inclusion in a
+# program, which means that bindir is made relative to libexecdir and other
+# variables are made relative to bindir if a relocatable package is desired.
+
+usage_pathname = ${call maybe_relative_to,${${1}},${gprdir}}
+# usage_pathname takes the name of a variable whose value is an absolute
+# pathname, and converts that pathname into the right form for inclusion in a
+# usage project, which means that it is made relative to gprdir if a
# relocatable package is desired.
-usage_pathname = ${call maybe_relative_to,${1},${gprdir}}
-# usage_pathname converts an absolute pathname into the right form for
-# inclusion in a usage project, which means that it is made relative to gprdir
-# if a relocatable package is desired.
+define convey_builder_directory_variable
+ all_directories += '-D${1}="${call embed_pathname,${1}}"'
+ all_directories += '-Dstage_${1}="${stage_${1}}"'
+ usage_directories += ${if ${call usage_relevant,${1}}, \
+ '-D${1}="${call usage_pathname,${1}}"'}
+
+endef
+# convey_builder_directory_variable takes the name of a builder-relevant
+# directory variable and returns Make code that conveys that variable to
+# project files. The code snippet ends with a line break.
+# · Append a symbol definition to all_directories to convey the variable to
+# comfignat.gpr in the right form for inclusion in a program.
+# · Also convey to comfignat.gpr the corresponding pathname under the
+# staging directory, which wouldn't be derived correctly from a relative
+# pathname.
+# · If the variable is also usage-relevant, then append a symbol definition
+# to usage_directories to convey it to usage projects in the form that
+# usage projects need.
+
+define use_directories_project_variable
+ all_directories += '-D${1}=${directories_project}.${1}'
+ usage_directories += ${if ${call usage_relevant,${1}}, \
+ '-D${1}=${directories_project}.${1}'}
+
+endef
+# use_directories_project_variable takes the name of a builder-relevant
+# directory variable and returns Make code that makes project files get that
+# variable from a directories project. The code snippet ends with a line break.
+# · Append a symbol definition to all_directories for comfignat.gpr.
+# · If the variable is also usage-relevant, then append a symbol definition
+# to usage_directories for usage projects.
+
+# Now that all those functions are defined, compute the symbol definitions for
+# the directory variables.
# Convey builddir, objdir and stagedir to comfignat.gpr.
all_directories = '-DBuilddir="${builddir}"' '-DObjdir="${objdir}"' \
'-DStagedir="${stagedir}"'
+usage_directories =
+
+# Make project files import the directories project if one has been provided.
+ifneq (${dirgpr},)
+ directories_project := ${basename ${notdir ${call mung_string,${dirgpr}}}}
+ all_directories += '-DDirectories_GPR="${dirgpr}"'
+ all_directories += '-DDirectories_Project=${directories_project}'
+ usage_directories += '-DDirectories_GPR="${dirgpr}"'
+endif
+
# Convey the builder-irrelevant directory variables, making them available to
# build projects for inclusion in binaries. Make most of the pathnames relative
# if a relocatable package is desired.
-all_directories += '-DDatadir="${call embed_pathname,${datadir}}"'
-all_directories += '-DSysconfdir="${call embed_pathname,${sysconfdir}}"'
-all_directories += '-DStatedir="${call embed_pathname,${statedir}}"'
-all_directories += '-DCachedir="${call embed_pathname,${cachedir}}"'
-all_directories += '-DLogdir="${call embed_pathname,${logdir}}"'
-all_directories += '-DGPRdir="${call embed_pathname,${gprdir}}"'
-all_directories += '-DLocaledir="${call embed_pathname,${localedir}}"'
-all_directories += '-DMandir="${call embed_pathname,${mandir}}"'
-all_directories += '-DInfodir="${call embed_pathname,${infodir}}"'
-all_directories += '-DMiscdocdir="${call embed_pathname,${miscdocdir}}"'
+all_directories += '-DDatadir="${call embed_pathname,datadir}"'
+all_directories += '-DSysconfdir="${call embed_pathname,sysconfdir}"'
+all_directories += '-DStatedir="${call embed_pathname,statedir}"'
+all_directories += '-DCachedir="${call embed_pathname,cachedir}"'
+all_directories += '-DLogdir="${call embed_pathname,logdir}"'
+all_directories += '-DGPRdir="${call embed_pathname,gprdir}"'
+all_directories += '-DLocaledir="${call embed_pathname,localedir}"'
+all_directories += '-DMandir="${call embed_pathname,mandir}"'
+all_directories += '-DInfodir="${call embed_pathname,infodir}"'
+all_directories += '-DMiscdocdir="${call embed_pathname,miscdocdir}"'
all_directories += '-DRunstatedir="${runstatedir}"'
all_directories += '-DLockdir="${lockdir}"'
# runstatedir and lockdir belong to the operating system and are used for
@@ -416,54 +479,22 @@ all_directories += '-DLockdir="${lockdir}"'
# to have its own runstatedir. Therefore these variables are always absolute
# pathnames.
-ifeq (${dirgpr},)
-
- # No directories project was provided, so convey even the builder-relevant
- # directory variables to comfignat.gpr, and convey the usage-relevant ones
- # to usage projects in the form that usage projects need.
-
- all_directories += '-DBindir="${call maybe_relative_to,${bindir},${libexecdir}}"'
- all_directories += '-DLibexecdir="${call embed_pathname,${libexecdir}}"'
- all_directories += '-DIncludedir="${call embed_pathname,${includedir}}"'
- all_directories += '-DArchincludedir="${call embed_pathname,${archincludedir}}"'
- all_directories += '-DLibdir="${call embed_pathname,${libdir}}"'
- all_directories += '-DAlidir="${call embed_pathname,${alidir}}"'
-
- all_directories += '-DStage_Bindir="${stage_bindir}"'
- all_directories += '-DStage_Libexecdir="${stage_libexecdir}"'
- all_directories += '-DStage_Includedir="${stage_includedir}"'
- all_directories += '-DStage_Archincludedir="${stage_archincludedir}"'
- all_directories += '-DStage_Libdir="${stage_libdir}"'
- all_directories += '-DStage_Alidir="${stage_alidir}"'
-
- usage_directories = '-DIncludedir="${call usage_pathname,${includedir}}"' \
- '-DArchincludedir="${call usage_pathname,${archincludedir}}"' \
- '-DLibdir="${call usage_pathname,${libdir}}"' \
- '-DAlidir="${call usage_pathname,${alidir}}"'
-
-else
-
- # A directories project is used, so make project files take the builder-
- # relevant directory variables from there.
-
- directories_project := ${basename ${notdir ${call mung_string,${dirgpr}}}}
-
- all_directories += '-DDirectories_GPR="${dirgpr}"'
- all_directories += '-DDirectories_Project=${directories_project}'
- all_directories += '-DBindir=${directories_project}.Bindir'
- all_directories += '-DLibexecdir=${directories_project}.Libexecdir'
- all_directories += '-DIncludedir=${directories_project}.Includedir'
- all_directories += '-DArchincludedir=${directories_project}.Archincludedir'
- all_directories += '-DLibdir=${directories_project}.Libdir'
- all_directories += '-DAlidir=${directories_project}.Alidir'
-
- usage_directories = '-DDirectories_GPR="${dirgpr}"' \
- '-DIncludedir=${directories_project}.Includedir' \
- '-DArchincludedir=${directories_project}.Archincludedir' \
- '-DLibdir=${directories_project}.Libdir' \
- '-DAlidir=${directories_project}.Alidir'
-
-endif
+# Set the builder-relevant directory variables.
+${eval ${foreach var,${builder_directory_variables}, \
+ ${if ${or ${findstring command line,${origin ${var}}}, \
+ ${filter true,${${var}_is_configured}}, \
+ ${filter 0,${words ${dirgpr}}}}, \
+ ${call convey_builder_directory_variable,${var}}, \
+ ${call use_directories_project_variable,${var}}}}}
+# For each builder-relevant directory variable, check whether its value in
+# project files should be taken from the corresponding Make variable or from a
+# directories project, and construct symbol definitions accordingly.
+# If a variable is of command line origin or marked as configured, or if dirgpr
+# is empty (that is, no directories project has been provided), then convey the
+# variable to project files. Otherwise make project files use the variable that
+# the directories project provides.
+
+# And now process any boolean options.
option_values = \
${foreach option,${options}, \