-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
428 lines (326 loc) · 12.8 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
# ------------------------------------------------------------------------------
# Usage:
# make [all] -- make lib test
# make lib -- make lib/libplasma.{a,so} lib/libcoreblas.{a,so}
# make lua -- make tools/lua-5.3.4/src/liblua.a
# make test -- make test/test
# make fortran_examples -- make executables in fortran_examples/
# make docs -- make docs/html
# make generate -- generate precisions
# make clean -- remove objects, libraries, and executables
# make cleangen -- remove generated precision files
# make distclean -- remove above, Makefile.*.gen, and anything else that can be generated
#
# Options:
# quiet=1 -- abbreviate long compilation commands
# static=0 -- build only shared libraries (no static)
# static=1 -- build only static libraries (no shared)
# By default, builds both static and shared libraries.
# fortran=0 -- do not build Fortran interface
# fortran=1 -- build Fortran interface and examples
# ------------------------------------------------------------------------------
# Define default rule first, before including Makefiles
all: lib test
# ------------------------------------------------------------------------------
# Tools and flags
# Variables defined in make.inc, or use make's defaults:
# CC, CFLAGS, INC -- C compiler and flags
# FC, FCFLAGS -- Fortran 2008 compiler and flags
# LDFLAGS, LIBS -- Linker options, library paths, and libraries
# AR, RANLIB -- Archiver, ranlib updates library TOC
# prefix -- where to install PLASMA
# lua_platform -- Lua configuration
include make.inc
# dependencies here interfere with manually edited make.inc
make.inc: #make.inc.in configure.py $(wildcard config/*.py)
python configure.py
# GNU make doesn't have defaults for these
RANLIB ?= ranlib
prefix ?= /usr/local/plasma
# one of: aix bsd c89 freebsd generic linux macosx mingw posix solaris
# usually generic is fine
lua_platform ?= macosx
ifeq ($(FCFLAGS),)
ifneq ($(FFLAGS),)
$(warning Warning: FFLAGS renamed FCFLAGS, per autoconf. Update make.inc.)
endif
endif
# ------------------------------------------------------------------------------
# Internal tools and flags
codegen := ./tools/codegen.py
lua_version := lua-5.3.4
lua_dir := tools/$(lua_version)/src
lua_lib := lib/liblua.a
PLASMA_INC := -Iinclude -I$(lua_dir)
PLASMA_LIBS := -Llib -lplasma -lcoreblas -llua
.DELETE_ON_ERROR:
.SUFFIXES:
ifeq ($(quiet),1)
quiet_CC = @echo "$(CC) ... $@";
quiet_FC = @echo "$(FC) ... $@";
quiet_AR = @echo "$(AR) ... $@";
endif
# ------------------------------------------------------------------------------
# Define sources, objects, libraries, executables.
# These makefiles define lists of source and header files in
# $(plasma_all), $(coreblas_all), and $(test_all).
makefiles_gen := \
Makefile.plasma.gen \
Makefile.coreblas.gen \
Makefile.test.gen
ifeq ($(fortran), 1)
makefiles_gen += Makefile.fortran_examples.gen
endif
-include $(makefiles_gen)
plasma_hdr := $(filter %.h, $(plasma_all))
coreblas_hdr := $(filter %.h, $(coreblas_all))
test_hdr := $(filter %.h, $(test_all))
headers := $(plasma_hdr) $(coreblas_hdr) $(test_hdr)
plasma_obj := $(addsuffix .o, $(basename $(filter-out %.h, $(plasma_all))))
coreblas_obj := $(addsuffix .o, $(basename $(filter-out %.h, $(coreblas_all))))
test_obj := $(addsuffix .o, $(basename $(filter-out %.h, $(test_all))))
test_exe := test/test
ifeq ($(fortran), 1)
fortran_interface_src := include/plasma_mod.f90
fortran_interface_obj := include/plasma_mod.o
fortran_interface_mod := include/plasma.mod
plasma_obj += $(fortran_interface_obj)
fortran_examples_exe := $(basename $(fortran_examples_all))
all: fortran_examples
endif
# ------------------------------------------------------------------------------
# Build dependencies (Lua)
lua: $(lua_lib)
$(lua_dir): tools/$(lua_version).tar.gz
cd tools && tar -zxvf $(lua_version).tar.gz
# clear TARGET_ARCH, which Intel's compilervars.sh script (erroneously?) sets to intel64
$(lua_lib): | $(lua_dir)
cd $(lua_dir) && make $(lua_platform) MYCFLAGS="-fPIC" CC=$(CC) TARGET_ARCH=
cp $(lua_dir)/liblua.a lib
# plasma needs lua include files
$(plasma_obj): | $(lua_dir)
$(coreblas_obj): | $(lua_dir)
libfiles = $(lua_lib)
# ------------------------------------------------------------------------------
# Create dependencies to generate Fortran interface.
fortran_gen := ./tools/fortran_gen.py
include/plasma_mod.f90: $(plasma_hdr)
$(fortran_gen) --prefix include/ $^
$(fortran_interface_obj): $(fortran_interface_src)
$(quiet_FC) $(FC) $(FCFLAGS) $(PLASMA_INC) $(INC) -c -o $@ $<
mv -f plasma.mod include/
# ------------------------------------------------------------------------------
# Build static libraries
ifneq ($(static),0)
libfiles += \
lib/libplasma.a \
lib/libcoreblas.a \
# In case changing Makefile.gen changes $(obj), also depend on it,
# which recreates the library if a file is removed.
lib/libplasma.a: $(plasma_obj) Makefile.plasma.gen
-rm -f $@
$(quiet_AR) $(AR) cr $@ $(plasma_obj)
$(RANLIB) $@
lib/libcoreblas.a: $(coreblas_obj) Makefile.coreblas.gen
-rm -f $@
$(quiet_AR) $(AR) cr $@ $(coreblas_obj)
$(RANLIB) $@
endif
# ------------------------------------------------------------------------------
# Build shared libraries
# if all FLAGS have -fPIC, allow compiling shared libraries
have_fpic = $(and $(findstring -fPIC, $(CFLAGS)), \
$(findstring -fPIC, $(LDFLAGS)))
ifneq ($(static),1)
ifneq ($(have_fpic),)
libfiles += \
lib/libplasma.so \
lib/libcoreblas.so
top = $(shell pwd)
rpath = -Wl,-rpath,$(top)/lib
# MacOS (darwin) needs shared library's path set
ifneq ($(findstring darwin, $(OSTYPE)),)
install_name = -install_name @rpath/$(notdir $@)
else
install_name =
endif
lib/libplasma.so: $(plasma_obj) Makefile.plasma.gen lib/libcoreblas.so $(lua_lib)
$(quiet_CC) $(CC) -shared $(LDFLAGS) -o $@ $(plasma_obj) \
-Llib -lcoreblas -llua $(LIBS) \
$(install_name)
lib/libcoreblas.so: $(coreblas_obj) Makefile.coreblas.gen $(lua_lib)
$(quiet_CC) $(CC) -shared $(LDFLAGS) -o $@ $(coreblas_obj) \
-Llib -llua $(LIBS) \
$(install_name)
endif
endif
# creare the lib
libdir:
mkdir -p lib
$(libfiles): libdir
.PHONY: lib
lib: $(libfiles)
# ------------------------------------------------------------------------------
# Build tester
.PHONY: test
test: $(test_exe)
$(test_exe): $(test_obj) $(libfiles) Makefile.test.gen
$(quiet_CC) $(CC) $(LDFLAGS) -o $@ $(test_obj) \
$(PLASMA_LIBS) \
$(LIBS) \
$(rpath)
# ------------------------------------------------------------------------------
# Build Fortran examples
.PHONY: fortran_examples
fortran_examples: $(fortran_examples_exe)
# implicit rule for building Fortran examples
%: %.f90 $(libfiles) Makefile.fortran_examples.gen
$(quiet_FC) $(FC) $(FCFLAGS) $(LDFLAGS) $(PLASMA_INC) -o $@ $< \
$(PLASMA_LIBS) \
$(LIBS) \
$(rpath)
run_fortran_tests: fortran_examples
$(foreach exe,$(fortran_examples_exe), ./$(exe);)
# ------------------------------------------------------------------------------
# Build objects
# Headers must exist before compiling, but use order-only prerequisite
# (after "|") so as not to force recompiling everything if a header changes.
# (Should use compiler's -MMD flag to create header dependencies.)
%.o: %.c | $(headers)
$(quiet_CC) $(CC) $(CFLAGS) $(PLASMA_INC) $(INC) -c -o $@ $<
%.i: %.c | $(headers)
# $(quiet_CC) $(CC) $(CFLAGS) $(PLASMA_INC) $(INC) -E -o $@ $<
$(quiet_CC) $(CC) $(CFLAGS) $(PLASMA_INC) $(INC) -o $@ $<
# ------------------------------------------------------------------------------
# Build documentation
.PHONY: docs
docs: generate
doxygen docs/doxygen/doxyfile.conf
# ------------------------------------------------------------------------------
# Install
# TODO: need to install Lua headers?
.PHONY: install_dirs install
install_dirs:
mkdir -p $(prefix)
mkdir -p $(prefix)/include
mkdir -p $(prefix)/lib
mkdir -p $(prefix)/lib/pkgconfig
install: lib install_dirs
cp include/*.h $(prefix)/include
cp include/*.mod $(prefix)/include
cp $(libfiles) $(prefix)/lib
# pkgconfig
cat lib/pkgconfig/plasma.pc.in | \
sed -e s:@INSTALL_PREFIX@:"$(prefix)": | \
sed -e s:@CFLAGS@:"$(INC)": | \
sed -e s:@LIBS@:"$(LIBS)": | \
sed -e s:@REQUIRES@:: \
> $(prefix)/lib/pkgconfig/plasma.pc
uninstall:
rm -f $(prefix)/include/core_blas*.h
rm -f $(prefix)/include/core_lapack*.h
rm -f $(prefix)/include/plasma*.h
rm -f $(prefix)/include/plasma.mod
rm -f $(prefix)/lib/libcoreblas*
rm -f $(prefix)/lib/libplasma*
rm -f $(prefix)/lib/liblua*
rm -f $(prefix)/lib/pkgconfig/plasma.pc
# ------------------------------------------------------------------------------
# Maintenance rules
# makefiles_gen define generate and cleangen.
.PHONY: clean distclean
clean:
-rm -f $(plasma_obj) $(coreblas_obj) $(test_obj) $(test_exe) $(libfiles)
-rmdir lib
ifeq ($(fortran), 1)
-rm -f $(fortran_interface_src) $(fortran_interface_obj) $(fortran_interface_mod)
-rm -f $(fortran_examples_exe)
endif
-cd $(lua_dir) && make clean
# cleangen removes generated files if the template still exists;
# grep for any stale generated files without a template.
distclean: clean cleangen
grep -s -l @generated $(plasma_src) $(coreblas_src) $(test_src) $(fortran_examples_src) | xargs rm -f
-rm -f compute/*.o control/*.o core_blas/*.o test/*.o
-rm -f $(makefiles_gen)
-rm -rf docs/html
-rm -rf tools/$(lua_version)
# ------------------------------------------------------------------------------
# Create dependencies to do precision generation.
plasma_src := $(wildcard compute/*.c include/plasma*.h)
coreblas_src := $(wildcard core_blas/*.c control/*.c include/core*.h)
test_src := $(wildcard test/*.c test/*.h)
fortran_examples_src := $(wildcard fortran_examples/*.f90)
Makefile.plasma.gen: $(codegen)
$(codegen) --make --prefix plasma $(plasma_src) > $@
Makefile.coreblas.gen: $(codegen)
$(codegen) --make --prefix coreblas $(coreblas_src) > $@
Makefile.test.gen: $(codegen)
$(codegen) --make --prefix test $(test_src) > $@
Makefile.fortran_examples.gen: $(codegen)
$(codegen) --make --prefix fortran_examples $(fortran_examples_src) > $@
# --------------------
# If the list of src files changes, then force remaking Makefile.gen
# To reduce unnecesary remaking, don't remake if either:
# 1) src == old:
# src has same files now as when Makefile.gen was generated, or
# 2) src - generated == templates:
# src has all the templates from Makefile.gen, and no new non-generated files.
ifneq ($(plasma_src),$(plasma_old))
ifneq ($(filter-out $(plasma_generated),$(plasma_src)),$(plasma_templates))
Makefile.plasma.gen: force_gen
endif
endif
ifneq ($(coreblas_src),$(coreblas_old))
ifneq ($(filter-out $(coreblas_generated),$(coreblas_src)),$(coreblas_templates))
Makefile.coreblas.gen: force_gen
endif
endif
ifneq ($(test_src),$(test_old))
ifneq ($(filter-out $(test_generated),$(test_src)),$(test_templates))
Makefile.test.gen: force_gen
endif
endif
ifneq ($(fortran_examples_src),$(fortran_examples_old))
ifneq ($(filter-out $(fortran_examples_generated),$(fortran_examples_src)),$(fortran_examples_templates))
Makefile.fortran_examples.gen: force_gen
endif
endif
# --------------------
force_gen: ;
# ------------------------------------------------------------------------------
# Debugging
echo:
@echo "CC $(CC)"
@echo "CFLAGS $(CFLAGS)"
@echo "LDFLAGS $(LDFLAGS)"
@echo
@echo "test_exe <$(test_exe)>"
@echo "libfiles <$(libfiles)>"
@echo
@echo "plasma_src <$(plasma_src)>"
@echo "plasma_old <$(plasma_old)>"
@echo "plasma_templates <$(plasma_templates)>"
@echo "plasma_filtered <$(filter-out $(plasma_generated),$(plasma))>"
@echo "plasma_hdr <$(plasma_hdr)>"
@echo "plasma_obj <$(plasma_obj)>"
@echo
@echo "coreblas_src <$(coreblas_src)>"
@echo "coreblas_old <$(coreblas_old)>"
@echo "coreblas_templates <$(coreblas_templates)>"
@echo "coreblas_filtered <$(filter-out $(coreblas_generated),$(coreblas))>"
@echo "coreblas_hdr <$(coreblas_hdr)>"
@echo
@echo "test_src <$(test_src)>"
@echo "test_old <$(test_old)>"
@echo "test_templates <$(test_templates)>"
@echo "test_filtered <$(filter-out $(test_generated),$(test))>"
@echo "test_hdr <$(test_hdr)>"
@echo
@echo "fortran_examples_src <$(fortran_examples_src)>"
@echo "fortran_examples_exe <$(fortran_examples_exe)>"
@echo "fortran_examples_old <$(fortran_examples_old)>"
@echo "fortran_examples_templates <$(fortran_examples_templates)>"
@echo "fortran_examples_filtered <$(filter-out $(fortran_examples_generated),$(fortran_examples))>"
@echo
@echo "headers <$(headers)>"