Ian Jauslin
summaryrefslogtreecommitdiff
blob: d73250a50bdeb665c6b0c13aee79382dc9447fcd (plain)
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
## Copyright 2016 Ian Jauslin
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
##     http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.

# whether to compile only the static library, only the dynamic library, or both
#   if static=0 then compile both
#   if static=2 then compile the dynamic library
#   if static=1 then compile the static library
STATIC=0

VERSION=1.0

# products of the compilation
PROJECT_SO=libinum.so.$(VERSION)
PROJECT_LIBS=libinum.a
PROJECT_DOCS=libinum-doc.html

# debug and optimization flags
#DB= -ggdb
OPT= -O3

# warning flags
WARNINGS= -Wall -Wextra -Wno-strict-overflow -std=c99 -pedantic

# installation dirs
PREFIX=/usr
LIBDIR=$(PREFIX)/lib
INCLUDEDIR=$(PREFIX)/include
DOCDIR=$(PREFIX)/share/doc/libinum

# compiler
CC=/usr/bin/gcc
LD=$(CC)
AR=/usr/bin/ar

# directories
INCLUDE = 
LIB = 

# flags
override LDFLAGS +=$(LIB)
override CFLAGS +=$(INCLUDE)$(DB) $(OPT) $(WARNINGS)

# build directories
BUILDDIR=./build
SRCDIR=./src
OBJDIR=./objs

# objects
LIBINUM_OBJS = $(addprefix $(OBJDIR)/, array.o integral.o utils.o polynomial.o polynomialMV.o root.o)


ifeq ($(STATIC),1)
  # compile libinum.a
  PREREQ=static
  # install static lib
  INSTALLLIB=install-static
else ifeq ($(STATIC),2)
  # compile libinum.so.$(VERSION)
  PREREQ=shared
  # install shared lib
  INSTALLLIB=install-shared
else
  # compile both
  PREREQ=shared static
  # install both
  INSTALLLIB=install-shared install-static
endif


all:	init $(PREREQ)

# create dirs
init:
	@[ -d $(OBJDIR) ] || /bin/mkdir $(OBJDIR)
	@[ -d $(BUILDDIR) ] || /bin/mkdir $(BUILDDIR)

# static library
static: $(PROJECT_LIBS)
# shared library
shared: $(PROJECT_SO)

libinum.a: $(LIBINUM_OBJS)
	$(AR) -rc $(BUILDDIR)/$@ $^

libinum.so.$(VERSION): $(LIBINUM_OBJS)
	$(LD) -shared -lm -lmpfr -lgmp -lpthread $(LDFLAGS) -o $(BUILDDIR)/$@ $^
	ln -fs ./libinum.so.$(VERSION) $(BUILDDIR)/libinum.so

%.o :	../$(SRCDIR)/%.c
	$(CC) -c $(CFLAGS) -fPIC $< -o $@

install: $(INSTALLLIB) all
	mkdir -p $(MANDIR) $(DOCDIR) $(INCLUDEDIR)/libinum
	cp -rL include/libinum/* $(INCLUDEDIR)/libinum/
	install -Dm644 include/libinum.h $(INCLUDEDIR)/
	cp -r doc/libinum-examples $(DOCDIR)/
	install -Dm644 $(addprefix doc/,$(PROJECT_DOCS)) $(DOCDIR)/

install-static: all
	mkdir -p $(LIBDIR)
	install -Dm755 $(addprefix $(BUILDDIR)/,$(PROJECT_LIBS)) $(LIBDIR)/
install-shared: all
	mkdir -p $(LIBDIR)
	install -Dm755 $(addprefix $(BUILDDIR)/,$(PROJECT_SO)) $(LIBDIR)/
	for lib in $(PROJECT_SO); do ln -fs ./$$lib $(LIBDIR)/$${lib%.so.*}.so; done

clean:
	@rm -rf $(OBJDIR)
	@rm -rf $(BUILDDIR)