diff options
| -rw-r--r-- | COPYING | 8 | ||||
| -rw-r--r-- | comfignat.gpr.gp | 39 | ||||
| -rw-r--r-- | comfignat.mk | 30 | ||||
| -rw-r--r-- | system_log.adb | 40 | ||||
| -rw-r--r-- | test/test_system_log.adb | 6 |
5 files changed, 90 insertions, 33 deletions
@@ -1,7 +1,7 @@ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 - Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. @@ -645,7 +645,7 @@ the "copyright" line and a pointer to where the full notice is found. GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. + along with this program. If not, see <https://www.gnu.org/licenses/>. Also add information on how to contact you by electronic and paper mail. @@ -664,11 +664,11 @@ might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see -<http://www.gnu.org/licenses/>. +<https://www.gnu.org/licenses/>. The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read -<http://www.gnu.org/philosophy/why-not-lgpl.html>. +<https://www.gnu.org/licenses/why-not-lgpl.html>. diff --git a/comfignat.gpr.gp b/comfignat.gpr.gp index e024f90..e7acd58 100644 --- a/comfignat.gpr.gp +++ b/comfignat.gpr.gp @@ -1,5 +1,5 @@ -- Comfignat configuration variables for GNAT project files --- Copyright 2013 - 2016 B. Persson, Bjorn@Rombobeorn.se +-- Copyright 2013 - 2025 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. @@ -11,9 +11,9 @@ -- modified is included with the above copyright notice. --- This file is part of Comfignat 1.5 – common, convenient, command-line- +-- This file is part of Comfignat 1.6 – common, convenient, command-line- -- controlled compile-time configuration of software built with the GNAT tools. --- For information about Comfignat, see http://www.Rombobeorn.se/Comfignat/. +-- For information about Comfignat, see https://www.Rombobeorn.se/Comfignat/. -- This project file defines directory variables for use in build-controlling @@ -229,6 +229,39 @@ abstract project Comfignat is -- + -- The following variables are convenient to use in Compiler'Switches or + -- Compiler'Default_Switches in project files. + -- + -- There are no switch variables for: + -- · Unitdir, Userunitdir and GPRdir: A program working on such files would + -- need to use a search path, not just one directory. + -- · Includedir, Archincludedir and Alidir: Libraries have those pathnames + -- in usage project files. There doesn't seem to be a usecase for + -- compiling them into binaries. + + Bindir_Switch := "-gnateDBindir=""" & Bindir & """"; + Libexecdir_Switch := "-gnateDLibexecdir=""" & Libexecdir & """"; + Datadir_Switch := "-gnateDDatadir=""" & Datadir & """"; + Sysconfdir_Switch := "-gnateDSysconfdir=""" & Sysconfdir & """"; + Statedir_Switch := "-gnateDStatedir=""" & Statedir & """"; + Cachedir_Switch := "-gnateDCachedir=""" & Cachedir & """"; + Logdir_Switch := "-gnateDLogdir=""" & Logdir & """"; + Runstatedir_Switch := "-gnateDRunstatedir=""" & Runstatedir & """"; + Lockdir_Switch := "-gnateDLockdir=""" & Lockdir & """"; + Libdir_Switch := "-gnateDLibdir=""" & Libdir & """"; + Localedir_Switch := "-gnateDLocaledir=""" & Localedir & """"; + Mandir_Switch := "-gnateDMandir=""" & Mandir & """"; + Infodir_Switch := "-gnateDInfodir=""" & Infodir & """"; + Miscdocdir_Switch := "-gnateDMiscdocdir=""" & Miscdocdir & """"; + + All_Dir_Switches := + (Bindir_Switch, Libexecdir_Switch, Datadir_Switch, Sysconfdir_Switch, + Statedir_Switch, Cachedir_Switch, Logdir_Switch, Runstatedir_Switch, + Lockdir_Switch, Libdir_Switch, Localedir_Switch, Mandir_Switch, + Infodir_Switch, Miscdocdir_Switch); + + + -- -- The following variables are for use in attributes to control where -- generated files are placed. -- diff --git a/comfignat.mk b/comfignat.mk index b71efb2..a574a17 100644 --- a/comfignat.mk +++ b/comfignat.mk @@ -1,5 +1,5 @@ # Comfignat makefile foundation for configuring and building GNAT projects -# Copyright 2013 - 2016 B. Persson, Bjorn@Rombobeorn.se +# Copyright 2013 - 2025 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. @@ -11,9 +11,9 @@ # modified is included with the above copyright notice. -# This file is part of Comfignat 1.5 – common, convenient, command-line- +# This file is part of Comfignat 1.6 – common, convenient, command-line- # controlled compile-time configuration of software built with the GNAT tools. -# For information about Comfignat, see http://www.Rombobeorn.se/Comfignat/. +# For information about Comfignat, see https://www.Rombobeorn.se/Comfignat/. # This file contains generic Make code. It is designed to be included by other @@ -168,6 +168,8 @@ cachedir = ${localstatedir}/cache logdir = ${localstatedir}/log runstatedir = /run lockdir = ${runstatedir}/lock +unitdir = ${prefix}/lib/systemd/system +userunitdir = ${prefix}/lib/systemd/user includedir = ${prefix}/include archincludedir = ${includedir} libdir = ${exec_prefix}/lib @@ -233,6 +235,8 @@ stage_sysconfdir = ${stagedir}${sysconfdir} stage_statedir = ${stagedir}${statedir} stage_cachedir = ${stagedir}${cachedir} stage_logdir = ${stagedir}${logdir} +stage_unitdir = ${stagedir}${unitdir} +stage_userunitdir = ${stagedir}${userunitdir} stage_includedir = ${stagedir}${includedir} stage_archincludedir = ${stagedir}${archincludedir} stage_libdir = ${stagedir}${libdir} @@ -257,6 +261,8 @@ Make_sysconfdir = ${call Make_pathname,stage_sysconfdir} Make_statedir = ${call Make_pathname,stage_statedir} Make_cachedir = ${call Make_pathname,stage_cachedir} Make_logdir = ${call Make_pathname,stage_logdir} +Make_unitdir = ${call Make_pathname,stage_unitdir} +Make_userunitdir = ${call Make_pathname,stage_userunitdir} Make_includedir = ${call Make_pathname,stage_includedir} Make_archincludedir = ${call Make_pathname,stage_archincludedir} Make_libdir = ${call Make_pathname,stage_libdir} @@ -281,9 +287,7 @@ preprocess_file = "${GNATPREP}" ${firstword ${filter %.gp,$^}} $@ \ # 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 \ - ${options_building} ${builder_arguments} ${GNATFLAGS} +build_GPR = ${call build_specified_GPR,${firstword ${filter %.gpr,$^}}} # build_GPR is a command for use in recipes. It performs a build controlled by # the first project file among the rule's prerequisites. @@ -415,6 +419,7 @@ configuration_variables += \ prefix exec_prefix datarootdir localstatedir \ bindir libexecdir \ datadir sysconfdir statedir cachedir logdir runstatedir lockdir \ + unitdir userunitdir \ includedir archincludedir libdir alidir gprdir \ localedir mandir infodir miscdocdir \ objdir stagedir \ @@ -614,6 +619,9 @@ preprocessed_files_in_builddir = ${addprefix ${Make_builddir}/,${preprocessed_fi # preprocessed files are assumed to be needed during the build and are written # to builddir. +build_specified_GPR = "${GNAT_BUILDER}" -P ${1} ${addprefix -aP,${VPATH}} -p \ + ${options_building} ${builder_arguments} ${GNATFLAGS} + # # Make rules: @@ -715,11 +723,17 @@ ${Make_gprdir}/%: % | ${Make_gprdir}/ preprocess: $${preprocessed_files_in_builddir} # How to build a project: -%.gpr.phony_target: %.gpr preprocess - ${build_GPR} +%.gpr.phony_target: preprocess + ${call build_specified_GPR,${basename $@}} # Instead of tracking dependencies between project files, this rule simply # requires that all preprocessing of files that are needed during the build is # done before any project is built. +# "%.gpr" isn't mentioned as a prerequisite because that stopped working in GNU +# Make 4.4. This rule is phony so that the builder is always run and gets to +# determine whether the project needs rebuilding. Thus there's no need to have +# Make check whether the project file has been changed. The dependency on +# preprocess ensures that the project file is generated if needed, and its name +# is known from the target name. .PHONY: base base: $${build_targets} preprocess diff --git a/system_log.adb b/system_log.adb index 2755501..33b070a 100644 --- a/system_log.adb +++ b/system_log.adb @@ -1,5 +1,5 @@ -- System_Log, a binding to the Unix syslog functions --- Copyright 2009 - 2013 B. Persson, Bjorn@Rombobeorn.se +-- Copyright 2009 - 2023 B. Persson, Bjorn@Rombobeorn.se -- -- This library is free software: you can redistribute it and/or modify it -- under the terms of the GNU General Public License version 3, as published @@ -7,12 +7,13 @@ with Interfaces.C.Strings; use Interfaces.C; use Interfaces.C.Strings; -with Ada.Unchecked_Conversion; package body System_Log is - Facility_Numbers : constant array(Log_Facility) of int := + subtype Facility_Number is int range 0 .. 23 * 8; + + Facility_Numbers : constant array(Log_Facility) of Facility_Number := (Kernel => 0 * 8, -- LOG_KERN User => 1 * 8, -- LOG_USER Mail => 2 * 8, -- LOG_MAIL @@ -33,7 +34,9 @@ package body System_Log is Local6 => 22 * 8, -- LOG_LOCAL6 Local7 => 23 * 8); -- LOG_LOCAL7 - Level_Numbers : constant array(Log_Level) of int := + subtype Level_Number is Natural range 0 .. 7; + + Level_Numbers : constant array(Log_Level) of Level_Number := (Emergency => 0, -- LOG_EMERG Alert => 1, -- LOG_ALERT Critical => 2, -- LOG_CRIT @@ -86,7 +89,6 @@ package body System_Log is procedure Set_Log_Levels(New_Levels : in Log_Levels) is Dummy : Log_Levels; - pragma Unreferenced(Dummy); begin Set_Log_Levels(New_Levels, Dummy); end Set_Log_Levels; @@ -98,17 +100,21 @@ package body System_Log is function setlogmask(mask : int) return int; pragma Import(C, setlogmask, "setlogmask"); - Bits : constant := Log_Level'Pos(Log_Level'Last) + 1; - type Mask is range 0 .. 2 ** Bits - 1; - for Mask'Size use Bits; - function To_Mask is new Ada.Unchecked_Conversion(Source => Log_Levels, - Target => Mask); - function To_Levels is new Ada.Unchecked_Conversion(Source => Mask, - Target => Log_Levels); + New_Mask : int := 0; + Old_Mask : unsigned; begin - -- Convert the input array of Boolean to a number, pass that to - -- setlogmask, and convert the output in the other direction. - Old_Levels := To_Levels(Mask(setlogmask(int(To_Mask(New_Levels))))); + -- Convert the input array of Boolean to a number. + for L in Log_Levels'Range loop + if New_Levels(L) then + New_Mask := New_Mask + 2 ** Level_Numbers(L); + end if; + end loop; + -- Pass that number to setlogmask and get the previous mask back. + Old_Mask := unsigned(setlogmask(New_Mask)); + -- Convert the output number to an array of Boolean. + for L in Log_Levels'Range loop + Old_Levels(L) := (Old_Mask and 2 ** Level_Numbers(L)) /= 0; + end loop; end Set_Log_Levels; @@ -131,7 +137,7 @@ package body System_Log is procedure Log(Level : in Log_Level; Message : in String) is begin - syslog(Level_Numbers(Level), Simple_Format, To_C(Message)); + syslog(int(Level_Numbers(Level)), Simple_Format, To_C(Message)); end Log; @@ -140,7 +146,7 @@ package body System_Log is Message : in String) is begin - syslog(Facility_Numbers(Facility) + Level_Numbers(Level), + syslog(Facility_Numbers(Facility) + int(Level_Numbers(Level)), Simple_Format, To_C(Message)); end Log; diff --git a/test/test_system_log.adb b/test/test_system_log.adb index 319c039..5a0a053 100644 --- a/test/test_system_log.adb +++ b/test/test_system_log.adb @@ -1,5 +1,5 @@ -- This is a simple test program for testing System_Log. --- Copyright 2012 B. Persson, Bjorn@Rombobeorn.se +-- Copyright 2009 - 2017 B. Persson, Bjorn@Rombobeorn.se -- -- This program is free software: you can redistribute it and/or modify it -- under the terms of the GNU General Public License version 3, as published @@ -14,4 +14,8 @@ begin Include_PID => True); Log(Info, "This is a test message on the info level."); Log(Debug, "This is a test message on the debug level."); + Set_Log_Threshold(Info); + Log(Debug, "This test message is below the threshold and shouldn't be seen."); + Log(Info, "This test message is above the threshold and should be seen."); + Log(Local5, Info, "This is a test message logged as the Local5 facility."); end Test_System_Log; |