Debian Codegraph @

Makefile

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 # GMPAda, binding to the Ada Language for the GNU MultiPrecision library.
2 # Copyright (C) 2007-2022 Nicolas Boulenguez <[email protected]>
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 ########################
18 # Global configuration #
19 ########################
20
21 LIB_NAME := gmpada
22
23 ################################
24 # Build and test configuration #
25 ################################
26
27 # For build flags:
28 # * settings from the environment are appended and take precedence.
29 # * Settings from the command line fully replace the default.
30
31 # Option for the Ada compiler
32 ADAFLAGS := -g -O2 -gnataEfnoqQ -gnatVa -Wall -Wextra -gnatw.eH.Y \
33 -gnatyBdIoOSuxy $(ADAFLAGS)
34
35 # Options for the C and C++ preprocessors
36 CPPFLAGS ?=
37
38 # Options for the C compiler
39 CFLAGS := -g -O2 -Wall -Wextra -pedantic $(CFLAGS)
40
41 # Options for the C++ compiler
42 CXXFLAGS := -Wall -Wextra $(CXXFLAGS)
43
44 # Options for the linker
45 LDFLAGS := -Wl,--as-needed -Wl,--no-allow-shlib-undefined \
46 -Wl,--no-copy-dt-needed-entries -Wl,--no-undefined $(LDFLAGS)
47
48 # Options for gnatmake
49 GNATMAKE_OPTIONS ?=
50
51 # A -j option in GNATMAKEFLAGS will be more efficient and produce
52 # readable logs. Never allow make -j to interfer.
53 .NOTPARALLEL:
54
55 # We want the same compiler for C, C++ and Ada, so the default value
56 # from Make is not sufficient. The following works on Debian but will
57 # probably require a command line override in other contexts.
58 GNATMAKE := gnatmake
59 gnat_version := $(shell $(GNATMAKE) --version | sed 's/.* \([0-9]\+\).*/\1/;q')
60 CC := gcc-$(gnat_version)
61 CXX := g++-$(gnat_version)
62
63 # Objects for the linker (FOO.o, libFOO.a, libFOO.so or -lFOO)
64 # The order may matter with --as-needed.
65 LDLIBS := -lgmp $(LDLIBS)
66
67 ##############################
68 # Installation configuration #
69 ##############################
70
71 prefix := /usr
72 datarootdir := $(prefix)/share
73 libdir := $(prefix)/lib
74
75 # The sources files are installed into a LIB_NAME subdirectory of
76 SRC_DIR := $(datarootdir)/ada/adainclude
77
78 # A LIB_NAME.gpr project convenient for library usage is installed into
79 gnat_project := $(LIB_NAME).gpr
80 GPR_DIR := $(datarootdir)/gpr
81
82 # The content of this file ignores DESTDIR.
83 # The GNAT ALI files are installed into a LIB_NAME subdirectory of
84 ALI_DIR := $(libdir)/ada/adalib
85
86 # The static archive is installed into
87 static_library := lib$(LIB_NAME).a
88 A_DIR := $(libdir)
89
90 # The shared library is installed into
91 SOVERSION := 2
92 shared_object_name := lib$(LIB_NAME).so.$(SOVERSION)
93 shared_library := $(shared_object_name)
94 development_link := lib$(LIB_NAME).so
95 SO_DIR := $(libdir)
96
97 # DESTDIR allows staged installs. It is prefixed to actual
98 # installation paths but ignored otherwise.
99
100 #########
101 # Rules #
102 #########
103
104 ada_units := $(wildcard src/*.adb) \
105 src/gmp.ads \
106 src/gmp-h.ads \
107 src/gnu_multiple_precision-text_io.ads \
108 src/gnu_multiple_precision-wide_text_io.ads \
109 src/gnu_multiple_precision-wide_wide_text_io.ads
110
111 # Default target is:
112 .PHONY: build
113 build: obj/$(shared_library) obj/$(static_library) obj/$(gnat_project)
114
115 # Phony so that GNATMAKE deals with Ada dependencies, not MAKE.
116 .PHONY: obj/$(shared_library)
117 obj/$(shared_library): src/gmp-h.ads obj-dynamic/gmp_macros.o | obj obj-dynamic
118 $(GNATMAKE) -c $(ada_units) -D obj-dynamic $(GNATMAKE_OPTIONS) \
119 -cargs $(ADAFLAGS) -fPIC
120 $(CC) -shared -o $@ -Wl,-soname,$(shared_object_name) \
121 obj-dynamic/*.o $(LDFLAGS) -lgnat $(LDLIBS)
122
123 .PHONY: obj/$(static_library)
124 obj/$(static_library): src/gmp-h.ads obj-static/gmp_macros.o | obj obj-static
125 $(GNATMAKE) -c $(ada_units) -D obj-static $(GNATMAKE_OPTIONS) \
126 -cargs $(ADAFLAGS)
127 ar cr $@ obj-static/*.o
128 ranlib $@
129
130 obj-dynamic/gmp_macros.o: src/gmp_macros.c | obj-dynamic
131 $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ -fPIC
132
133 obj-static/gmp_macros.o: src/gmp_macros.c | obj-static
134 $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
135
136 obj/$(gnat_project): template_for_installed_project | obj
137 sed \
138 -e '/@LDLIBS@/{s||$(patsubst %,"%",$(LDLIBS))|;s/" "/", "/g}' \
139 $(foreach v,ALI_DIR LIB_NAME SO_DIR SRC_DIR,-e "s|@$(v)@|$($(v))|") \
140 $< > $@
141
142 src/gmp-h.ads: gmp-h.ads.sed | obj
143 echo '#include <gmp.h>' > obj/tmp.h
144 cd obj && $(CXX) $(CPPFLAGS) $(CXXFLAGS) --dump-ada-spec tmp.h
145 sed -f $< obj/*_gmp_h.ads > $@
146 # Uncomment this when debugging a new version
147 # diff -u obj/*_gmp_h.ads $@ | less
148
149 obj obj-dynamic obj-static:
150 mkdir $@
151 clean::
152 rm -f src/gmp-h.ads
153 rm -fr obj obj-dynamic obj-static
154 find -name "*~" -delete
155
156 ######################################################################
157 .PHONY: test
158 test: | demo-dynamic demo-static
159 $(MAKE) install DESTDIR=demo-install
160
161 $(GNATMAKE) demo.adb \
162 -o demo-dynamic/demo -D demo-dynamic $(GNATMAKE_OPTIONS) \
163 -aIdemo-install$(SRC_DIR)/$(LIB_NAME) \
164 -aOdemo-install$(ALI_DIR)/$(LIB_NAME) \
165 -cargs $(ADAFLAGS) -gnata \
166 -largs $(LDFLAGS) demo-install$(SO_DIR)/$(development_link) $(LDLIBS)
167 LD_LIBRARY_PATH=demo-install$(SO_DIR) demo-dynamic/demo
168
169 $(GNATMAKE) demo.adb \
170 -o demo-static/demo -D demo-static $(GNATMAKE_OPTIONS) \
171 -aIdemo-install$(SRC_DIR)/$(LIB_NAME) \
172 -aOdemo-install$(ALI_DIR)/$(LIB_NAME) \
173 -cargs $(ADAFLAGS) -gnata \
174 -largs $(LDFLAGS) demo-install$(A_DIR)/$(static_library) $(LDLIBS)
175 demo-static/demo
176
177 $(MAKE) uninstall DESTDIR=demo-install
178 test `find demo-install -type f | wc -l` = 0
179
180 demo-dynamic demo-static:
181 mkdir $@
182 clean::
183 rm -f b~demo.adb b~demo.ads b~demo.ali b~demo.o
184 rm -fr demo-dynamic demo-install demo-static
185
186 ######################################################################
187 .PHONY: install
188 install: build
189 install -m644 -Dt$(DESTDIR)$(SRC_DIR)/$(LIB_NAME) src/*
190 install -m644 -Dt$(DESTDIR)$(GPR_DIR) obj/$(gnat_project)
191 install -m444 -Dt$(DESTDIR)$(ALI_DIR)/$(LIB_NAME) obj-dynamic/*.ali
192 install -m644 -Dt$(DESTDIR)$(A_DIR) obj/$(static_library)
193 install -m644 -Dt$(DESTDIR)$(SO_DIR) obj/$(shared_library)
194 ln -fs $(shared_library) $(DESTDIR)$(SO_DIR)/$(development_link)
195
196 .PHONY: uninstall
197 uninstall:
198 rm -fr $(DESTDIR)$(SRC_DIR)/$(LIB_NAME) \
199 $(DESTDIR)$(ALI_DIR)/$(LIB_NAME)
200 rm -f $(DESTDIR)$(GPR_DIR)/$(gnat_project) \
201 $(DESTDIR)$(A_DIR)/$(static_library) \
202 $(DESTDIR)$(SO_DIR)/$(shared_library) \
203 $(DESTDIR)$(SO_DIR)/$(development_link)
204
205 ######################################################################
206 .PHONY: clean