1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
|
#!/usr/bin/make -f
# Build script for GPRBuild in Debian.
# Copyright (c) 2009-2012 Stephen Leake <stephen_leake@stephe-leake.org>
# Copyright (c) 2013-2018 Nicolas Boulenguez <nicolas@debian.org>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
# On Debian systems, the full text of the GPL is in the file
# /usr/share/common-licenses/GPL-3.
# NOTE:
# In order to prevent a circular build-dependency, the Debian packages
# for XML/Ada and GPRBuild bother to build without project support.
# Please keep the two debian/rules files similar enough to ease
# backport of good ideas.
######################################################################
# *_DEV_PKG, *_LIB_PKG and *_SONAME are read from the control file.
# To debug, replace eval with error.
$(foreach line,$(shell sed -n ' \
s/^Package:\s*\(lib\([a-z]\+\)\([0-9.]\+\)\)$$/ \
\2_LIB_PKG:=\1 \
\2_SONAME:=lib\2.so.\3 \
/p;\
s/^Package:\s*\(lib\([a-z]\+\)[0-9.]\+-dev\)$$/ \
\2_DEV_PKG:=\1 \
/p;\
s/^ gnat, gnat-\([0-9.]\+\),\?$$/ \
GNAT_VERSION:=\1 \
/p;\
s/^ \(libxmlada-\([a-z]\+\)[0-9.]\+-dev\)\( (.*)\)\?,\?$$/ \
xmlada_\2_DEV_PKG:=\1 \
/p;\
' debian/control),$(eval $(line)))
DEB_BUILD_MAINT_OPTIONS := hardening=+all
DEB_ADAFLAGS_MAINT_APPEND := -gnatwa -Wall -gnatn
DEB_LDFLAGS_MAINT_APPEND := -Wl,--as-needed -Wl,--no-undefined \
-Wl,--no-copy-dt-needed-entries -Wl,--no-allow-shlib-undefined
include /usr/share/dpkg/default.mk
include /usr/share/ada/debian_packaging-$(GNAT_VERSION).mk
# gprbuild.gpr selects inlining.
# It also selects -E -static binder options, but:
# #666106 affects only kfreebsd-i386, where storing tracebacks in
# exception occurrences causes a segmentation fault. This prevents
# handling of any exceptions. gprconfig relies on handling exceptions
# when parsing compilers.xml.
# Author: Ludovic Brenta <lbrenta@debian.org>
%:
dh $@
# Rewrite upstream configure/make build system.
.PHONY: $(addprefix override_dh_auto_, \
configure build-arch build-indep test install clean)
# Rewrite upstream targets without gprbuild or gprclean.
# gnatmake does not support projects anymore, we cannot use xmlada.gpr.
######################################################################
# Regenerate gpr-snames.ad[bs].
obj/shared/$(gpr_SONAME) obj/static/libgpr.a: gpr/src/gpr-snames.ads
obj/xsnames: gpr/xsnames.adb | obj
gnatmake gpr/xsnames.adb -D obj -o $@ \
$(BUILDER_OPTIONS) \
-cargs $(ADAFLAGS) \
-largs $(LDFLAGS)
gpr/src/gpr-snames.ads: obj/xsnames \
gpr/snames.list \
gpr/snames_spec_init.txt \
gpr/snames_spec_init.txt
cd gpr; ../$<
mv gpr/gpr-snames.ad[bs] gpr/src
override_dh_auto_clean::
rm -f gpr/src/gpr-snames.ad[bs]
######################################################################
ADS_DIR := usr/share/ada/adainclude
GPR_DIR := usr/share/gpr
ALI_DIR := usr/lib/$(DEB_HOST_MULTIARCH)/ada/adalib
SO_DIR := usr/lib/$(DEB_HOST_MULTIARCH)
A_DIR := usr/lib/$(DEB_HOST_MULTIARCH)
define library_template
# Parameters:
# _SRCDIR: directory containing the sources files
# _deps_int : used in -aI -aO -l for libs built by this deb source
# _deps_int_direct: subset used for .gpr and ada:Depends
# _deps_ext : used in -aI -aO -l for libs from packaged Build-Depends
# _deps_ext_direct: subset used for .gpr and ada:Depends
# _deps_gnarl : used in -l, should be empty or gnarl-BV
# For any dependency d, $(d)_DEV_PKG: deb -dev package for $(d)
# For any internal dependency d, $(d)_SRCDIR as above.
# Remove pure specifications and separate compilation units.
$(library)_unit_bodies := $(foreach s, \
$(wildcard $($(library)_SRCDIR)/*.adb) \
,$(if $(shell grep -l '^separate ' $(s)),,$(s)))
$(library)_c_sources := $(wildcard $($(library)_SRCDIR)/*.c)
# Build dynamic library.
override_dh_auto_build-arch: obj/shared/$($(library)_SONAME)
obj/shared/$($(library)_SONAME): \
$$(patsubst $($(library)_SRCDIR)/%.c,obj/shared_$(library)_obj/%.o,$$($(library)_c_sources)) \
| obj/shared obj/shared_$(library)_ali obj/shared_$(library)_obj
# -fPIC/-shared overrides -fPIE/-pie in ADAFLAGS/LDFLAGS.
gnatmake -c $$($(library)_unit_bodies) -D obj/shared_$(library)_obj \
$(BUILDER_OPTIONS) \
$(foreach l, $($(library)_deps_int), \
-aI$($(l)_SRCDIR) \
-aOobj/shared_$(l)_ali) \
$(addprefix -aI/$(ADS_DIR)/, $($(library)_deps_ext)) \
$(addprefix -aO/$(ALI_DIR)/, $($(library)_deps_ext)) \
-cargs $(ADAFLAGS) -fPIC
gcc-$(GNAT_VERSION) $(LDFLAGS) -shared \
-o $$@ \
-Wl,-soname,$($(library)_SONAME) \
obj/shared_$(library)_obj/*.o \
-Lobj/shared $(addprefix -l, $($(library)_deps_int) \
$($(library)_deps_ext) \
$($(library)_deps_gnarl) \
gnat-$(GNAT_VERSION))
# Create development link so that the other libraries may link with it.
ln -fs $($(library)_SONAME) obj/shared/lib$(library).so
# Move ALI files to library directory and mark them read-only.
mv obj/shared_$(library)_obj/*.ali obj/shared_$(library)_ali
chmod 444 obj/shared_$(library)_ali/*
# Build static library.
override_dh_auto_build-arch: obj/static/lib$(library).a
obj/static/lib$(library).a: \
$(patsubst $($(library)_SRCDIR)/%.c,obj/static_$(library)_obj/%.o,$($(library)_c_sources)) \
| obj/static obj/static_$(library)_ali obj/static_$(library)_obj
gnatmake -c $$($(library)_unit_bodies) -D obj/static_$(library)_obj \
$(BUILDER_OPTIONS) \
$(foreach l, $($(library)_deps_int), \
-aI$($(l)_SRCDIR) \
-aOobj/static_$(l)_ali) \
$(addprefix -aI/$(ADS_DIR)/, $($(library)_deps_ext)) \
$(addprefix -aO/$(ALI_DIR)/, $($(library)_deps_ext)) \
-cargs $(ADAFLAGS)
ar rc $$@ obj/static_$(library)_obj/*.o
ranlib $$@
# Move ALI files to library directory and mark them read-only.
mv obj/static_$(library)_obj/*.ali obj/static_$(library)_ali
chmod 444 obj/static_$(library)_ali/*.ali
obj/shared_$(library)_obj/%.o: $($(library)_SRCDIR)/%.c | obj/shared_$(library)_obj
gcc-$(GNAT_VERSION) -c $(CFLAGS) $(CPPFLAGS) $$< -o $$@ -fPIC
obj/static_$(library)_obj/%.o: $($(library)_SRCDIR)/%.c | obj/static_$(library)_obj
gcc-$(GNAT_VERSION) -c $(CFLAGS) $(CPPFLAGS) $$< -o $$@
obj/shared_$(library)_ali obj/shared_$(library)_obj obj/static_$(library)_ali obj/static_$(library)_obj: | obj
mkdir $$@
override_dh_install::
# dynamic library
dh_install --package=$($(library)_LIB_PKG) \
obj/shared/$($(library)_SONAME) \
$(SO_DIR)
# static library
dh_install --package=$($(library)_DEV_PKG) \
obj/static/lib$(library).a \
$(A_DIR)
# development symbolic link
dh_link --package=$($(library)_DEV_PKG) \
$(SO_DIR)/$($(library)_SONAME) \
$(SO_DIR)/lib$(library).so
# ALI files
dh_install --package=$($(library)_DEV_PKG) \
obj/shared_$(library)_ali/*.ali \
$(ALI_DIR)/$(library)
# Sources
dh_install --package=$($(library)_DEV_PKG) \
$($(library)_SRCDIR)/*.ad[bs] $$($(library)_c_sources) \
$(ADS_DIR)/$(library)
# Substitution variables for the control file.
echo 'ada:Depends=gnat, gnat-$(GNAT_VERSION), \
$(foreach l, $($(library)_deps_int_direct), $($(l)_DEV_PKG) (=$$$${binary:Version}),) \
$(foreach l, $($(library)_deps_ext_direct), $($(l)_DEV_PKG),) \
$($(library)_LIB_PKG)' \
>> debian/$($(library)_DEV_PKG).substvars
# Externally built project installed for end users.
override_dh_auto_build-arch: obj/$(library).gpr
obj/$(library).gpr: debian/template.gpr | obj
sed ' \
/@IMPORTS@/ { \
s//$(foreach l, $($(library)_deps_int_direct) \
$($(library)_deps_ext_direct) \
,with "$(l).gpr";\n)/; \
s/\n /\n/g; }; \
$(foreach v,library SO_DIR ADS_DIR ALI_DIR,s|@$(v)@|$($(v))|;) \
' $$< > $$@
override_dh_install::
dh_install --package=$($(library)_DEV_PKG) \
obj/$(library).gpr \
$(GPR_DIR)
endef
gpr_SRCDIR := gpr/src
gpr_deps_ext_direct := \
xmlada_schema xmlada_dom xmlada_sax xmlada_input
gpr_deps_ext := \
xmlada_schema xmlada_dom xmlada_sax xmlada_input xmlada_unicode
gpr_deps_gnarl := gnarl-$(GNAT_VERSION)
# To debug an instantiation, replace eval with error:
$(foreach library, \
gpr \
,$(eval $(call library_template)))
######################################################################
EXECUTABLES := gprbind gprbuild gprclean gprconfig gprinstall gprlib gprls gprname gprslave
override_dh_auto_build-arch: $(EXECUTABLES)
chmod 644 share/gprconfig/fallback_targets.xml
# Gnatmake knows better than Make if something is up to date.
.PHONY: $(EXECUTABLES)
# Some main units are poorly named.
gprbind gprlib gprslave: MAIN_EXT :=
gprbuild gprclean gprconfig gprinstall gprls gprname: MAIN_EXT := -main
# Each executable may not require each library, but there should be no
# consequence with --as-needed linker flag.
$(EXECUTABLES): obj/shared/$(gpr_SONAME) | obj
gnatmake $@$(MAIN_EXT).adb -aIsrc -D obj -o obj/$@ \
$(BUILDER_OPTIONS) \
-aI$(gpr_SRCDIR) -aOobj/shared_gpr_ali \
$(addprefix -aI/$(ADS_DIR)/, $(gpr_deps_ext)) \
$(addprefix -aO/$(ALI_DIR)/, $(gpr_deps_ext)) \
-cargs $(ADAFLAGS) \
-largs $(LDFLAGS) \
-Lobj/shared $(addprefix -l, gpr $(gpr_deps_ext))
obj/shared obj/static: | obj
obj obj/shared obj/static:
mkdir $@
override_dh_auto_clean::
rm -fr obj
# Remaining install tasks.
.PHONY: override_dh_install
override_dh_install::
dh_install --remaining-packages
|