Ian Jauslin
summaryrefslogtreecommitdiff
blob: 493117519597c759db44bfd7e09f45b2030dc3c8 (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
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
## Copyright 2015 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 link dynamically
#   if static=0 then link dynamically
#   if static=2 then link statically
#   if static=1 then link libkondo statically but other libraries dynamically
STATIC=1

VERSION=1.2

# products of the compilation
PROJECT_BINS= meankondo numkondo meantools kondo_preprocess meantools-convert
PROJECT_SO=libkondo.so.$(VERSION)
PROJECT_LIBS=libkondo.a
PROJECT_MANS=meankondo.1 numkondo.1 meantools.1 meantools-convert.1 kondo_preprocess.1
PROJECT_SCRIPTS=config_functions.sh
PROJECT_DOCS=meankondo-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
BINDIR=$(PREFIX)/bin
LIBDIR=$(PREFIX)/lib
MANDIR=$(PREFIX)/share/man/man1
SCRIPTDIR=$(PREFIX)/share/meankondo/scripts
DOCDIR=$(PREFIX)/share/doc/meankondo-doc

# 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
LIBKONDO_OBJS = $(addprefix $(OBJDIR)/,array.o cli_parser.o coefficient.o fields.o grouped_polynomial.o idtable.o istring.o number.o parse_file.o polynomial.o rational_float.o rational_int.o rcc.o tools.o)
MEANKONDO_OBJS = $(addprefix $(OBJDIR)/,meankondo.o mean.o)
NUMKONDO_OBJS = $(addprefix $(OBJDIR)/,numkondo.o flow.o)
MEANTOOLS_OBJS = $(addprefix $(OBJDIR)/,meantools.o meantools_exp.o meantools_deriv.o meantools_eval.o)
KONDO_PP_OBJS = $(addprefix $(OBJDIR)/,kondo_preprocess.o kondo.o)


# flags which depend on whether to link statically or dynamically
# lib flag for libkondo
LIBKONDO_FLAG=-lkondo
# additional library required for static linking
XTRA_LIBS=

ifeq ($(STATIC),1)
  # compile libkondo.a
  PREREQ=static
  # libkondo is linked against libm
  XTRA_LIBS=-lm
  # link binaries using the static library
  LIBKONDO_FLAG=-l:libkondo.a
  # install static lib
  INSTALLLIB=install-static
else ifeq ($(STATIC),2)
  # compile libkondo.a
  PREREQ=static
  # libkondo is linked against libm
  XTRA_LIBS=-lm
  # link binaries statically
  override LDFLAGS += -static
  INSTALLLIB=install-static
else
  # compile libkondo.so.$(VERSION)
  PREREQ=shared
  # required flag for subsequent dynamic linking
  override CFLAGS += -fPIC
  INSTALLLIB=install-shared
endif


all:	init $(PREREQ)

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

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

libkondo.a: $(LIBKONDO_OBJS)
	$(AR) -rc $(BUILDDIR)/lib/$@ $^

libkondo.so.$(VERSION): $(LIBKONDO_OBJS)
	$(LD) -shared -lm $(LDFLAGS) -o $(BUILDDIR)/lib/$@ $^
	ln -fs ./libkondo.so.$(VERSION) $(BUILDDIR)/lib/libkondo.so

meankondo: $(MEANKONDO_OBJS)
	$(LD) -L$(BUILDDIR)/lib $(LDFLAGS) -o $(BUILDDIR)/bin/$@ $^ $(LIBKONDO_FLAG) -lpthread $(XTRA_LIBS)

numkondo: $(NUMKONDO_OBJS)
	$(LD) -L$(BUILDDIR)/lib $(LDFLAGS) -o $(BUILDDIR)/bin/$@ $^ $(LIBKONDO_FLAG) -lm $(XTRA_LIBS)

meantools: $(MEANTOOLS_OBJS)
	$(LD) -L$(BUILDDIR)/lib $(LDFLAGS) -o $(BUILDDIR)/bin/$@ $^ $(LIBKONDO_FLAG) $(XTRA_LIBS)

meantools-convert:
	cp scripts/meantools-convert $(BUILDDIR)/bin/

kondo_preprocess: $(KONDO_PP_OBJS)
	$(LD) -L$(BUILDDIR)/lib $(LDFLAGS) -o $(BUILDDIR)/bin/$@ $^ $(LIBKONDO_FLAG) $(XTRA_LIBS)

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

install: $(INSTALLLIB) all
	mkdir -p $(BINDIR) $(MANDIR) $(SCRIPTDIR) $(DOCDIR)
	install -Dm755 $(addprefix $(BUILDDIR)/bin/,$(PROJECT_BINS)) $(BINDIR)/
	install -Dm644 $(addprefix man/,$(PROJECT_MANS)) $(MANDIR)/
	gzip $(addprefix $(MANDIR)/,$(PROJECT_MANS))
	install -Dm644 $(addprefix scripts/,$(PROJECT_SCRIPTS)) $(SCRIPTDIR)/
	install -Dm644 $(addprefix doc/,$(PROJECT_DOCS)) $(DOCDIR)/

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

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