23
SOVERSION := $(shell sed -n 's/.*Soversion *:= *"\([[:digit:].]\+\)";.*/\1/p' $(LIB_NAME).gpr)
25
25
################################
26
26
# Build and test configuration #
27
27
################################
29
# Default values if these variables are not set in the environment.
30
# These flags are used in this Makefile as usual, in particular in the
31
# implicit rule compiling generate_constants.c. Prefer overriding them
32
# instead of cargs or largs..
34
LDFLAGS ?= -Wl,--as-needed
35
# -g: produce debugging information
36
# -O2: default optimization
37
# -Wl,--as-needed: link only needed libraries
39
# Gprbuild allows setting specific flags for each step (Compiler,
40
# Binder, Linker, Gprbuild) and language.
42
cargs_Ada := -gnatn -gnatw.e -gnatwH
44
gargs := -R -s -j$(shell getconf _NPROCESSORS_ONLN)
45
# -gnatn: allow subprogram inlining
46
# -gnatw.e: activate all optional warnings
47
# -gnatwH: except hiding
48
# -R: no run path option
49
# -s: recompile if compilation switches have changed
51
# Here is the exhaustive flag list.
53
cargs cargs_Ada cargs_C \
54
bargs bargs_Ada bargs_C \
55
largs largs_Ada largs_C \
59
# Note that -gargs must come last, or else following flags will be
60
# interpreted as linker flags.
62
# Build the actual command line flags. For readability, only append
63
# the non-empty variables.
64
define append_gprbuild_flag
66
GPRBUILD_FLAGS += -$(subst _,:,$(1)) $$($(1))
69
$(foreach var,$(gpr_flag_names),$(eval $(call append_gprbuild_flag,$(var))))
29
# Use environment variables if available, this is common practice for
36
GPRBUILD_OPTIONS := -j$(shell getconf _NPROCESSORS_ONLN)
39
CFLAGS += -Wall -Wextra -Wformat -Wformat-security -g
40
ADAFLAGS += -Wall -Wextra -g -gnatE -gnatQ -gnatVa -gnata -gnatf \
41
-gnato -gnatq -gnatySdouxy
42
GPRBUILD_OPTIONS += -s -we
45
# We want the same compiler for generate_constants.c and the library.
71
48
##############################
72
49
# Installation configuration #
75
52
# Each of the following path should be prefixed with
78
# The sources files are installed into a $(LIB_NAME) subdirectory of
55
# The sources files are installed into a LIB_NAME subdirectory of
79
56
SRC_DIR := usr/share/ada/adainclude
81
# A $(LIB_NAME).gpr project convenient for library usage is installed into
58
# A LIB_NAME.gpr project convenient for library usage is installed into
82
59
GPR_DIR := usr/share/ada/adainclude
83
60
# The content of this file ignores DESTDIR.
85
# The GNAT ALI files are installed into a $(LIB_NAME) subdirectory of
62
# The GNAT ALI files are installed into a LIB_NAME subdirectory of
86
63
ALI_DIR := usr/lib/ada/adalib
88
65
# The static and dynamic library are installed into
72
# Function exporting a variable on the command line.
73
to_X_options = $(foreach var,$(1),-X$(var)="$($(var))")
95
75
build: build-dynamic build-static
97
77
build-dynamic build-static: build-%: src/gmp-constants.ads
98
gprbuild $(GPRBUILD_FLAGS) $(LIB_NAME).gpr -XKIND=$*
78
gprbuild $(LIB_NAME).gpr $(GPRBUILD_OPTIONS) -XKIND=$* $(call to_X_options,\
79
ADAFLAGS CFLAGS LDFLAGS SOVERSION)
100
82
rm -f $(foreach dir,obj lib,$(foreach kind,dynamic static,build-$(dir)-$(kind)/*))
112
94
find -name "*~" -delete
114
96
test: build-static
115
gprbuild $(GPRBUILD_FLAGS) demo/demo.gpr -XKIND=static
97
gprbuild demo/demo.gpr $(GPRBUILD_OPTIONS) -XKIND=static $(call to_X_options,\
98
ADAFLAGS CFLAGS LDFLAGS)
100
# Gmpada.gpr is found in the current directory when executing this
101
# recipe, and will be found in the default system location after
118
rm -f demo/demo demo/obj/*
104
gprclean -q demo/demo.gpr -XKIND=static
121
107
install --directory $(DESTDIR)/$(SRC_DIR)/$(LIB_NAME)
140
126
rm -f $(DESTDIR)/$(LIB_DIR)/lib$(LIB_NAME).so.$(SOVERSION)
141
127
rm -f $(DESTDIR)/$(LIB_DIR)/lib$(LIB_NAME).so
143
# Paranoid flags for developpers.
145
# -g: debugging information
146
# -Wall: optional warnings
147
# -Wextra: extra warnings
148
# -fstack-check: stack overflow checking
149
# -gnatf: full errors
151
# -gnatQ: generate ALI files for cross-ref
152
# -gnata: Assert and Debug pragmas
153
# -gnatVa: all validity checks
154
# -gnaty: all style checks
155
# -gnatyM159: max line length
156
# -gnato: runtime overflow checking
157
# -gnatE: checks for access-before-elaboration
158
# -E: exception backtraces
160
$(MAKE) test CFLAGS="-g -O2 -Wall -Wextra -fstack-check" \
161
cargs_Ada="-gnatn -gnatw.e -gnatwH -gnatf -gnatq -gnatQ -gnata -gnatVa -gnaty -gnatyM159 -gnato -gnatE" \
164
.PHONY: build build-dynamic build-static clean devel install test uninstall
129
.PHONY: build build-dynamic build-static clean install test uninstall