Ian Jauslin
summaryrefslogtreecommitdiff
blob: 9fe6bd8f2a1153fc0702bd5e77c7c59752aaaf68 (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
## 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 link dynamically
#   if static=0 then link dynamically
#   if static=2 then link statically
#   if static=1 then link libinum statically but other libraries dynamically
STATIC=1

# whether to compile libinum
LIBINUM_COMPILE=1

VERSION=1.0
LIBINUM_VERSION=1.0.1

# products of the compilation
PROJECT_BINS= hhtop

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

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

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

# directories
INCLUDE = 
LIB = 

# flags
# do not override CLI flags (so they can be pushed to libinum)
LDFLAGS_HH =$(LDFLAGS) $(LIB)
CFLAGS_HH =$(CFLAGS) $(INCLUDE) $(DB) $(OPT) $(WARNINGS)

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

# objects
OBJS = $(addprefix $(OBJDIR)/, hh_integral.o hh_root.o hhtop.o parser.o ss_integral.o zz_integral.o hh_integral_double.o hh_root_double.o ss_integral_double.o zz_integral_double.o double_util.o)

# flags which depend on whether to link statically or dynamically
# lib flag for libinum
LIBINUM_FLAG=
# additional library required for static linking
XTRA_LIBS=

ifeq ($(STATIC),0)
  XTRA_LIBS=-lm -lmpfr -lgmp -lpthread
  LIBINUM_FLAG=-linum
else ($(STATIC),1)
  # libinum is linked against libm, libmpfr, libgmp and libpthread
  XTRA_LIBS=-lm -lmpfr -lgmp -lpthread
  # link binaries using the static library
  LIBINUM_FLAG=-l:libinum.a
else ifeq ($(STATIC),2)
  # libinum is linked against libm, libmpfr, libgmp and libpthread
  XTRA_LIBS=-lm -lmpfr -lgmp -lpthread
  LIBINUM_FLAG=-linum
  # link binaries statically
  LDFLAGS_HH += -static
endif


LIBINUM_COMPILE_COMMAND=
ifeq ($(LIBINUM_COMPILE),1)
  LIBINUM_COMPILE_COMMAND=libinum
  LDFLAGS_HH += -L./libinum-$(LIBINUM_VERSION)/build
  CFLAGS_HH += -I./libinum-$(LIBINUM_VERSION)/include
endif



all:	$(LIBINUM_COMPILE_COMMAND) init hhtop

# compile libinum
libinum:
	tar xzf ./libinum-$(LIBINUM_VERSION).tar.gz
	make STATIC=0 CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" CC="$(CC)" LD="$(LD)" AR="$(AR)" OPT="$(OPT)" DB="$(DB)" INCLUDE="$(INCLUDE)" LIB="$(LIB)" -C ./libinum-$(LIBINUM_VERSION)

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


hhtop: $(OBJS)
	$(LD) $(LDFLAGS_HH) -o $(BUILDDIR)/$@ $^ $(LIBINUM_FLAG) $(XTRA_LIBS)

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

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