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
|
# GMPAda, binding to the Ada Language for the GNU MultiPrecision library.
# Copyright (C) 2007-2013 Nicolas Boulenguez <nicolas.boulenguez@free.fr>
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
########################
# Global configuration #
########################
LIB_NAME := gmpada
SOVERSION := 2
################################
# Build and test configuration #
################################
# Use environment variables if available, this is common practice for
# CFLAGS and LDFLAGS.
CPPFLAGS ?=
CFLAGS ?= -O2
ADAFLAGS ?= -O2 -gnatn
# Inlining helps a lot for the thin binding.
LDFLAGS ?=
.NOTPARALLEL:
GNATMAKE_OPTIONS := -j$(shell getconf _NPROCESSORS_ONLN)
ifdef ALL_CHECKS
CFLAGS += -Wall -Wextra -Wformat -Wformat-security -g
ADAFLAGS += -Wall -Wextra -g -gnataEfoqQ -gnatVa -gnatw.eH \
-gnatydoSuxy
GNATMAKE_OPTIONS += -s -we
endif
# We want the same compiler for C and Ada sources.
CC := $(shell gnatmake --version | sed -n '1 s/GNATMAKE /gcc-/p')
LDLIBS := -lgmp -lmpfr
##############################
# Installation configuration #
##############################
# Each of the following path should be prefixed with
DESTDIR :=
# The sources files are installed into a LIB_NAME subdirectory of
SRC_DIR := usr/share/ada/adainclude
# A LIB_NAME.gpr project convenient for library usage is installed into
GPR_DIR := usr/share/ada/adainclude
# The content of this file ignores DESTDIR.
# The GNAT ALI files are installed into a LIB_NAME subdirectory of
ALI_DIR := usr/lib/ada/adalib
# The static and dynamic library are installed into
LIB_DIR := usr/lib
################################
# Make magic to replace spaces #
################################
comma := ,
empty :=
space := $(empty) $(empty)
#########
# Rules #
#########
build: build-dynamic build-static
build-dynamic build-static: build-%: src/gmp-constants.ads
gnatmake -P$(LIB_NAME).gpr $(GNATMAKE_OPTIONS) -XKIND=$*
clean::
rm -f $(foreach dir,obj lib,$(foreach kind,dynamic static,build-$(dir)-$(kind)/*))
src/gmp-constants.ads: generate_constants
./$< > $@
clean::
rm -f src/gmp-constants.ads generate_constants
clean::
find -name "*~" -delete
TEST_PROJECT := demo/demo.gpr
test: build-static
gnatmake -P$(TEST_PROJECT) $(GNATMAKE_OPTIONS) -XKIND=static
demo/demo
# LIB_NAME.gpr is found in the current directory when executing this
# recipe, and in the default system location after installation.
clean:: $(LIB_NAME).gpr
# See below for an explanation of this prerequisite.
clean::
gnatclean -q -P$(TEST_PROJECT) -XKIND=static
install: build
install --directory $(DESTDIR)/$(SRC_DIR)/$(LIB_NAME)
install --mode=644 src/*.ad[sb] src/*.[ch] $(DESTDIR)/$(SRC_DIR)/$(LIB_NAME)
install --directory $(DESTDIR)/$(GPR_DIR)
sed template_for_installed_project \
$(foreach var,LIB_NAME SRC_DIR ALI_DIR LDLIBS LIB_DIR, \
-e 's|$$($(var))|$(subst $(space),"$(comma) ",$($(var)))|g') \
> $(DESTDIR)/$(GPR_DIR)/$(LIB_NAME).gpr
chmod 644 $(DESTDIR)/$(GPR_DIR)/$(LIB_NAME).gpr
install --directory $(DESTDIR)/$(ALI_DIR)/$(LIB_NAME)
install --mode=444 build-lib-dynamic/*.ali $(DESTDIR)/$(ALI_DIR)/$(LIB_NAME)
install --directory $(DESTDIR)/$(LIB_DIR)
install --mode=644 build-lib-static/lib$(LIB_NAME).a $(DESTDIR)/$(LIB_DIR)
install --mode=644 build-lib-dynamic/lib$(LIB_NAME).so.$(SOVERSION) $(DESTDIR)/$(LIB_DIR)
cd $(DESTDIR)/$(LIB_DIR) && ln --force --symbolic lib$(LIB_NAME).so.$(SOVERSION) lib$(LIB_NAME).so
uninstall:
rm -rf $(DESTDIR)/$(SRC_DIR)/$(LIB_NAME)
rm -f $(DESTDIR)/$(GPR_DIR)/$(LIB_NAME).gpr
rm -rf $(DESTDIR)/$(ALI_DIR)/$(LIB_NAME)
rm -f $(DESTDIR)/$(LIB_DIR)/lib$(LIB_NAME).a
rm -f $(DESTDIR)/$(LIB_DIR)/lib$(LIB_NAME).so.$(SOVERSION)
rm -f $(DESTDIR)/$(LIB_DIR)/lib$(LIB_NAME).so
############################################################
# All that C stuff will be unnecessary with gprbuild’s mixed C/Ada
# project files. For the moment, gnatmake will embed all .o files,
# we only have to compile them and store them in the object dir.
C_SRC := $(wildcard src/*.c)
C_OBJ_DYNAMIC := $(patsubst src/%.c,build-obj-dynamic/%.o,$(C_SRC))
build-dynamic: $(C_OBJ_DYNAMIC)
$(C_OBJ_DYNAMIC): build-obj-dynamic/%.o: src/%.c
$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ -fPIC
C_OBJ_STATIC := $(patsubst src/%.c,build-obj-static/%.o, $(C_SRC))
build-static: $(C_OBJ_STATIC)
$(C_OBJ_STATIC): build-obj-static/%.o: src/%.c
$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
######################################################################
# gnatmake 4.4 does not handle External_As_List, so we emulate it with
# a template instead of passing the options with -X.
build-dynamic build-static: $(LIB_NAME).gpr
# This is a prerequisite for clean too, but it must bea added before
# gnatclean is called.
$(LIB_NAME).gpr: %.gpr: %.gpr.sed
sed $< \
$(foreach var,ADAFLAGS CFLAGS CPPFLAGS LDFLAGS LDLIBS SOVERSION, \
-e 's/$(var)/$(subst $(space),"$(comma) ",$($(var)))/') \
> $@
clean::
rm -f $(LIB_NAME).gpr
.PHONY: build build-dynamic build-static clean install test uninstall
|