Rombobjörn

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Persson <bjorn@rombobjörn.se>2013-02-13 23:17:52 +0100
committerBjörn Persson <bjorn@rombobjörn.se>2013-02-13 23:17:52 +0100
commit4766a7a7a2f23ee10560e1a2a177eec8931d974a (patch)
tree5380090b964906e3317b930b43ce38bd60f5e0cf
parentb5565b3dc55003122b0ffdc211d03446971ff12a (diff)
Added a convenient and flexible build system.
-rw-r--r--Makefile21
-rw-r--r--build_milter_api.gpr43
-rw-r--r--build_milter_api.gpr.in47
-rw-r--r--build_test_milter.gpr (renamed from test/build_test_milter.gpr)17
-rw-r--r--build_thread_wrapper.gpr (renamed from thread_wrapper/build_thread_wrapper.gpr)12
-rw-r--r--comfignat.gpr.in98
-rw-r--r--comfignat.mk220
-rw-r--r--directories.gpr18
-rw-r--r--milter_api.gpr.in (renamed from milter_api.gpr)22
9 files changed, 418 insertions, 80 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..a0e260b
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,21 @@
+# makefile to compile the Ada Milter API into a shared library
+# Copyright 2013 B. Persson, Bjorn@Rombobeorn.se
+#
+# This makefile is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 3, as published
+# by the Free Software Foundation.
+
+
+include comfignat.mk
+
+options = wrap_threads
+wrap_threads = false
+
+build_GPRs = build_milter_api.gpr
+ifeq (${wrap_threads},true)
+ build_GPRs += build_thread_wrapper.gpr
+endif
+usage_GPRs = milter_api.gpr
+
+test_milter: build build_test_milter.gpr
+ ${build_GPR}
diff --git a/build_milter_api.gpr b/build_milter_api.gpr
deleted file mode 100644
index a6d7245..0000000
--- a/build_milter_api.gpr
+++ /dev/null
@@ -1,43 +0,0 @@
--- Use this project file to compile the Ada Milter API into a shared library.
--- Copyright 2009 - 2012 B. Persson, Bjorn@Rombobeorn.se
---
--- This project file is free software: you can redistribute it and/or modify it
--- under the terms of the GNU General Public License version 3, as published
--- by the Free Software Foundation.
-
-
-with "directories";
-with "system_log";
-
-project Build_Milter_API is
-
- Version := "1.2.1";
- Destdir := external("DESTDIR", "");
-
- for Library_Name use "adamilter";
- for Library_Kind use "relocatable";
- for Library_Version use "libadamilter.so." & Version;
- for Library_Src_Dir use Destdir & Directories.Includedir & "/adamilter";
- for Library_Dir use Destdir & Directories.Libdir;
- for Library_ALI_Dir use Destdir & Directories.Libdir & "/adamilter";
-
- -- Put the binder files for different architectures in subdirectories where
- -- they won't conflict with each other.
- for Object_Dir use "obj/" & Directories.Hardware_Platform;
-
- for Library_Interface use ("Milter_API", "Berkeley_Exit_Codes");
- for Languages use ("Ada", "C");
-
- package Compiler is
- for Default_Switches ("Ada") use ("-gnato");
- end Compiler;
-
- -- Ensure that the shared library will be initialized. GPRbuild 2010 doesn't
- -- pass -a automatically.
- package Binder is
- for Default_Switches ("Ada") use ("-a");
- end Binder;
-
- for Library_Options use ("-lmilter");
-
-end Build_Milter_API;
diff --git a/build_milter_api.gpr.in b/build_milter_api.gpr.in
new file mode 100644
index 0000000..dfa8334
--- /dev/null
+++ b/build_milter_api.gpr.in
@@ -0,0 +1,47 @@
+-- project file to compile the Ada Milter API into a shared library
+-- Copyright 2009 - 2013 B. Persson, Bjorn@Rombobeorn.se
+--
+-- This project file is free software: you can redistribute it and/or modify it
+-- under the terms of the GNU General Public License version 3, as published
+-- by the Free Software Foundation.
+
+
+with "comfignat.gpr";
+with "system_log.gpr";
+
+library project Build_Milter_API is
+
+ Version := "1.2.1";
+
+ for Library_Name use "adamilter";
+ for Library_Kind use "dynamic";
+ for Library_Version use "libadamilter.so." & Version;
+ for Languages use ("Ada", "C");
+ for Library_Interface use ("Milter_API", "Berkeley_Exit_Codes");
+ for Object_Dir use Comfignat.Objdir;
+ for Library_Src_Dir use Comfignat.Stage_Includedir & "/adamilter";
+ for Library_Dir use Comfignat.Stage_Libdir;
+ for Library_ALI_Dir use Comfignat.Stage_Libdir & "/adamilter";
+
+ package Compiler is
+ for Default_Switches ("Ada") use ("-gnato");
+ end Compiler;
+
+ -- Ensure that the shared library will be initialized. GPRbuild 2010 doesn't
+ -- pass -a automatically. (Fixed in GPRbuild 2012.)
+ package Binder is
+ for Default_Switches ("Ada") use ("-a");
+ end Binder;
+
+ -- libadamilter shall link to libmilter.
+ for Library_Options use ("-lmilter");
+
+ #if Wrap_Threads then
+ package Linker is
+ -- When the test milter links to libadamilter it shall link to
+ -- libadamilter_thread_wrapper and libdl too.
+ for Linker_Options use ("-ladamilter_thread_wrapper", "-ldl");
+ end Linker;
+ #end if;
+
+end Build_Milter_API;
diff --git a/test/build_test_milter.gpr b/build_test_milter.gpr
index 6746be3..305dfbf 100644
--- a/test/build_test_milter.gpr
+++ b/build_test_milter.gpr
@@ -1,16 +1,21 @@
--- Use this project file to compile the test milter of the Ada Milter API.
+-- project file to compile the test milter of the Ada Milter API
-- Copyright 2013 B. Persson, Bjorn@Rombobeorn.se
--
-- This project file is free software: you can redistribute it and/or modify it
-- under the terms of the GNU General Public License version 3, as published
-- by the Free Software Foundation.
-with "milter_api";
-with "system_log";
-project Build_Test_Milter is
- for Main use ("test_milter");
- for Languages use ("Ada");
+with "comfignat.gpr";
+with "build_milter_api.gpr"; -- Link to the just compiled library.
+with "system_log.gpr";
+
+standard project Build_Test_Milter is
+
+ for Main use ("test_milter");
+ for Source_Dirs use ("test");
+ for Object_Dir use Comfignat.Objdir;
+ for Exec_Dir use Comfignat.Stage_Bindir;
package Compiler is
for Default_Switches ("Ada") use ("-g", "-gnato", "-Wall", "-Wextra");
diff --git a/thread_wrapper/build_thread_wrapper.gpr b/build_thread_wrapper.gpr
index 78325b4..f0dd181 100644
--- a/thread_wrapper/build_thread_wrapper.gpr
+++ b/build_thread_wrapper.gpr
@@ -1,4 +1,4 @@
--- Use this project file to compile the thread wrapper into a static library.
+-- project file to compile the thread wrapper into a static library
-- Copyright 2013 B. Persson, Bjorn@Rombobeorn.se
--
-- This project file is free software: you can redistribute it and/or modify it
@@ -6,15 +6,13 @@
-- by the Free Software Foundation.
-with "directories";
+with "comfignat.gpr";
library project Build_Thread_Wrapper is
-
- Destdir := external("DESTDIR", "");
-
for Library_Name use "adamilter_thread_wrapper";
for Library_Kind use "static";
- for Library_Dir use Destdir & Directories.Libdir;
for Languages use ("C");
-
+ for Source_Dirs use ("thread_wrapper");
+ for Object_Dir use Comfignat.Objdir;
+ for Library_Dir use Comfignat.Stage_Libdir;
end Build_Thread_Wrapper;
diff --git a/comfignat.gpr.in b/comfignat.gpr.in
new file mode 100644
index 0000000..8212336
--- /dev/null
+++ b/comfignat.gpr.in
@@ -0,0 +1,98 @@
+-- Comfignat configuration variables for GNAT project files
+-- Copyright 2013 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 project file
+-- 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.
+
+
+-- This project file defines directory variables for use in build-controlling
+-- project files. It is not to be installed on the target system.
+--
+-- Normally the preprocessing of this file will be controlled by comfignat.mk,
+-- which will make it import the directory project if one is provided. It can
+-- also be preprocessed manually if Make cannot be used for some reason. There
+-- are defaults that will be used if no preprocessor symbols are defined.
+
+
+#if Directory_GPR'Defined then
+ with $Directory_GPR;
+#end if;
+
+abstract project Comfignat is
+
+ #if Objdir'Defined then
+ Objdir := $Objdir;
+ #else
+ Objdir := "build";
+ #end if;
+ -- Intermediate files produced during the build shall be kept in Objdir.
+
+ #if Directory_Project'Defined then
+ -- Put intermediate files for different architectures in subdirectories
+ -- where they won't conflict with each other. (This is useful especially
+ -- with binder files when they are packaged in debug information packages
+ -- for multiarch systems.)
+ Objdir := Objdir & "/" & $Directory_Project.Hardware_Platform;
+ #end if;
+
+ #if Stagedir'Defined then
+ Stagedir := $Stagedir;
+ #else
+ Stagedir := external("DESTDIR", "");
+ #end if;
+ -- Files to be installed shall be placed under Stagedir instead of the root
+ -- directory.
+
+ #if Prefix'Defined then
+ Prefix := $Prefix;
+ #else
+ Prefix := "/usr/local";
+ #end if;
+
+ #if Exec_Prefix'Defined then
+ Exec_Prefix := $Exec_Prefix;
+ #else
+ Exec_Prefix := Prefix;
+ #end if;
+
+ #if Bindir'Defined then
+ Bindir := $Bindir;
+ #else
+ Bindir := Exec_Prefix & "/bin";
+ #end if;
+ Stage_Bindir := Stagedir & Bindir;
+ -- Programs intended to be run by users shall be installed in Stage_Bindir.
+
+ #if Libexecdir'Defined then
+ Libexecdir := $Libexecdir;
+ #else
+ Libexecdir := Exec_Prefix & "/libexec";
+ #end if;
+ Stage_Libexecdir := Stagedir & Libexecdir;
+ -- Programs intended to be run by other programs rather than by users shall
+ -- be installed under Stage_Libexecdir.
+
+ #if Includedir'Defined then
+ Includedir := $Includedir;
+ #else
+ Includedir := Prefix & "/include";
+ #end if;
+ Stage_Includedir := Stagedir & Includedir;
+ -- Source files needed for compiling against a library shall be installed
+ -- under Stage_Includedir.
+
+ #if Libdir'Defined then
+ Libdir := $Libdir;
+ #else
+ Libdir := Prefix & "/lib";
+ #end if;
+ Stage_Libdir := Stagedir & Libdir;
+ -- Binary libraries shall be installed in Stage_Libdir.
+
+end Comfignat;
diff --git a/comfignat.mk b/comfignat.mk
new file mode 100644
index 0000000..785a9f5
--- /dev/null
+++ b/comfignat.mk
@@ -0,0 +1,220 @@
+# Comfignat makefile foundation for configuring and building GNAT projects
+# Copyright 2013 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 makefile
+# 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.
+
+
+# This file contains generic Make code. It is designed to be included by other
+# makefiles, called containing makefiles, which add information specific to the
+# project at hand. Builds are controlled by GNAT project files which import the
+# abstract project Comfignat and use the directory variables it defines. For
+# libraries there shall also be usage projects to be installed on the target
+# system. Usage projects and the Comfignat project will be preprocessed with
+# Gnatprep. (Build projects may also be preprocessed.)
+#
+# If a directory project is provided, then the project files will get the
+# directory variables from there, otherwise the Make variables will be used.
+#
+# This file may not work with other Make clones than GNU Make. (Reusable Make
+# code is pretty much impossible to write without advanced Make features.) If
+# Make cannot be used for whatever reason, then it's not too difficult to run
+# the project files through Gnatprep manually.
+
+
+#
+# Program-name variables and the usual options variables are picked up from the
+# environment or the command line:
+#
+
+GNATPREP ?= gnatprep
+GNAT_BUILDER ?= gprbuild
+
+# If GNAT_BUILDER looks like it will invoke Gnatmake, then make the default
+# value of GNATFLAGS compatible with Gnatmake. Otherwise make it suitable for
+# building multi-language projects with GPRbuild.
+ifeq ($(findstring gnatmake,${notdir ${lastword ${GNAT_BUILDER}}}),)
+ GNATFLAGS ?= ${GNAT_BUILDER_FLAGS} \
+ -cargs:Ada ${ADAFLAGS} -cargs:C ${CFLAGS} \
+ -cargs:C++ ${CXXFLAGS} -cargs:Fortran ${FFLAGS} \
+ -largs ${LDFLAGS}
+else
+ GNATFLAGS ?= ${GNAT_BUILDER_FLAGS} -cargs ${ADAFLAGS} -largs ${LDFLAGS}
+endif
+
+# (DESTDIR is also supported.)
+
+
+#
+# These variables should be overridden on the command line as needed, but will
+# not be picked up from the environment:
+#
+
+dirgpr =
+# dirgpr should be the filename of the directory project if there is one. It
+# becomes the Gnatprep symbols Directory_GPR and Directory_Project.
+
+prefix = /usr/local
+exec_prefix = ${prefix}
+bindir = ${exec_prefix}/bin
+libexecdir = ${exec_prefix}/libexec
+datarootdir = ${prefix}/share
+datadir = ${datarootdir}
+sysconfdir = ${prefix}/etc
+localstatedir = ${prefix}/var
+includedir = ${prefix}/include
+libdir = ${prefix}/lib
+gprdir = ${datarootdir}/gpr
+localedir = ${datarootdir}/locale
+mandir = ${datarootdir}/man
+infodir = ${datarootdir}/info
+# These are the directories where different kinds of files will be installed on
+# the target system. Some of these directory variables aren't used in this file
+# but may be needed in containing makefiles.
+
+builddir = build
+objdir = ${builddir}/obj
+stagedir = ${builddir}/stage
+# Intermediate files produced during the build are kept in objdir. Files to be
+# installed are written to stagedir, and then copied to their destination in
+# the installation step.
+
+
+#
+# Containing makefiles should assign or append to these variables as needed:
+#
+
+ifneq (${origin configured_files},file)
+ configured_files := ${basename ${wildcard *.in}}
+endif
+# configured_files is a list of files to be produced in the preprocessing step
+# at the beginning of the build. Containing makefiles may override it or append
+# additional filenames to it.
+
+ifneq (${origin build_GPRs},file)
+ build_GPRs :=
+endif
+# build_GPRs shall name one or more project files for building the software.
+# These project files will be used when "make" or "make build" is invoked.
+
+ifneq (${origin usage_GPRs},file)
+ usage_GPRs :=
+endif
+# If the build produces libraries, then usage_GPRs shall name the project files
+# that other projects should import to link to the libraries. These project
+# files will be installed to the target system.
+
+ifneq (${origin options},file)
+ options :=
+endif
+# options may be assigned a list of variable names. Those variables may be
+# overridden on the command line, and will be defined as Gnatprep symbols.
+# Their values must be "true" or "false".
+# The containing makefile should assign a default value to each variable unless
+# it shall be mandatory to always set the option on the command line.
+
+ifneq (${origin Gnatprep_definitions},file)
+ Gnatprep_definitions :=
+endif
+# Any text assigned to Gnatprep_definitions will be included in the Gnatprep
+# command line. It may be used for additional symbol definitions.
+
+
+#
+# Compute the symbol definitions for Gnatprep, and some other data that the
+# rules need:
+#
+
+# Convey objdir and stagedir to Gnatprep.
+definitions = '-DObjdir="${objdir}"' '-DStagedir="${stagedir}"'
+
+# Convey the prefix variables too, although they're supposed to be unused when
+# the preprocessing is done with Make.
+definitions += '-DPrefix="${prefix}"' '-DExec_Prefix="${exec_prefix}"'
+
+# If a directory project is used, then make project files take the directory
+# variables from there. Otherwise convey the ones defined above.
+ifeq (${dirgpr},)
+ definitions += '-DBindir="${bindir}"' '-DLibexecdir="${libexecdir}"'
+ definitions += '-DIncludedir="${includedir}"' '-DLibdir="${libdir}"'
+else
+ directory_project := ${basename ${notdir ${dirgpr}}}
+ definitions += '-DDirectory_GPR="${dirgpr}"'
+ definitions += '-DDirectory_Project=${directory_project}'
+ definitions += '-DBindir=${directory_project}.Bindir'
+ definitions += '-DLibexecdir=${directory_project}.Libexecdir'
+ definitions += '-DIncludedir=${directory_project}.Includedir'
+ definitions += '-DLibdir=${directory_project}.Libdir'
+endif
+
+# Convey boolean options to Gnatprep.
+definitions += \
+ ${foreach option,${options},\
+ ${if ${and ${filter-out environment,${origin ${option}}},\
+ ${filter 1,${words ${${option}}}},\
+ ${filter true false,${${option}}}},\
+ -D${option}=${${option}},\
+ ${error ${option} must be "true" or "false".}}}
+# For each variable listed in options, check that it didn't come from the
+# environment (to prevent accidents), that its value is a single word, and that
+# that word is either "true" or "false". If so, append a symbol definition;
+# otherwise complain and stop.
+
+# Convey any additional symbols that the containing makefile has defined.
+definitions += ${Gnatprep_definitions}
+
+build_targets = ${addsuffix .phony_target,${build_GPRs}}
+
+stage_any_GPRs = ${if ${usage_GPRs},stage_GPRs}
+
+build_GPR = "${GNAT_BUILDER}" -P ${firstword ${filter %.gpr,$^}} -p \
+ ${GNATFLAGS} -margs
+# build_GPR is a command for use in recipies. It performs a build controlled by
+# the first project file among the rule's prerequisites. Arguments for the
+# builder may be appended.
+
+
+#
+# Make rules:
+#
+
+.SECONDEXPANSION:
+
+all: build
+
+%.gpr: %.gpr.in
+ "${GNATPREP}" $< $@ ${definitions}
+
+configure: $${configured_files}
+
+%.gpr.phony_target: %.gpr configure
+ ${build_GPR}
+# Instead of tracking dependencies between project files, this rule simply
+# requires that all preprocessing is done before any project is built.
+
+stage_GPRs: $${usage_GPRs}
+ mkdir -p "${stagedir}${gprdir}"
+ cp -p ${usage_GPRs} "${stagedir}${gprdir}"
+.PHONY: stage_GPRs
+
+build: $${build_targets} $${stage_any_GPRs}
+
+${stagedir}:
+ @${MAKE} build --no-print-directory
+# "make install" straight out of a source package triggers a build, but if
+# something has been built then "make install" doesn't rebuild anything, just
+# copies the built files to their destination.
+
+install: ${stagedir}
+ mkdir -p "${DESTDIR}/"
+ cp -RPpf "${stagedir}"/* "${DESTDIR}/"
+.PHONY: install
+
+clean::
+ rm -Rf ${builddir} ${configured_files}
diff --git a/directories.gpr b/directories.gpr
deleted file mode 100644
index 689d436..0000000
--- a/directories.gpr
+++ /dev/null
@@ -1,18 +0,0 @@
--- Default directories
--- Copyright 2012 B. Persson, Bjorn@Rombobeorn.se
--- You may do whatever you want with this file as long as you acknowledge the
--- author's copyright.
-
--- If your system has a global directories.gpr and you want to install to the
--- directories it specifies, then just delete this file and let the build use
--- the global one. Otherwise edit the paths below to your liking.
-
-
-project Directories is
- Hardware_Platform := "";
- Libdir := "/usr/local/lib";
- Bindir := "/usr/local/bin";
- Libexecdir := "/usr/local/libexec";
- Includedir := "/usr/local/include";
- for Source_Files use ();
-end Directories;
diff --git a/milter_api.gpr b/milter_api.gpr.in
index 741cfe4..4ec7ebf 100644
--- a/milter_api.gpr
+++ b/milter_api.gpr.in
@@ -5,16 +5,26 @@
-- under the terms of the GNU General Public License version 3, as published
-- by the Free Software Foundation.
-with "directories";
-project Milter_API is
- for Library_Name use "adamilter";
- for Source_Dirs use (Directories.Includedir & "/adamilter");
- for Library_Dir use Directories.Libdir;
- for Library_ALI_Dir use Directories.Libdir & "/adamilter";
+
+#if Directory_GPR'Defined then
+with $Directory_GPR;
+#end if;
+
+library project Milter_API is
+
+ for Library_Name use "adamilter";
+ for Library_Kind use "dynamic";
+ for Source_Dirs use ($Includedir & "/adamilter");
+ for Library_Dir use $Libdir;
+ for Library_ALI_Dir use $Libdir & "/adamilter";
for Externally_Built use "true";
+ #if Wrap_Threads then
package Linker is
+ -- Programs that link to libadamilter shall link to
+ -- libadamilter_thread_wrapper and libdl too.
for Linker_Options use ("-ladamilter_thread_wrapper", "-ldl");
end Linker;
+ #end if;
end Milter_API;