-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.config
840 lines (709 loc) · 24.9 KB
/
Makefile.config
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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
# -*- Makefile -*-
# ======================================================================
# $(foreach v, $(.VARIABLES), $(info $(v) = $($(v))))
# ifeq ($(filter 4.%,$(MAKE_VERSION)),)
# ifeq ($(R_PACKAGE_DIR),)
# $(error use GNU make 4.x+)
# endif
# endif
ifeq ($(filter 4.%,$(MAKE_VERSION)),)
$(error use GNU make 4.x+ instead of $(MAKE_VERSION))
endif
ifeq ($(ACMACSD_ROOT),)
$(error undefined env var ACMACSD_ROOT)
endif
ifneq (,$(findstring darwin,$(MAKE_HOST)))
PLATFORM = darwin
else ifeq (x86_64-pc-linux-gnu,$(MAKE_HOST))
PLATFORM = linux
else ifeq (,$(MAKE_HOST))
UNAME = $(shell uname)
ifeq ($(UNAME),Darwin)
PLATFORM = darwin
else ifeq ($(UNAME),Linux)
PLATFORM = linux
else
$(error Unsupported platform $(UNAME))
endif
else
$(error Unsupported platform $(MAKE_HOST))
endif
# ----------------------------------------------------------------------
MAKEFLAGS = -w
ifeq ($(MAKECMDGOALS),clean)
VERBOSE = 1
endif
ifndef VERBOSE
.SILENT:
endif
# ----------------------------------------------------------------------
capable_20 = $(shell if echo "" | $(1) -std=c++20 -x c++ -c -o /dev/null - >/dev/null 2>&1; then echo 1; fi)
# capable_2a = $(shell if echo "" | $(1) -std=c++2a -x c++ -c -o /dev/null - >/dev/null 2>&1; then echo 1; fi)
# capable_17 = $(shell if echo "" | $(1) -std=c++17 -x c++ -c -o /dev/null - >/dev/null 2>&1; then echo 1; fi)
# ----------------------------------------------------------------------
# clang
# ----------------------------------------------------------------------
ifeq ($(PLATFORM),darwin)
BREW_PREFIX = $(shell brew --prefix)
CLANG_ROOT = $(BREW_PREFIX)/opt/llvm
CLANG = $(CLANG_ROOT)/bin/clang++
CLANG_LIB_DIR = $(CLANG_ROOT)/lib
# $(info WARNING: $(MAKE_HOST) $(findstring darwin2,$(MAKE_HOST)))
# ifneq (,$(findstring darwin2,$(MAKE_HOST)))
# ifeq ($(realpath /Library/Developer/CommandLineTools/SDKs/MacOSX$(call sysctl -a | grep kern.osproductversion: | cut -f 1 -d ' ').sdk/usr/include/math.h),)
# $(error No SDK in /Library/Developer/CommandLineTools/SDKs/MacOSX$(call sysctl -a | grep kern.osproductversion: | cut -f 1 -d ' ').sdk)
# endif
# else
# ifeq ($(realpath /usr/include/math.h),)
# $(error please open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.*.pkg to install headers in /usr/include)
# endif
# endif
endif
ifeq ($(call capable_20,$(CLANG)),1)
CLANG_VERSION = $(shell $(CLANG) --version | awk '/version/ { print $$NF; }')
ifeq ($(CLANG_VERSION),)
$(error $(CLANG) version detection failed)
endif
CLANG_LIBS += -L$(CLANG_LIB_DIR)
# ifneq ($(filter 8.%,$(CLANG_VERSION)),)
# CLANG_LIBS += -lc++fs
# endif
else
ifeq ($(PLATFORM),darwin)
$(info WARNING: CLANG not capable_20)
endif
endif
ifneq ($(CLANG_VERSION),)
FOUND_COMPILERS += CLANG
else
CLANG =
endif
ifeq ($(PLATFORM),linux)
CLANG = clang++
endif
# ----------------------------------------------------------------------
# gcc
# ----------------------------------------------------------------------
GCC11 = g++-11
ifneq ($(GCC11),)
ifeq ($(call capable_20,$(GCC11)),1)
GCC11_VERSION = $(shell $(GCC11) -v 2>&1 | tail -n 1 | cut -d ' ' -f 3)
endif
ifneq ($(GCC11_VERSION),)
FOUND_COMPILERS += GCC11
else
GCC11 =
endif
endif
GCC10 = g++-10
ifneq ($(GCC10),)
ifeq ($(call capable_20,$(GCC10)),1)
GCC10_VERSION = $(shell $(GCC10) -v 2>&1 | tail -n 1 | cut -d ' ' -f 3)
endif
ifneq ($(GCC10_VERSION),)
FOUND_COMPILERS += GCC10
else
GCC10 =
endif
endif
# GCC9 = g++-9
# ifneq ($(GCC9),)
# ifeq ($(call capable_2a,$(GCC9)),1)
# # GCC9_VERSION = $(shell $(GCC9) --version | head -n 1 | rev | cut -d ' ' -f 1 | rev)
# GCC9_VERSION = $(shell $(GCC9) -v 2>&1 | tail -n 1 | cut -d ' ' -f 3)
# endif
# ifneq ($(GCC9_VERSION),)
# FOUND_COMPILERS += GCC9
# else
# GCC9 =
# endif
# endif
# ----------------------------------------------------------------------
ifeq ($(FOUND_COMPILERS),)
$(error No 2a compilers found)
endif
ifeq ($(PLATFORM),darwin)
ifeq ($(findstring CLANG,$(FOUND_COMPILERS)),CLANG)
DEFAULT_COMPILER = CLANG
else
DEFAULT_COMPILER = $(word 1,$(FOUND_COMPILERS))
endif
endif
ifeq ($(PLATFORM),linux)
ifeq ($(findstring GCC11,$(FOUND_COMPILERS)),GCC11)
DEFAULT_COMPILER = GCC11
else ifeq ($(findstring GCC10,$(FOUND_COMPILERS)),GCC10)
DEFAULT_COMPILER = GCC10
# else ifeq ($(findstring GCC9,$(FOUND_COMPILERS)),GCC9)
# DEFAULT_COMPILER = GCC9
else
DEFAULT_COMPILER = $(word 1,$(FOUND_COMPILERS))
endif
endif
# ----------------------------------------------------------------------
ifeq ($(DEFAULT_COMPILER),)
$(error No compiler found)
endif
ifeq ($(C),)
C = $(DEFAULT_COMPILER)
else ifeq ($(findstring $(C),$(FOUND_COMPILERS)),)
$(error Not supported compiler $(C), use either of $(FOUND_COMPILERS))
endif
ifeq ($(C),CLANG)
override CXX = $(CLANG)
CXX_COMPILER_TYPE = clang
CXX_NAME = clang++ $(CLANG_VERSION)
CXX_LIBS = $(CLANG_LIBS) $(FMT_LIBS)
# -lomp
# -L/usr/local/lib -lomp
WARNINGS = -Wno-weak-vtables -Wall -Wno-switch-default -Wno-unsafe-buffer-usage -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-c++20-compat -Wno-padded -Wno-unsafe-buffer-usage
# -Weverything
# -fsized-deallocation required by pybind11 (https://github.com/pybind/pybind11/issues/1604)
CXX_FEATURES += -fsized-deallocation
ASAN = -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-inline-functions -Wno-source-uses-openmp
# else ifeq ($(C),GCC8)
# override CXX = $(GCC8)
# CXX_COMPILER _TYPE= gcc
# CXX_NAME = g++ $(GCC8_VERSION)
# CXX_LIBS = -lstdc++fs $(FMT_LIBS)
# WARNINGS = -Wall -Wextra
# CXX_FEATURES =
else ifeq ($(C),$(filter $(C), GCC10 GCC11))
override CXX = $($(C))
CXX_COMPILER_TYPE = gcc
CXX_NAME = g++ $($(C)_VERSION)
CXX_LIBS = $(FMT_LIBS)
WARNINGS = -Wall -Wextra
CXX_FEATURES =
ASAN = -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-inline-functions
else
$(error Unsupported C++ compiler: $(C))
endif
ifeq ($(DEBUG),1)
ifeq ($(NO_ASAN),1)
OPT = -O1
CXX_NAME += DEBUG-NO-ASAN
else
OPT = -O1 $(ASAN)
CXX_NAME += DEBUG-ASAN
endif
else
OPT = -O3 $(MAVX) $(MTUNE) -fopenmp
CXX_NAME += OPT
endif
# https://clang.llvm.org/docs/SourceBasedCodeCoverage.html
ifeq ($(PROFILE),1)
OPT += -fprofile-instr-generate -fcoverage-mapping
CXX_NAME += PROFILE
endif
ifeq ($(TIMER),1)
ifeq ($(PLATFORM),darwin)
TIME_CMD = $(shell if gtime true 2>/dev/null; then echo gtime; else echo time; fi)
else
TIME_CMD = time
endif
else
TIME_CMD =
endif
CCLS=1
ifeq ($(CCLS),1)
ifeq ($(PLATFORM),darwin)
# https://sarcasm.github.io/notes/dev/compilation-database.html
COMPILATION_DATABASE = -MJ [email protected]
endif
endif
ifeq ($(PLATFORM),darwin)
MACOS_10_14_OR_LATER := $(shell test `uname -r | cut -f 1 -d .` -ge 18 && echo true)
ifneq ($(MACOS_10_14_OR_LATER),true)
$(error macOS older than 10.14 (Mojave) are not supported)
endif
UNAME_MACHINE := $(shell uname -m)
ifeq ($(UNAME_MACHINE),x86_64)
MTUNE = -mtune=x86-64
MAVX = -mavx
MATH_SSE = -mfpmath=sse
else ifeq ($(UNAME_MACHINE),arm64)
MTUNE =
MAVX =
MATH_SSE =
else
$(error macOS: unsupported uname -m: $(UNAME_MACHINE))
endif
# MACOS_10_14 := $(shell test `uname -r | cut -f 1 -d .` -eq 18 && echo true)
# MACOS_10_15 := $(shell test `uname -r | cut -f 1 -d .` -eq 19 && echo true)
# MACOS_11 := $(shell test `uname -r | cut -f 1 -d .` -eq 20 && echo true)
# ifeq ($(MACOS_10_15),true)
# MAVX = -mavx
# # MACOSX_VERSION_MIN = -mmacosx-version-min=10.15
# else ifeq ($(MACOS_10_14),true)
# MAVX = -mavx
# # have to use 10.5, otherwise many errors, e.g. filessytem::path is unavailable: introduced in macOS 10.15
# MACOSX_VERSION_MIN = -mmacosx-version-min=10.15
# else
# # support old machines without avx
# MAVX = -msse4 -mfpmath=sse
# # https://stackoverflow.com/questions/52310835/xcode-10-call-to-unavailable-function-stdvisit
# CXX_FEATURES += -D_LIBCPP_DISABLE_AVAILABILITY -faligned-allocation
# CXX_NAME += MACOS_BEFORE_10_14
# MACOSX_VERSION_MIN = -mmacosx-version-min=10.11
# endif
else ifeq ($(PLATFORM),linux)
# David B has machine with i7 920 which does not support AVX, so -mavx is replaced with -msse4
MAVX = -msse4 -mfpmath=sse
MTUNE = -mtune=intel
endif
$(shell pkg-config zlib)
ifneq ($(.SHELLSTATUS),0)
$(error zlib is not installed)
endif
$(shell pkg-config liblzma)
ifneq ($(.SHELLSTATUS),0)
ifeq ($(PLATFORM),darwin)
$(error install liblzma: brew install xz)
else
$(error install liblzma: sudo apt install liblzma-dev)
endif
endif
$(shell pkg-config libbrotlidec)
ifneq ($(.SHELLSTATUS),0)
ifeq ($(PLATFORM),darwin)
$(error install brotli: brew install brotli)
else
$(error install brotli: sudo apt install libbrotli-dev)
endif
endif
PKG_INCLUDES = $(shell pkg-config --cflags liblzma) $(shell pkg-config --cflags zlib) $(shell pkg-config --cflags libbrotlienc)
INCLUDES = -I$(AD_INCLUDE) -Icc -I$(BUILD)/include $(PKG_INCLUDES) $(PYTHON_INCLUDES) $(BOOST_INCLUDES) $(CAIRO_INCLUDES) $(OPENSSL_INCLUDES) $(MONGO_INCLUDES) $(LIBCURL_INCLUDES) $(OPENXLSX_INCLUDES) $(GUILE_INCLUDES) $(INCLUDE_USR_LOCAL)
CXXFLAGS = -g -MMD $(OPT) -fPIC -std=c++2a $(WARNINGS) $(INCLUDES) $(CXX_FEATURES) $(MACOSX_VERSION_MIN) $(COMPILATION_DATABASE)
# CXXFLAGS = -g -MMD $(OPT) -fPIC -std=c++17 $(WARNINGS) $(INCLUDES) $(CXX_FEATURES) $(MACOSX_VERSION_MIN)
LDFLAGS = $(OPT) $(MACOSX_VERSION_MIN)
XZ_LIBS = $$(pkg-config --libs liblzma)
GZ_LIBS = $$(pkg-config --libs zlib)
BZ2_LIBS = -lbz2
BROTLI_LIBS = $$(pkg-config --libs libbrotlidec) $$(pkg-config --libs libbrotlienc)
ifeq ($(PLATFORM),linux)
INCLUDE_USR_LOCAL=-I/usr/local/include
else
INCLUDE_USR_LOCAL=
endif
# ----------------------------------------------------------------------
AD_PACKAGE_NAME = $(notdir $(CURDIR))
AD_SOURCES_ROOT = $(abspath ../..)
AD_SOURCES = $(AD_SOURCES_ROOT)/sources
AD_INCLUDE = $(AD_SOURCES_ROOT)/include
AD_BUILD = $(AD_SOURCES_ROOT)/build
BUILD = $(AD_BUILD)/$(AD_PACKAGE_NAME)/build
DIST = $(AD_BUILD)/$(AD_PACKAGE_NAME)/dist
AD_ROOT = $(abspath $(ACMACSD_ROOT))
AD_LIB = $(AD_ROOT)/lib
AD_BIN = $(AD_ROOT)/bin
AD_PY = $(AD_ROOT)/py
AD_DATA = $(AD_ROOT)/data
AD_SHARE = $(AD_ROOT)/share
AD_DOC = $(AD_SHARE)/doc
AD_CONF = $(AD_SHARE)/conf
AD_TEMPLATES = $(AD_SHARE)/templates
ifeq ($(PLATFORM),linux)
AD_RPATH = -Wl,-rpath,$(AD_LIB)
endif
# ======================================================================
# install darwin
# ======================================================================
ifeq ($(PLATFORM),darwin)
# $(1) - source lib
define install_lib
ln -sf $(1) $(AD_LIB)
/usr/bin/install_name_tool -id $(AD_LIB)/$(notdir $(1)) $(AD_LIB)/$(notdir $(1))
endef
# $(1) - package name
define install_headers
if [ ! -d $(AD_INCLUDE)/$(1) ]; then mkdir $(AD_INCLUDE)/$(1); fi
$(call symbolic_link_wildcard,$(abspath cc)/*.hh,$(AD_INCLUDE)/$(1))
$(call symbolic_link_wildcard,$(abspath cc)/*.hpp,$(AD_INCLUDE)/$(1))
$(call symbolic_link_wildcard,$(abspath cc)/*.h,$(AD_INCLUDE)/$(1))
endef
# shared_lib_name: $(1) - name, $(2) - major, $(3) - minor
# shared_lib_name = $(1).$(2).$(3).dylib
shared_lib_name = $(1).$(2).dylib
shared_lib_suffix = .dylib
# $(1) - name, $(2) - major, $(3) - minor
make_shared_lib = $(CXX) -dynamiclib -current_version $(2).$(3) -compatibility_version $(2).0
# $(1) - package name
define install_py
if [ -d $(abspath py)/$(subst -,_,$(1)) ]; then $(call symbolic_link,$(abspath py)/$(subst -,_,$(1)),$(AD_PY)/$(subst -,_,$(1))); fi
endef
define install_py_all
for src in $(abspath py)/*; do $(call symbolic_link,$$src,$(AD_PY)/$$(basename $$src)); done
endef
define install_bin
$(call symbolic_link_wildcard,$(abspath bin)/*,$(AD_BIN))
endef
define install_doc
if [ -d doc ]; then $(call symbolic_link_wildcard,$(abspath doc)/*,$(AD_DOC)); fi
endef
define install_conf
if [ -d conf ]; then $(call symbolic_link_wildcard,$(abspath conf)/*,$(AD_CONF)); fi
endef
# $(1) - package name
define install_templates
if [ -d templates ]; then $(call symbolic_link,$(abspath templates),$(AD_TEMPLATES)/$(1)); fi
endef
# $(1) - filename, $(2) - target dir
define install_file
$(call symbolic_link,$(abspath $(1)),$(2))
endef
# $(1) - filename, $(2) - target dir
define install_exec_file
$(call symbolic_link,$(abspath $(1)),$(2))
endef
# $(1) - filename, $(2) - target filename
define install_program
$(call symbolic_link,$(abspath $(1)),$(2))
endef
# $(1) - source wildcard, $(2) - target_dir
define install_wildcard
$(call make_dir,$(2))
$(call symbolic_link_wildcard,$(1),$(2))
endef
# ======================================================================
# install linux
# ======================================================================
else ifeq ($(PLATFORM),linux)
# $(1) - source lib
define install_lib
/usr/bin/install --verbose --compare -D -t $(AD_LIB) $(1)
ln -sf --verbose $(notdir $(1)) $(AD_LIB)/$(basename $(notdir $(1)))
endef
# $(1) - package name
define install_headers
for f in $(abspath cc)/*.hh $(abspath cc)/*.hpp $(abspath cc)/*.h; do if [ -f "$$f" ]; then /usr/bin/install --verbose --compare --mode=0644 -D -t $(AD_INCLUDE)/$(1) "$$f"; fi; done
endef
# shared_lib_name: $(1) - name, $(2) - major, $(3) - minor
shared_lib_name = $(1).so.$(2)
shared_lib_suffix = .so
# $(1) - name, $(2) - major, $(3) - minor
make_shared_lib = $(CXX) -shared -Wl,-soname,$(1).so.$(2) -Wl,-rpath,'$$ORIGIN'
# $(1) - package name
define install_py
if [ -d py/$(subst -,_,$(1)) ]; then \
for f in py/$(subst -,_,$(1))/*; do \
if [ -f $$f ]; then \
/usr/bin/install --verbose --compare --mode=0644 -D -t $(AD_PY)/$(subst -,_,$(1)) "$$f"; \
fi; \
done; \
fi
endef
define install_py_all
/usr/bin/rsync -av --exclude obsolete --exclude-from=py/.gitignore py/* $(AD_PY)
endef
define install_py_all_old
for src in py/*; do \
if [ "$(basename $$f)" != "obsolete" ]; then \
for f in $$src/*; do \
if [ -f $$f ]; then \
/usr/bin/install --verbose --compare --mode=0644 -D -t $(AD_PY)/$$(basename $$src) "$$f"; \
fi; \
done; \
fi; \
done
endef
define install_bin
if [ -d bin ]; then /usr/bin/install --verbose --compare -D -t $(AD_BIN) bin/*; fi
endef
define install_conf
if [ -d conf ]; then /usr/bin/install --verbose --compare --mode=0644 -D -t $(AD_CONF) conf/*; fi
endef
define install_doc
if [ -d doc ]; then /usr/bin/install --verbose --compare --mode=0644 -D -t $(AD_DOC) doc/*; fi
endef
# $(1) - package name
define install_templates
if [ -d templates ]; then /usr/bin/install --verbose --compare --mode=0644 -D -t $(AD_TEMPLATES)/$(1) templates/*; fi
endef
# $(1) - filename, $(2) - target dir
define install_file
/usr/bin/install --verbose --compare --mode=0644 -D -t $(2) $(1)
endef
# $(1) - filename, $(2) - target dir
define install_exec_file
/usr/bin/install --verbose --compare -D -t $(2) $(1)
endef
# $(1) - filename, $(2) - target filename
define install_program
/usr/bin/install --verbose --compare --no-target-directory $(1) $(2)
endef
endif
# $(1) - source wildcard, $(2) - target_dir
define install_wildcard
$(call make_dir,$(2))
rsync -a $(1) $(2)
endef
# ----------------------------------------------------------------------
define install_dist
if [ -d dist ]; then \
for f in dist/*; do \
case $$f in \
*.so) $(call install_exec_file,$$f,$(AD_LIB));; \
*.so.* | *.dylib) :;; \
*) $(call install_exec_file,$$f,$(AD_BIN));; \
esac; \
done; \
fi
endef
# $(1) - package name
define install_all
$(call install_headers,$(1))
$(call install_dist)
$(call install_bin)
$(call install_conf)
$(call install_doc)
$(call install_templates,$(1))
endef
# ======================================================================
# $(1) - source wildcard, $(2) - target
define symbolic_link_wildcard
for f in $(1); do \
if [ -f $$f ] || [ -d $$f ]; then \
if [ -d $(2) ]; then \
if [ ! -e $(2)/$$(basename $$f) ]; then ln -sfv $$f $(2); fi; \
else \
if [ ! -e $(2) ]; then ln -sfv $$f $(2); fi; \
fi \
fi \
done
endef
# $(1) - source, $(2) - target
define symbolic_link
if [ -d $(1) ]; then \
if [ -d $(2) ] && [ ! -L $(2) ]; then \
if [ ! -f $(2)/$$(basename $(1)) ]; then ln -sfv $(1) $(2); fi; \
else \
if [ ! -f $(2) ] && [ ! -d $(2) ]; then ln -sfv $(1) $(2); fi; \
fi; \
else \
if [ -d $(2) ]; then \
if [ ! -f $(2)/$$(basename $(1)) ]; then ln -sfv $(1) $(2); fi; \
else \
if [ ! -f $(2) ]; then ln -sfv $(1) $(2); fi; \
fi \
fi
endef
echo_echo = printf "%-16s %s\n"
echo_compile = $(echo_echo) "$(CXX_NAME)" $(1)
echo_shared_lib = $(echo_echo) "SharedLib" $(1)
echo_link_exe = $(echo_echo) "LinkExe" $(1)
# $(1) - target dir, $(2) - git uri, $(3) - branch
define git_clone_or_pull
if [ -d $(1) ]; then \
echo Pulling in $(1); \
cd $(1); git pull -q || exit 1; \
else \
echo Cloning to $(1); \
if [ -n "$(3)" ]; then BRANCH="--branch $(3)"; fi; \
git clone -q $$BRANCH $(2)/$(notdir $(1)).git $(1); \
fi
endef
# $(1) - target dir, $(2) - git uri, $(3) - tag
define git_clone_tag
if [ ! -d $(1) ]; then \
echo Cloning to $(1) branch $(3); \
git clone -q --depth 1 --branch $(3) $(2)/$(notdir $(1)).git $(1); \
fi
endef
# $(1) - dir to make
define make_dir
if [ ! -d $(1) ]; then \
if [ ! -e $(1) ]; then \
echo mkdir $(1); \
mkdir -p $(1); \
else \
echo "make_dir: $(1) exists and it is not a directory" >&2; \
fi; \
fi
endef
# ----------------------------------------------------------------------
# python
# ----------------------------------------------------------------------
ifeq ($(CONFIGURE_PYTHON),1)
PYTHON_CONFIG = python3-config
PYTHON_MODULE_SUFFIX = $(shell $(PYTHON_CONFIG) --extension-suffix)
PYTHON_INCLUDES = $(shell $(PYTHON_CONFIG) --includes)
ifeq (,$(shell $(PYTHON_CONFIG) --ldflags | grep -e -lpython))
# use --embed starting with python 3.8
PYTHON_LIBS = $(shell $(PYTHON_CONFIG) --ldflags --embed)
else
PYTHON_LIBS = $(shell $(PYTHON_CONFIG) --ldflags | sed -E 's/-Wl,-stack_size,[0-9]+//')
endif
# $(1) - source lib
define install_py_lib
$(call symbolic_link,$(1),$(AD_PY))
endef
endif
# ----------------------------------------------------------------------
# boost
# ----------------------------------------------------------------------
ifeq ($(CONFIGURE_BOOST),1)
BOOST_VERSION_HPP = $(realpath /usr/include/boost/version.hpp /usr/local/include/boost/version.hpp) # /usr/local/opt/[email protected]/include/boost/version.hpp)
ifeq (,$(BOOST_VERSION_HPP))
ifeq ($(PLATFORM),darwin)
$(error install boost: brew install boost)
else
$(error install boost: apt-get install libboost-dev libboost-date-time-dev)
endif
endif
BOOST_ROOT = $(subst /include/boost/version.hpp,,$(word 1,$(BOOST_VERSION_HPP)))
# BOOST_INCLUDES = -I$(BOOST_ROOT)/include
BOOST_LIB_PATH = $(BOOST_ROOT)/lib
L_BOOST = -L$(BOOST_LIB_PATH)
endif
# ----------------------------------------------------------------------
# cairo
# ----------------------------------------------------------------------
ifeq ($(CONFIGURE_CAIRO),1)
CAIRO_LIBS = $(shell pkg-config --libs cairo)
ifeq ($(PLATFORM),darwin)
# homebrew has issues 2019-03-19 https://github.com/Homebrew/homebrew-core/issues/37873
CAIRO_INCLUDES = $(shell env PKG_CONFIG_PATH=$(BREW_PREFIX)/opt/libffi/lib/pkgconfig pkg-config --cflags cairo)
else
CAIRO_INCLUDES = $(shell pkg-config --cflags cairo)
endif
endif
# ----------------------------------------------------------------------
# openssl
# ----------------------------------------------------------------------
ifeq ($(CONFIGURE_OPENSSL),1)
ifeq ($(PLATFORM),darwin)
OPENSSL_LIBS = -L$(BREW_PREFIX)/opt/openssl/lib $(shell env PKG_CONFIG_PATH="$(BREW_PREFIX)/opt/openssl/lib/pkgconfig" pkg-config --libs openssl)
OPENSSL_INCLUDES = -I$(BREW_PREFIX)/opt/openssl/include
else
OPENSSL_LIBS = $(shell pkg-config --libs openssl)
OPENSSL_INCLUDES = $(shell pkg-config --cflags openssl)
endif
endif
# ----------------------------------------------------------------------
# mongo
# ----------------------------------------------------------------------
ifeq ($(CONFIGURE_MONGO),1)
MONGO_LIBS = -L$(AD_LIB) -lmongocxx -lbsoncxx
MONGO_INCLUDES = -I$(AD_INCLUDE)/mongocxx/v_noabi -I$(AD_INCLUDE)/bsoncxx/v_noabi
endif
# ----------------------------------------------------------------------
# fmt
# ----------------------------------------------------------------------
FMT_LIBS = -L$(AD_LIB) -lfmt
# ----------------------------------------------------------------------
# openxlsx
# ----------------------------------------------------------------------
OPENXLSX_INCLUDES = -I$(AD_INCLUDE)/OpenXLSX
OPENXLSX_LIBS = -L$(AD_LIB) -lOpenXLSX
# ----------------------------------------------------------------------
# xlnt
# ----------------------------------------------------------------------
XLNT_INCLUDES =
XLNT_LIBS = -L$(AD_LIB) -lxlnt
# ----------------------------------------------------------------------
# libcurl
# ----------------------------------------------------------------------
ifeq ($(CONFIGURE_LIBCURL),1)
ifneq ($(shell if pkg-config libcurl; then echo 1; fi),1)
$(error Please install libcurl (apt-get install libcurl4-openssl-dev))
endif
LIBCURL_LIBS = $(shell pkg-config --libs libcurl)
LIBCURL_INCLUDES = $(shell pkg-config --cflags libcurl)
endif
# ----------------------------------------------------------------------
# guile
# ----------------------------------------------------------------------
ifeq ($(CONFIGURE_GUILE),1)
GUILE_LIBS = $(shell guile-config link)
GUILE_INCLUDES = $(shell guile-config compile)
endif
# ----------------------------------------------------------------------
# sass
# ----------------------------------------------------------------------
ifeq ($(CONFIGURE_SASS),1)
SASSC = sassc
ifeq ($(shell if $(SASSC) -v >/dev/null 2>&1; then echo 1; fi),)
$(error Please install SASSC)
endif
# $(1) - target
# $(2) - source
define sass
echo "SASS " $(notdir $@)
$(SASSC) --style compressed -I sass $(abspath $<) $(basename $@)
gzip -9f $(basename $@)
endef
endif
# ----------------------------------------------------------------------
# rtags
# ----------------------------------------------------------------------
ifeq ($(NO_RTAGS_TARGET),)
ifndef RTAGS_TARGET
RTAGS_TARGET = all
endif
rtags:
$(MAKE) -nkB $(RTAGS_TARGET) | grep -e -MMD | /usr/local/bin/rc --compile -
endif
# ----------------------------------------------------------------------
# armadillo http://arma.sourceforge.net
# ----------------------------------------------------------------------
ifeq ($(CONFIGURE_ARMADILLO),1)
ifeq ($(PLATFORM),darwin)
ifneq ($(shell if pkg-config armadillo; then echo 1; fi),1)
$(error Please install armadillo (brew install armadillo))
endif
LIBARMADILLO_LIBS = $$(pkg-config --libs armadillo) -framework Accelerate
LIBARMADILLO_INCLUDES = $$(pkg-config --cflags arpack armadillo)
else
ARAMDILLO_H = $(realpath /usr/include/armadillo)
ifeq (,$(ARAMDILLO_H))
$(error Please install armadillo (apt install libarmadillo-dev))
endif
LIBARMADILLO_LIBS = -larmadillo -lblas
LIBARMADILLO_INCLUDES =
endif
endif
# ----------------------------------------------------------------------
-include $(BUILD)/*.d
# ----------------------------------------------------------------------
# rules
# ----------------------------------------------------------------------
# abspath below is to show full file path by __FILE__ macro used in logging
$(BUILD)/%.o: cc/%.cc | $(BUILD) install-headers
$(call echo_compile,$<)
ifeq ($(ECHO_COMPILATION_COMMAND),1)
echo $(CXX) $(CXXFLAGS) -c -o $@ $(abspath $<)
endif
$(TIME_CMD) $(CXX) $(CXXFLAGS) -c -o $@ $(abspath $<)
install-headers:
$(call install_headers,$(AD_PACKAGE_NAME))
make-installation-dirs: $(AD_INCLUDE) $(AD_LIB) $(AD_SHARE) $(AD_CONF) $(AD_TEMPLATES) $(AD_DOC) $(AD_BIN) $(AD_PY) $(AD_DATA)
.PHONY: make-installation-dirs
$(AD_BIN) $(AD_INCLUDE) $(AD_LIB) $(AD_PY) $(AD_SHARE):
ifeq ($(PLATFORM),darwin)
mkdir -p $(AD_BUILD)/$(@F) && if [ ! -L $@ ]; then rm -f $@; ln -sv $(AD_BUILD)/$(@F) $@; fi
else ifeq ($(PLATFORM),linux)
$(call make_dir,$@)
endif
$(AD_BUILD) $(AD_CONF) $(AD_TEMPLATES) $(AD_DOC) $(AD_DATA): $(AD_SHARE)
$(call make_dir,$@)
ifeq ($(NO_CLEAN_TARGET),)
clean:
rm -rf $(DIST) $(BUILD)
endif
$(DIST): $(AD_BUILD)
mkdir -pv $@
$(call symbolic_link,$@,dist)
$(BUILD): $(AD_BUILD)
mkdir -pv $@
$(call symbolic_link,$@,build)
# avoid deleting intermediate files
.SECONDARY:
# ----------------------------------------------------------------------
help-vars:
printf "\nVariables:\n"
printf "\tVERBOSE=1 - echo commands being executed\n"
printf "\tDEBUG=1 - disable optimisation and omp\n"
printf "\tC=CLANG or C=GCC10 - compiler to use\n"
printf "\n"
# ======================================================================