forked from fmidev/smartmet-library-newbase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
194 lines (144 loc) · 3.91 KB
/
Makefile
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
SUBNAME = newbase
LIB = smartmet-$(SUBNAME)
SPEC = smartmet-library-$(SUBNAME)
INCDIR = smartmet/$(SUBNAME)
# Installation directories
processor := $(shell uname -p)
ifeq ($(origin PREFIX), undefined)
PREFIX = /usr
else
PREFIX = $(PREFIX)
endif
ifeq ($(processor), x86_64)
libdir = $(PREFIX)/lib64
else
libdir = $(PREFIX)/lib
endif
bindir = $(PREFIX)/bin
includedir = $(PREFIX)/include
datadir = $(PREFIX)/share
objdir = obj
# Compiler options
DEFINES = -DUNIX -D_REENTRANT
# Say 'yes' to disable Gdal
DISABLED_GDAL=
ifeq ($(DISABLED_GDAL),yes)
DEFINES += -DDISABLED_GDAL
endif
ifeq ($(CXX), clang++)
FLAGS = \
-std=c++11 -fPIC -MD \
-Weverything \
-Wno-c++98-compat \
-Wno-float-equal \
-Wno-padded \
-Wno-missing-prototypes
INCLUDES = \
-isystem $(includedir) \
-isystem $(includedir)/smartmet
else
FLAGS = -std=c++11 -fPIC -MD -Wall -W -Wno-unused-parameter -fdiagnostics-color=always
FLAGS_DEBUG = \
-Wcast-align \
-Winline \
-Wno-multichar \
-Wno-pmf-conversions \
-Woverloaded-virtual \
-Wpointer-arith \
-Wcast-qual \
-Wredundant-decls \
-Wwrite-strings \
-Wsign-promo \
-Wno-inline
FLAGS_RELEASE = -Wuninitialized
INCLUDES = \
-I$(includedir) \
-I$(includedir)/smartmet
endif
# Compile options in detault, debug and profile modes
CFLAGS = $(DEFINES) $(FLAGS) $(FLAGS_RELEASE) -DNDEBUG -O2 -g
CFLAGS_DEBUG = $(DEFINES) $(FLAGS) $(FLAGS_DEBUG) -Werror -Og -g
CFLAGS_PROFILE = $(DEFINES) $(FLAGS) $(FLAGS_PROFILE) -DNDEBUG -O2 -g -pg
CFLAGS0 = $(DEFINES) $(FLAGS) $(FLAGS_RELEASE) -DNDEBUG -O0 -g
LIBS = -L$(libdir) \
-lfmt \
-lboost_date_time \
-lboost_filesystem \
-lboost_iostreams \
-lboost_regex \
-lboost_thread
ifneq ($(DISABLED_GDAL),yes)
LIBS += -lgdal
endif
# What to install
LIBFILE = libsmartmet-$(SUBNAME).so
ALIBFILE = libsmartmet-$(SUBNAME).a
# How to install
INSTALL_PROG = install -p -m 775
INSTALL_DATA = install -p -m 664
ARFLAGS = -r
# Compile option overrides
ifneq (,$(findstring debug,$(MAKECMDGOALS)))
CFLAGS = $(CFLAGS_DEBUG)
CFLAGS0 = $(CFLAGS_DEBUG)
endif
ifneq (,$(findstring profile,$(MAKECMDGOALS)))
CFLAGS = $(CFLAGS_PROFILE)
CFLAGS0 = $(CFLAGS_PROFILE)
endif
# Compilation directories
vpath %.cpp $(SUBNAME)
vpath %.h $(SUBNAME)
# The files to be compiled
SRCS = $(wildcard $(SUBNAME)/*.cpp)
HDRS = $(wildcard $(SUBNAME)/*.h)
OBJS = $(patsubst %.cpp, obj/%.o, $(notdir $(SRCS)))
INCLUDES := -Iinclude $(INCLUDES)
.PHONY: test rpm
# The rules
all: objdir $(LIBFILE) $(ALIBFILE)
debug: all
release: all
profile: all
$(LIBFILE): $(OBJS)
$(CXX) $(CFLAGS) -shared -rdynamic -o $(LIBFILE) $(OBJS) $(LIBS)
$(ALIBFILE): $(OBJS)
$(AR) $(ARFLAGS) $(ALIBFILE) $(OBJS)
clean:
rm -f $(LIBFILE) $(ALIBFILE) *~ $(SUBNAME)/*~
rm -rf $(objdir)
rm -f test/*Test
format:
clang-format -i -style=file $(SUBNAME)/*.h $(SUBNAME)/*.cpp test/*.cpp
install:
@mkdir -p $(includedir)/$(INCDIR)
@list='$(HDRS)'; \
for hdr in $$list; do \
HDR=$$(basename $$hdr); \
echo $(INSTALL_DATA) $$hdr $(includedir)/$(INCDIR)/$$HDR; \
$(INSTALL_DATA) $$hdr $(includedir)/$(INCDIR)/$$HDR; \
done
@mkdir -p $(libdir)
echo $(INSTALL_PROG) $(LIBFILE) $(libdir)/$(LIBFILE)
$(INSTALL_PROG) $(LIBFILE) $(libdir)/$(LIBFILE)
echo $(INSTALL_DATA) $(ALIBFILE) $(libdir)/$(ALIBFILE)
$(INSTALL_DATA) $(ALIBFILE) $(libdir)/$(ALIBFILE)
test:
+cd test && make test
objdir:
@mkdir -p $(objdir)
rpm: clean $(SPEC).spec
rm -f $(SPEC).tar.gz # Clean a possible leftover from previous attempt
tar -czvf $(SPEC).tar.gz --transform "s,^,$(SPEC)/," *
rpmbuild -ta $(SPEC).tar.gz
rm -f $(SPEC).tar.gz
.SUFFIXES: $(SUFFIXES) .cpp
modernize:
for F in newbase/*.cpp; do echo $$F; clang-tidy $$F -fix -checks=-*,modernize-* -- $(CFLAGS) $(DEFINES) $(INCLUDES); done
obj/%.o: %.cpp
$(CXX) $(CFLAGS) $(INCLUDES) -c -o $@ $<
obj/NFmiEnumConverter.o: NFmiEnumConverter.cpp
$(CXX) $(CFLAGS0) $(INCLUDES) -c -o $@ $<
ifneq ($(wildcard obj/*.d),)
-include $(wildcard obj/*.d)
endif