forked from libxsmm/libxsmm
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile.inc
1615 lines (1523 loc) · 50.4 KB
/
Makefile.inc
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
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#############################################################################
# Copyright (c) 2015-2018, Intel Corporation #
# All rights reserved. #
# #
# Redistribution and use in source and binary forms, with or without #
# modification, are permitted provided that the following conditions #
# are met: #
# 1. Redistributions of source code must retain the above copyright #
# notice, this list of conditions and the following disclaimer. #
# 2. Redistributions in binary form must reproduce the above copyright #
# notice, this list of conditions and the following disclaimer in the #
# documentation and/or other materials provided with the distribution. #
# 3. Neither the name of the copyright holder nor the names of its #
# contributors may be used to endorse or promote products derived #
# from this software without specific prior written permission. #
# #
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS #
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT #
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR #
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT #
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, #
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED #
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR #
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF #
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING #
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS #
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #
#############################################################################
# Hans Pabst (Intel Corp.)
#############################################################################
MAKEINC = $(abspath $(dir $(filter %Makefile.inc,$(MAKEFILE_LIST))))
ifeq (d,$(filter d,$(MAKEFLAGS)))
SHELL = bash -xv
endif
ifeq (Windows_NT,$(OS))
UNAME ?= Windows_NT
ENV ?= $(NULL)
# Cygwin/MinGW based
DLIBEXT ?= dll
SLIBEXT ?= lib
endif
# Command line utilities
#PKGCFG ?= $(shell which pkg-config 2>/dev/null)
CP ?= $(shell which cp 2>/dev/null)
MV ?= $(shell which mv 2>/dev/null)
UNAME ?= $(shell uname)
MAKE ?= make
ENV ?= env
# Python interpreter per PYTHON=/path/to/python
PYTHON3 ?= $(shell which python3 2>/dev/null)
PYTHON ?= $(shell which python 2>/dev/null)
ifeq (,$(PYTHON))
ifneq (,$(PYTHON3))
SHELL := env PATH=$(MAKEINC):$(PATH) $(SHELL)
PYTHON = $(shell ln -s $(PYTHON3) $(MAKEINC)/python 2>/dev/null && which python 2>/dev/null)
else
$(info ERROR: No Python interpreter found!)
endif
endif
ifneq (Darwin,$(UNAME))
ifneq (,$(strip $(CP)))
CP += -u
endif
DLIBEXT ?= so
SLIBEXT ?= a
else
DLIBEXT ?= dylib
SLIBEXT ?= a
endif
# Regular expression to match "main" (good-enough pattern)
CMAIN = "main\s*(.*)"
FMAIN = "^\s*PROGRAM\s\s*\w\w*\(\s\s*\!.*\)*$$"
# Debugging and symbols (e.g., when profiling)
SYM ?= 0
DBG ?= 0
# Optimization level
ifeq (0,$(DBG))
OPT ?= 2
else
OPT ?= 0
endif
# Optimization flag derived from OPT flag
ifeq (0,$(shell echo "$(OPT)" | grep -q "^[0-9]\+$$"; echo "$$?"))
OPTFLAG = -O$(OPT)
else
OPTFLAG = -$(OPT)
endif
# Instrumentation level (trace)
ifeq (,$(strip $(INSTRUMENT)))
INSTRUMENT = 0
endif
TRACE ?= 0
# Number of repeated calls (tests),
# or used to scale the problem size
TESTSIZE ?= 1
# PYMOD=1: enable Python module development
PYMOD ?= 0
# Static or shared binary
STATIC ?= 0
# PIC: PIC or pic
PIC ?= pic
# Intrinsics support level
INTRINSICS ?= 2
ifneq (0,$(INTRINSICS))
ifeq (1,$(INTRINSICS))
DFLAGS += -DLIBXSMM_INTRINSICS_STATIC
endif
else # disabled
DFLAGS += -DLIBXSMM_INTRINSICS_NONE
endif
OFFLOAD ?= 0
ifneq (0,$(OFFLOAD))
MPSS ?= 1
KNC ?= 1
else
MPSS ?= 0
KNC ?= 0
endif
DEPDIR ?= $(ROOTDIR)
ifeq (0,$(KNC))
LIBNAME ?= $(DEPDIR)/lib/libxsmm
else ifneq (3,$(AVX))
ifeq (0,$(OFFLOAD))
LIBNAME ?= $(DEPDIR)/lib/mic/libxsmm
else
LIBNAME ?= $(DEPDIR)/lib/libxsmm
endif
else
LIBNAME ?= $(DEPDIR)/lib/libxsmm
endif
# Internal utilities
MKTEMP = $(DEPDIR)/.mktmp.sh
FLOCK = $(DEPDIR)/.flock.sh
# THREADS refers to foundational TRT (and not necessarily Posix Threads)
THREADS ?= 1
# Threading runtime
ifeq (0,$(THREADS))
override OMP = 0
endif
OMP ?= 0
# Code conformance (beyond -Wall)
PEDANTIC ?= 0
# Embed InterProcedural Optimization information into libraries
IPO ?= 0
# ILP64=0 (LP64 with 32-bit integers), and ILP64=0 (64-bit integers)
ILP64 ?= 0
# TBB enabled (1) or disabled (0)
# availability depends on TBBROOT
TBB ?= 0
# TBB runtime compatible with oldest supported GCC
TBB_OLDRTL ?= 0
# C Compiler is used for link stage
ifneq (Darwin,$(UNAME))
XGROUP_BEGIN = -Wl,--start-group
XGROUP_END = -Wl,--end-group
XLIB_BEGIN = -Wl,--as-needed
XLIB_END = -Wl,--no-as-needed
XRPATH = -Wl,--rpath=$(NULL)
else
XRPATH = -Xlinker -rpath -Xlinker $(NULL)
endif
# Enable absolute library paths
ABSLIBS ?= 0
abslibrpath = $(strip $(if $(wildcard $1),$(XRPATH)$(dir $(abspath $1)),$(NULL)))
absliblpath = $(strip $(if $(filter .$(DLIBEXT),$(suffix $1)), \
$(if $1,-L$(dir $(abspath $1)),-L$(dir $1)),$(NULL)))
abslibfile = $(strip $(if $(filter .$(DLIBEXT),$(suffix $1)), \
$(if $(patsubst lib%,%,$(basename $(notdir $1))), \
-l$(patsubst lib%,%,$(basename $(notdir $1))),$(NULL)),$1))
ifneq (0,$(ABSLIBS))
abslibpath = $(strip $(call abslibrpath,$1) $(call absliblpath,$1))
else
abslibpath = $(call absliblpath,$1)
endif
BRACE_OPEN := (
BRACE_CLOSE := )
libpath = $(strip $(if $1, \
$(if $(shell $1 $2 -l$3 2>&1 | grep "\-l$3"),$(NULL), \
$(subst //,/,$(abspath $(shell $1 $2 -l$3 -Wl,--verbose 2>/dev/null | grep "$3" | tail -n1 | grep -o "[^ ()]*" | grep "\/")))), \
$(NULL)))
abslib = $(strip $(call abslibpath,$1) $(call abslibfile,$1))
# Embedd soname into shared library
SONAMELNK ?= 2
ifneq (Darwin,$(UNAME))
ifeq (0,$(shell ln -fs this-file-does-not-exist .ln 2>/dev/null && echo "$$?" && rm .ln 2>/dev/null))
solink = -o $1.$2.$3.$4 -Wl,-soname=$(strip $(notdir $1).$5)
ifneq (0,$(SONAMELNK))
solink += $(shell cd $(dir $1) && ln -fs $(notdir $1.$2.$3.$4) $(notdir $1.$5))
endif
ifneq (0,$(shell echo "$$((1<$(SONAMELNK) || 0>$(SONAMELNK)))"))
solink += $(shell cd $(dir $1) && ln -fs $(notdir $1.$5) $(notdir $1))
endif
else # MinGW
solink = -o $1 -Wl,-soname=$(strip $(notdir $1).$5)
endif
else # osx
solink = -o $(basename $1).$2$(suffix $1) \
-install_name $(notdir $(basename $1).$2$(suffix $1)) \
-current_version $2.$3.$4 -compatibility_version $5
ifneq (0,$(SONAMELNK))
solink += $(shell cd $(dir $1) && ln -fs $(notdir $(basename $1).$2$(suffix $1)) $(notdir $1))
endif
endif
# Pickup OpenMP library name if passed as OMP=libname|name
ifneq (0,$(shell echo "$(OMP)" | grep -q "^-*[0-9]\+$$"; echo "$$?")) # NaN
OMPRT = $(patsubst lib%,%,$(OMP))
endif
ifneq (0,$(PYMOD))
PYVERSION_STRING = $(shell $(PYTHON) --version 2>&1 | head -n1 | sed "s/..* \([0-9][0-9]*\.[0-9][0-9]*\.*[0-9]*\)[ \S]*.*/\1/")
PYVERSION = $(shell echo "$(PYVERSION_STRING)" | cut -d"." -f1,2)
PYROOT = $(abspath $(dir $(shell which $(PYTHON) 2>/dev/null))/..)
PYINC = $(wildcard $(PYROOT)/include/python$(PYVERSION)/Python.h)
ifneq (,$(PYINC))
LDFLAGS += -lpython$(PYVERSION)
IFLAGS += -I$(dir $(PYINC))
DFLAGS += -D__PYTHON
# Avoid (unresolved) BLAS (alternative: BLAS=1|2)
ifeq (,$(filter environment% override command%,$(origin BLAS)))
override BLAS = 0
endif
# Enable shared library (req. for Python module)
override STATIC = 0
endif
endif
# Explicitly disables BLAS by user's intervention
# Makefile defines what happens (perhaps nothing)
NOBLAS ?= 0
DNOBLAS = -D__BLAS=0
ifneq (,$(filter environment% override command%,$(origin BLAS)))
ifeq (0,$(BLAS))
BLAS_FLAGS += $(DNOBLAS)
NOBLAS = 1
endif
endif
# Secondary static
ifneq (file,$(origin STATIC)) # prefer user override/preference (in any case)
DEPSTATIC ?= $(STATIC)
else ifneq (,$(wildcard $(LIBNAME).$(SLIBEXT))) # prefer static (library exists)
DEPSTATIC ?= 1
else ifneq (0,$(STATIC))
DEPSTATIC ?= $(STATIC)
else
DEPSTATIC ?= 0
endif
# Library extension
ifneq (0,$(DEPSTATIC))
LIBEXT ?= $(SLIBEXT)
else
LIBEXT ?= $(DLIBEXT)
endif
# Separate control on how to link against the BLAS library
BLAS_STATIC ?= $(DEPSTATIC)
ifneq (0,$(BLAS_STATIC))
BLASLIBEXT ?= $(SLIBEXT)
else # shared (DLL)
BLASLIBEXT ?= $(IMPEXT)
endif
# BLAS is not used by default
BLAS ?= 0
LIBDEP = $(LIBNAME).$(IMPEXT)
MAINLIB = $(call abslib,$(LIBDEP))
FORTDEP = $(LIBNAME)f.$(IMPEXT)
FORTLIB = $(call abslib,$(FORTDEP))
EXTDEP = $(LIBNAME)ext.$(IMPEXT)
EXTLIB = $(XLIB_BEGIN) $(call abslib,$(EXTDEP)) $(XLIB_END)
ifeq (0,$(BLAS))
# provides libxsmmnoblas to satisfy BLAS symbols
NOBLASLIB = $(XLIB_BEGIN) $(call abslib,$(LIBNAME)noblas.$(IMPEXT)) $(XLIB_END)
else
NOBLASLIB = $(NULL)
endif
XBLASLIB ?= $(NOBLASLIB)
COMPILER_VERSION_FLAG ?= --version
CC_VERSION_FLAG ?= $(COMPILER_VERSION_FLAG)
FC_VERSION_FLAG ?= $(COMPILER_VERSION_FLAG)
CXX_VERSION_FLAG ?= $(CC_VERSION_FLAG)
# Automatically pickup the environment (make -e not needed),
# or pickup the Intel Compiler (if available).
ifneq (,$(notdir $(shell which icpc 2>/dev/null)))
CXX = icpc
endif
ifneq (,$(notdir $(shell which icc 2>/dev/null)))
CC = icc
endif
ifneq (,$(notdir $(shell which ifort 2>/dev/null)))
FC = ifort
endif
# check if the Intel Development Tools are available
INTEL ?= $(shell echo "$$((2==$(words $(filter icpc icc, \
$(shell $(CXX) $(CXX_VERSION_FLAG) 2>/dev/null | head -n1 | cut -d' ' -f1) \
$(shell $(CC) $(CC_VERSION_FLAG) 2>/dev/null | head -n1 | cut -d' ' -f1)))))")
ifneq (0,$(INTEL))
ifeq (0,$(OFFLOAD))
CXXFLAGS += -qno-offload
CFLAGS += -qno-offload
ifneq (,$(strip $(FC)))
ifeq (ifort,$(shell $(FC) $(FC_VERSION_FLAG) 2>/dev/null | head -n1 | cut -d" " -f1))
FCFLAGS += -qno-offload
endif
endif
endif
else
ifeq (,$(notdir $(shell which $(CXX) 2>/dev/null)))
CXX = g++
else ifneq (0,$(shell $(CXX) $(CXX_VERSION_FLAG) >/dev/null 2>/dev/null; echo "$$?"))
CXX = g++
endif
ifeq (,$(notdir $(shell which $(CC) 2>/dev/null)))
CC = gcc
else ifneq (0,$(shell $(CC) $(CC_VERSION_FLAG) >/dev/null 2>/dev/null; echo "$$?"))
CC = gcc
endif
ifneq (0,$(FORTRAN))
ifneq (,$(strip $(FC)))
ifneq (0,$(shell $(FC) $(FC_VERSION_FLAG) >/dev/null 2>/dev/null; echo "$$?"))
ifneq (,$(notdir $(shell which gfortran 2>/dev/null)))
FC = gfortran
else
FC = $(NULL)
endif
endif
endif
endif
endif
ifeq (0,$(FORTRAN))
FC = $(NULL)
endif
ifeq (,$(strip $(FC)))
DFLAGS += -DLIBXSMM_NOFORTRAN
endif
CXX_VERSION_STRING = $(shell $(CXX) $(CXX_VERSION_FLAG) 2>/dev/null | head -n1 | sed "s/..* \([0-9][0-9]*\.[0-9][0-9]*\.*[0-9]*\)[ \S]*.*/\1/")
CXX_VERSION_MAJOR = $(shell echo "$(CXX_VERSION_STRING)" | cut -d"." -f1)
CXX_VERSION_MINOR = $(shell echo "$(CXX_VERSION_STRING)" | cut -d"." -f2)
CXX_VERSION_PATCH = $(shell echo "$(CXX_VERSION_STRING)" | cut -d"." -f3)
ifeq (3,$(words $(CXX_VERSION_MAJOR) $(CXX_VERSION_MINOR) $(CXX_VERSION_PATCH)))
CXX_VERSION = $(shell echo "$$(($(CXX_VERSION_MAJOR)*10000+$(CXX_VERSION_MINOR)*100+$(CXX_VERSION_PATCH)))")
else ifeq (2,$(words $(CXX_VERSION_MAJOR) $(CXX_VERSION_MINOR)))
CXX_VERSION = $(shell echo "$$(($(CXX_VERSION_MAJOR)*10000+$(CXX_VERSION_MINOR)*100))")
CXX_VERSION_PATCH = 0
else
CXX_VERSION_STRING = $(NULL)
CXX_VERSION = 0
endif
CC_VERSION_STRING = $(shell $(CC) $(CC_VERSION_FLAG) 2>/dev/null | head -n1 | sed "s/..* \([0-9][0-9]*\.[0-9][0-9]*\.*[0-9]*\)[ \S]*.*/\1/")
CC_VERSION_MAJOR = $(shell echo "$(CC_VERSION_STRING)" | cut -d"." -f1)
CC_VERSION_MINOR = $(shell echo "$(CC_VERSION_STRING)" | cut -d"." -f2)
CC_VERSION_PATCH = $(shell echo "$(CC_VERSION_STRING)" | cut -d"." -f3)
ifeq (3,$(words $(CC_VERSION_MAJOR) $(CC_VERSION_MINOR) $(CC_VERSION_PATCH)))
CC_VERSION = $(shell echo "$$(($(CC_VERSION_MAJOR)*10000+$(CC_VERSION_MINOR)*100+$(CC_VERSION_PATCH)))")
else ifeq (2,$(words $(CC_VERSION_MAJOR) $(CC_VERSION_MINOR)))
CC_VERSION = $(shell echo "$$(($(CC_VERSION_MAJOR)*10000+$(CC_VERSION_MINOR)*100))")
CC_VERSION_PATCH = 0
else
CC_VERSION_STRING = $(NULL)
CC_VERSION = 0
endif
ifneq (,$(strip $(FC)))
FC_VERSION_STRING := $(shell $(FC) $(FC_VERSION_FLAG) 2>/dev/null | head -n1 | sed "s/..* \([0-9][0-9]*\.[0-9][0-9]*\.*[0-9]*\)[ \S]*.*/\1/")
FC_VERSION_MAJOR = $(shell echo "$(FC_VERSION_STRING)" | cut -d"." -f1)
FC_VERSION_MINOR = $(shell echo "$(FC_VERSION_STRING)" | cut -d"." -f2)
FC_VERSION_PATCH = $(shell echo "$(FC_VERSION_STRING)" | cut -d"." -f3)
endif
ifeq (3,$(words $(FC_VERSION_MAJOR) $(FC_VERSION_MINOR) $(FC_VERSION_PATCH)))
FC_VERSION = $(shell echo "$$(($(FC_VERSION_MAJOR)*10000+$(FC_VERSION_MINOR)*100+$(FC_VERSION_PATCH)))")
else ifeq (2,$(words $(FC_VERSION_MAJOR) $(FC_VERSION_MINOR)))
FC_VERSION = $(shell echo "$$(($(FC_VERSION_MAJOR)*10000+$(FC_VERSION_MINOR)*100))")
FC_VERSION_PATCH = 0
else
FC_VERSION_STRING = $(NULL)
FC_VERSION = 0
endif
ifneq (,$(strip $(FC)))
ifeq (GNU,$(shell $(FC) $(FC_VERSION_FLAG) 2>/dev/null | head -n1 | cut -d" " -f1))
ifneq (0,$(shell echo "$$((40500>$(FC_VERSION)))"))
ifneq (gfortran,$(notdir $(FC)))
FC = gfortran
FC_VERSION_STRING := $(shell $(FC) $(FC_VERSION_FLAG) 2>/dev/null | head -n1 | sed "s/..* \([0-9][0-9]*\.[0-9][0-9]*\.*[0-9]*\)[ \S]*.*/\1/")
FC_VERSION_MAJOR = $(shell echo "$(FC_VERSION_STRING)" | cut -d"." -f1)
FC_VERSION_MINOR = $(shell echo "$(FC_VERSION_STRING)" | cut -d"." -f2)
FC_VERSION_PATCH = $(shell echo "$(FC_VERSION_STRING)" | cut -d"." -f3)
ifeq (3,$(words $(FC_VERSION_MAJOR) $(FC_VERSION_MINOR) $(FC_VERSION_PATCH)))
FC_VERSION = $(shell echo "$$(($(FC_VERSION_MAJOR)*10000+$(FC_VERSION_MINOR)*100+$(FC_VERSION_PATCH)))")
else ifeq (2,$(words $(FC_VERSION_MAJOR) $(FC_VERSION_MINOR)))
FC_VERSION = $(shell echo "$$(($(FC_VERSION_MAJOR)*10000+$(FC_VERSION_MINOR)*100))")
FC_VERSION_PATCH = 0
else
FC_VERSION = 0
endif
ifneq (0,$(shell echo "$$((40500>$(FC_VERSION)))"))
# keep FC_VERSION_STRING available for message about outdated compiler
override FC = $(NULL)
FC_VERSION = 0
FORTRAN = 0
endif
else
# keep FC_VERSION_STRING available for message about outdated compiler
override FC = $(NULL)
FC_VERSION = 0
FORTRAN = 0
endif
endif
else ifneq (0,$(INTEL))
ifneq (0,$(shell echo "$$((130000>$(FC_VERSION) && 0<$(FC_VERSION)))"))
override FC = $(NULL)
FC_VERSION = 0
FORTRAN = 0
endif
endif
endif
# compiler names
CXX_NAME = $(basename $(shell $(CXX) $(CXX_VERSION_FLAG) 2>/dev/null | head -n1 \
| sed -e "s/^\([^0-9][^0-9]*\) ..*/\1/" -e "s/ version//" -e "s/ $(BRACE_OPEN)..*//" \
| rev | cut -d" " -f1 | rev))
ifeq (,$(strip $(CXX_NAME)))
CXX_NAME = $(basename $(notdir $(CXX)))
endif
CC_NAME = $(basename $(shell $(CC) $(CC_VERSION_FLAG) 2>/dev/null | head -n1 \
| sed -e "s/^\([^0-9][^0-9]*\) ..*/\1/" -e "s/ version//" -e "s/ $(BRACE_OPEN)..*//" \
| rev | cut -d" " -f1 | rev))
ifeq (,$(strip $(CC_NAME)))
CC_NAME = $(basename $(notdir $(CC)))
endif
ifneq (,$(strip $(FC)))
FC_NAME = $(firstword $(notdir $(FC)))
endif
ifeq (,$(strip $(FC_NAME)))
FC_NAME = $(basename $(notdir $(FC)))
endif
# native GCC?
GCC ?= 0
ifeq (0,$(shell $(CC) $(CC_VERSION_FLAG) 2>/dev/null | grep -q "Free Software Foundation"; echo "$$?"))
GCC = 1
else ifeq (GCC,$(shell $(CC) $(CC_VERSION_FLAG) 2>/dev/null | head -n1 | sed "s/.* (\(..*\)) .*/\1/"))
GCC = 1
else ifneq (pgcc,$(CC_NAME))
ifneq (,$(findstring pgcc,$(CC_NAME)))
GCC = 1
endif
endif
ifeq (1,$(GCC))
ifeq (0,$(shell $(CXX) $(CXX_VERSION_FLAG) 2>/dev/null | grep -q "Free Software Foundation"; echo "$$?"))
GCC = 2
else ifeq (GCC,$(shell $(CXX) $(CXX_VERSION_FLAG) 2>/dev/null | head -n1 | sed "s/.* (\(..*\)) .*/\1/"))
GCC = 2
else ifneq (,$(findstring g++,$(CXX_NAME)))
GCC = 2
endif
ifeq (2,$(GCC))
ifneq (,$(strip $(FC)))
ifeq (GCC,$(shell $(FC) $(FC_VERSION_FLAG) 2>/dev/null | head -n1 | sed "s/.* (\(..*\)) .*/\1/"))
GCC = 3
else ifeq (0,$(shell $(FC) $(FC_VERSION_FLAG) 2>/dev/null | grep -q "Free Software Foundation"; echo "$$?"))
GCC = 3
else ifneq (pgfortran,$(CC_NAME))
ifneq (,$(findstring gfortran,$(FC_NAME)))
GCC = 3
endif
endif
endif
endif
endif
FORCE_CXX ?= 0
ifneq (0,$(FORCE_CXX))
CC = $(CXX)
endif
ifeq (Windows_NT,$(UNAME))
ifeq (MINGW64,$(MSYSTEM))
MINGW = 64
else ifeq (MINGW32,$(MSYSTEM))
MINGW = 32
else ifeq (0,$(shell $(CC) -dM -E - < /dev/null 2>/dev/null | grep -q "__MINGW64__"; echo "$$?"))
MINGW = 64
else ifeq (0,$(shell $(CC) -dM -E - < /dev/null 2>/dev/null | grep -q "__MINGW32__"; echo "$$?"))
MINGW = 32
endif
endif
MINGW ?= 0
#ifneq (0,$(MINGW))
# IMPEXT ?= $(SLIBEXT)
#endif
IMPEXT ?= $(LIBEXT)
# Too many ICEs with Clang hence we want to know if we are on Clang
ifeq (0,$(GCC)) # not GCC
ifeq (0,$(INTEL)) # not Intel
ifeq (0,$(shell $(CC) -dM -E - < /dev/null 2>/dev/null | grep -q "__clang__"; echo "$$?"))
CLANG = 1
endif
endif
endif
CLANG ?= 0
# Make GCC version number available even when not using GCC
ifneq (0,$(shell echo "$$((1<=$(GCC)))"))
GCC_VERSION_STRING = $(CXX_VERSION_STRING)
GCC_VERSION_MAJOR = $(CXX_VERSION_MAJOR)
GCC_VERSION_MINOR = $(CXX_VERSION_MINOR)
GCC_VERSION_PATCH = $(CXX_VERSION_PATCH)
else ifeq (0,$(CLANG))
GCCBIN = $(notdir $(shell which gcc 2>/dev/null))
ifneq (,$(strip $(GCCBIN)))
GCC_VERSION_STRING = $(shell $(GCCBIN) $(CXX_VERSION_FLAG) 2>/dev/null | head -n1 | sed "s/..* \([0-9][0-9]*\.[0-9][0-9]*\.*[0-9]*\)[ \S]*.*/\1/")
GCC_VERSION_MAJOR = $(shell echo "$(GCC_VERSION_STRING)" | cut -d"." -f1)
GCC_VERSION_MINOR = $(shell echo "$(GCC_VERSION_STRING)" | cut -d"." -f2)
GCC_VERSION_PATCH = $(shell echo "$(GCC_VERSION_STRING)" | cut -d"." -f3)
endif
endif
ifeq (3,$(words $(GCC_VERSION_MAJOR) $(GCC_VERSION_MINOR) $(GCC_VERSION_PATCH)))
GCC_VERSION = $(shell echo "$$(($(GCC_VERSION_MAJOR)*10000+$(GCC_VERSION_MINOR)*100+$(GCC_VERSION_PATCH)))")
else ifeq (2,$(words $(GCC_VERSION_MAJOR) $(GCC_VERSION_MINOR)))
GCC_VERSION = $(shell echo "$$(($(GCC_VERSION_MAJOR)*10000+$(GCC_VERSION_MINOR)*100))")
GCC_VERSION_PATCH = 0
else
GCC_VERSION_STRING = $(NULL)
GCC_VERSION = 0
endif
# Select code path (if not selected otherwise)
CPUFLAGS = $(strip $(shell if [ -e /proc/cpuinfo ]; then \
grep -m1 flags /proc/cpuinfo | cut -d: -f2-; \
elif [ "Darwin" = "$(UNAME)" ]; then \
sysctl -a machdep.cpu.features \
machdep.cpu.extfeatures \
machdep.cpu.leaf7_features \
| cut -d: -f2- | tr "\n" " " | tr [:upper:] [:lower:]; \
fi))
SSE ?= 0
ifeq (0,$(SSE)) # discover AVX
ifeq (1,$(words $(filter avx512f,$(CPUFLAGS))))
AVX ?= 3
SSE = 0
ifeq (2,$(words $(filter avx512pf avx512er,$(CPUFLAGS)))) # KNL
MIC ?= 1
else # SKX
MIC ?= 0
endif
else ifeq (1,$(words $(filter avx avx1.0,$(CPUFLAGS))))
ifeq (1,$(words $(filter fma,$(CPUFLAGS))))
AVX ?= 2
else
AVX ?= 1
endif
SSE = 0
endif
else ifeq (1,$(SSE)) # discover SSE
ifeq (1,$(words $(filter sse4_2 sse4.2,$(CPUFLAGS))))
SSE = 4
else ifneq (0,$(words $(filter sse3 ssse3,$(CPUFLAGS))))
SSE = 3
else #ifeq (,$(SSE))
SSE = 0
endif
else ifneq (0,$(KNC))
MPSS = 1
endif
AVX ?= 0
ifneq (0,$(INTEL))
SUITE = Intel Compiler
else ifneq (0,$(GCC))
SUITE = GNU Compiler Collection
else
SUITE = Compiler
ifeq (0,$(CLANG))
COMPATIBLE ?= 1
endif
ifneq (0,$(COMPATIBLE))
ifeq (Cray,$(shell $(CC) -V 2>&1 | head -n1 | cut -d' ' -f1))
LDFLAGS += -hsystem_alloc
CRAY ?= 1
else
PGI ?= $(shell $(CC) $(CC_VERSION_FLAG) 2>/dev/null | if grep -q "PGI"; then echo "1"; else echo "0"; fi)
endif
endif
endif
CRAY ?= 0
PGI ?= 0
# linker setup
LD = $(CC)
XLD = $(CXX)
ifeq (0,$(DEPSTATIC))
LIB_LD := $(LD) -shared
LIB_XLD := $(XLD) -shared
else
LIB_LD := $(LD)
LIB_XLD := $(XLD)
endif
ifeq (3,$(GCC)) # try to avoid some more references to Fortran runtime libraries
LIBGFORTRAN = $(call libpath,$(FC) $(SLDFLAGS),$(NULL),gfortran)
ifneq (,$(strip $(LIBGFORTRAN)))
FLDFLAGS += $(call abslibpath,$(LIBGFORTRAN)) $(XLIB_BEGIN) $(call abslibfile,$(LIBGFORTRAN)) $(XLIB_END)
LIB_FLD = $(LIB_LD)
FLD = $(LD)
endif
endif
ifeq (,$(strip $(FLD)))
ifneq (,$(strip $(FC)))
FLD = $(FC)
ifeq (0,$(DEPSTATIC))
LIB_FLD := $(FLD) -shared
else
LIB_FLD := $(FLD)
endif
else # fallback
LIB_FLD := $(LIB_LD)
FLD := $(LD)
endif
endif
ifneq (0,$(CRAY))
ifeq (0,$(DEPSTATIC))
XLD := $(XLD) -dynamic
FLD := $(FLD) -dynamic
LD := $(LD) -dynamic
endif
endif
# Avoid more sophisticated flags of the GCC tool chain,
# and improve compatibility with compilers supposed to be
# compatible with the GCC tool chain
COMPATIBLE ?= 0
ifneq (0,$(INTEL))
AR ?= xiar
CXXLDFLAGS += $(XLIB_BEGIN) -lc $(XLIB_END)
FCLDFLAGS += $(XLIB_BEGIN) -lc -lstdc++ $(XLIB_END)
CLDFLAGS += $(XLIB_BEGIN) -lstdc++ $(XLIB_END)
CXXFLAGS += -Wall -diag-disable 1879,3415,3948,10006,10010,10411,13003
CFLAGS += -Wall -diag-disable 1879,3415,3948,10006,10010,10411,13003
LDFLAGS += -diag-disable 1879,3415,10006,10010,10411
FCFLAGS += -diag-disable 10006,10010,10411,13003
ifneq (0,$(THREADS))
FCMTFLAGS += -threads
endif
CPEDANTIC += -Wcheck -diag-disable 177,1419,2547,10382
FPEDANTIC += -warn all,notruncated_source -diag-disable 7025,7373,10237,10342,10382
CWARNEXTRA = -Wremarks
ifeq (1,$(PEDANTIC))
FSTD = -std03
CSTD = -std=c99
CXXFLAGS += -Wcheck
CFLAGS += $(CSTD) -Wcheck
FMFLAGS += $(FSTD) $(FPEDANTIC) -diag-disable 10010
FCFLAGS += -free
else ifneq (0,$(PEDANTIC))
FSTD = -std03
CSTD = -std=c89
CXXFLAGS += $(CPEDANTIC)
CFLAGS += $(CSTD) $(CPEDANTIC) $(CWARNEXTRA)
FCFLAGS += $(FSTD) $(FPEDANTIC)
FMFLAGS += -fixed
else
CSTD = -std=c89
FCFLAGS += -free
endif
# flag specifying output directory must be last
FMFLAGS += -module
CXXFLAGS += $(OPTFLAG)
CFLAGS += $(OPTFLAG)
FCFLAGS += $(OPTFLAG)
ifeq (0,$(DBG))
# consider more accurate -fp-model (C/C++: precise, Fortran: source)
CXXFLAGS += -fno-alias -ansi-alias -qoverride_limits #-fp-model fast=2
CFLAGS += -fno-alias -ansi-alias -qoverride_limits #-fp-model fast=2
FCFLAGS += -qoverride_limits #-fp-model fast=2
ifneq (0,$(shell echo "$$((130000<=$(FC_VERSION)))"))
FCFLAGS += -align array64byte
endif
ifneq (0,$(IPO))
CXXFLAGS += -ipo
CFLAGS += -ipo
FCFLAGS += -ipo
endif
ifneq (0,$(INSTRUMENT))
SYM = $(INSTRUMENT)
else ifeq (0,$(shell echo "$$((0>$(SYM)))"))
DFLAGS += -DNDEBUG
else
DFLAGS += -D_DEBUG
endif
else # debugging enabled
ifneq (0,$(shell echo "$$((1<$(DBG) || 0>$(DBG)))"))
DFLAGS += -D_DEBUG
endif
FCFLAGS += -check
SYM = $(DBG)
endif
ifneq (0,$(INSTRUMENT))
CXXFLAGS += -finstrument-functions
CFLAGS += -finstrument-functions
FCFLAGS += -finstrument-functions
DFLAGS += -D__TRACE=$(INSTRUMENT)
endif
ifneq (0,$(shell echo "$$((3>$(DBG)))"))
ifeq (0,$(COMPATIBLE))
ifneq (,$(filter environment% override command%,$(origin COMPATIBLE)))
ifeq (3,$(AVX))
ifeq (0,$(MIC))
ifneq (file,$(origin MIC))
CTARGET = -xCORE-AVX512
else
CTARGET = -xCOMMON-AVX512
endif
else
CTARGET = -xMIC-AVX512
endif
else ifeq (2,$(AVX))
CTARGET = -xCORE-AVX2
else ifeq (1,$(AVX))
CTARGET = -xAVX
else ifneq (0,$(SSE))
ifeq (1,$(SSE)) # default
CTARGET = -xSSE4.2
else ifeq (3,$(SSE))
ifneq (Darwin,$(UNAME))
CTARGET = -xSSE3
else # no systems with less than SSE4.2
CTARGET = -xSSE4.2
endif
else ifeq (4,$(SSE))
CTARGET = -xSSE4.2
else
CTARGET = -xSSE$(SSE)
endif
else ifneq (0,$(AVX))
CTARGET = -xHost
endif
endif
endif
ifeq (3,$(AVX))
ifneq (,$(MIC)) # specified
ifneq (0,$(MIC)) # MIC
CTARGET = -xMIC-AVX512
else # SKX
CTARGET = -xCORE-AVX512
endif
else
CTARGET = -xCOMMON-AVX512
endif
else ifeq (2,$(AVX))
CTARGET = -march=core-avx2
endif
endif
ifneq (0,$(SYM))
ifeq (1,$(SYM))
CXXFLAGS := -g $(CXXFLAGS)
CFLAGS := -g $(CFLAGS)
FCFLAGS := -g -traceback $(FCFLAGS)
else
CXXFLAGS := -g3 -debug inline-debug-info $(CXXFLAGS)
CFLAGS := -g3 -debug inline-debug-info $(CFLAGS)
FCFLAGS := -g -traceback $(FCFLAGS)
endif
endif
OMPFLAG = -fopenmp
ifeq (,$(strip $(OMPRT)))
OMPRT = iomp5
endif
ifneq (0,$(OMP))
CXXFLAGS += $(OMPFLAG)
CFLAGS += $(OMPFLAG)
FCFLAGS += $(OMPFLAG)
LDFLAGS += $(OMPFLAG)
endif
ifneq (0,$(SIMD))
ifneq (0,$(shell echo "$$((150000<=$(CXX_VERSION)))"))
DFLAGS += -DLIBXSMM_OPENMP_SIMD
CXXFLAGS += -qopenmp-simd
CFLAGS += -qopenmp-simd
FCFLAGS += -qopenmp-simd
endif
endif
ifeq (1,$(STATIC))
SLDFLAGS += -no-intel-extensions -static-intel -static-libstdc++
ifneq (Darwin,$(UNAME))
SLDFLAGS += -static-libgcc
endif
DFLAGS += -D__STATIC=1
else ifneq (0,$(STATIC))
DFLAGS += -D__STATIC=$(STATIC)
SLDFLAGS += -static
endif
ifneq (,$(strip $(R8)))
ifneq (0,$(R8))
FCFLAGS += -autodouble
endif
endif
# workaround for certain bits introduced by GCC 7.0
ifneq (0,$(shell echo "$$(((180000<=$(CC_VERSION) && 180001>$(CC_VERSION)) || (170006>$(CC_VERSION) && 0!=$(CC_VERSION))))"))
CFLAGS += -D_Float128=__float128
endif
else # GCC assumed
FCLDFLAGS += $(XLIB_BEGIN) -lc -lstdc++ $(XLIB_END)
CLDFLAGS += $(XLIB_BEGIN) -lstdc++ $(XLIB_END)
CXXLDFLAGS += $(XLIB_BEGIN) -lc $(XLIB_END)
LDFLAGS += $(XLIB_BEGIN) -lm $(XLIB_END)
ifeq (0,$(COMPATIBLE))
ifneq (0,$(shell echo "$$((40700<=$(GCC_VERSION)))"))
CXXFLAGS += -std=c++11
endif
CXXFLAGS += -Wall -Wno-unused-function #-Wno-attributes
CFLAGS += -Wall -Wno-unused-function #-Wno-attributes
FSTD = -std=f2003
CPEDANTIC += -pedantic -Wextra -Wno-variadic-macros
FPEDANTIC += -pedantic -Wextra -Wunused-variable \
-Wcharacter-truncation -Wline-truncation \
-Wconversion -Wintrinsics-std \
-Wimplicit-interface -Wimplicit-procedure
ifneq (0,$(shell echo "$$((40500<=$(FC_VERSION)))"))
CPEDANTIC += -Wshadow -Wno-overlength-strings
endif
ifneq (0,$(shell echo "$$((50000<=$(FC_VERSION)))"))
FWARNEXTRA = -Wuse-without-only -Wc-binding-type \
-Wrealloc-lhs -Wrealloc-lhs-all \
-Wreal-q-constant -Wconversion-extra
endif
ifeq (0,$(MINGW))
CPEDANTIC += -Wformat=2
else # MinGW
CXXFLAGS += -fno-asynchronous-unwind-tables
FCFLAGS += -fno-asynchronous-unwind-tables
CFLAGS += -fno-asynchronous-unwind-tables
ifneq (0,$(PEDANTIC))
ifneq (1,$(PEDANTIC))
CFLAGS += -Wno-format
endif
endif
endif
FPEDANTIC += $(FWARNEXTRA)
ifeq (1,$(PEDANTIC))
CSTD = -std=c99
CXXFLAGS += $(CPEDANTIC) -Wno-long-long
#CXXFLAGS += -Wno-missing-field-initializers
CFLAGS += $(CSTD) $(CPEDANTIC)
FCFLAGS += -ffree-form
FMFLAGS += $(FSTD) -pedantic -Wunused-variable $(FWARNEXTRA)
else ifneq (0,$(PEDANTIC))
ifneq (Darwin,$(UNAME))
CPEDANTIC += -Wno-long-long
CSTD = -std=c89
else ifneq (0,$(shell echo "$$((1<=$(GCC)))"))
CPEDANTIC += -Wno-long-long
CSTD = -std=c89
else # Clang may run into ICEs under OSX
CSTD = -std=c99
endif
CXXFLAGS += $(CPEDANTIC) -Wno-long-long #-Wzero-as-null-pointer-constant
#CXXFLAGS += -Wno-missing-field-initializers
CFLAGS += $(CSTD) $(CPEDANTIC)
FCFLAGS += $(FSTD) $(FPEDANTIC)
else ifeq (0,$(COMPATIBLE))
CPEDANTIC += -Wno-long-long #-Wno-missing-field-initializers
FCFLAGS += -ffree-form
CSTD = -std=c89
endif
# flag specifying output directory must be last
FMFLAGS += -J
else # fallback
FMFLAGS += -I
endif
CXXFLAGS += $(OPTFLAG)
CFLAGS += $(OPTFLAG)
FCFLAGS += $(OPTFLAG)
ifeq (0,$(DBG))
ifeq (0,$(COMPATIBLE))
CXXFLAGS += -funroll-loops
CFLAGS += -funroll-loops
FCFLAGS += -funroll-loops
endif
ifneq (0,$(IPO))
CXXFLAGS += -flto -ffat-lto-objects
CFLAGS += -flto -ffat-lto-objects
FCFLAGS += -flto -ffat-lto-objects
FLDFLAGS += -fno-lto
LDFLAGS += -flto
endif
ifneq (0,$(INSTRUMENT))
SYM = $(INSTRUMENT)
else ifeq (0,$(shell echo "$$((0>$(SYM)))"))
DFLAGS += -DNDEBUG
else
DFLAGS += -D_DEBUG
endif
else
ifneq (0,$(shell echo "$$((1<$(DBG) || 0>$(DBG)))"))
DFLAGS += -D_DEBUG
endif
SYM = $(DBG)
endif
ifneq (0,$(INSTRUMENT))
CXXFLAGS += -finstrument-functions
CFLAGS += -finstrument-functions
FCFLAGS += -finstrument-functions
# e.g. clang does not need/understand below flag
ifneq (0,$(shell echo "$$((40300<=$(GCC_VERSION)))"))
CFLAGS += -finstrument-functions-exclude-function-list=_mm_,_mm256_,_mm512_,__rdtsc
ifneq (0,$(shell echo "$$((2<=$(GCC)))"))
CXXFLAGS += -finstrument-functions-exclude-function-list=_mm_,_mm256_,_mm512_,__rdtsc
ifneq (0,$(shell echo "$$((3<=$(GCC)))"))
FCFLAGS += -finstrument-functions-exclude-function-list=_mm_,_mm256_,_mm512_,__rdtsc
endif
endif
endif
DFLAGS += -D__TRACE=$(INSTRUMENT)
endif
ifeq (Windows_NT,$(UNAME))
LDFLAGS += $(XLIB_BEGIN) -ldbghelp $(XLIB_END)
else ifeq (FreeBSD,$(UNAME))
LDFLAGS += $(XLIB_BEGIN) -lexecinfo $(XLIB_END)
endif
ifneq (0,$(SYM))
ifeq (1,$(SYM))
CXXFLAGS := -g $(CXXFLAGS)
CFLAGS := -g $(CFLAGS)
FCFLAGS := -g $(FCFLAGS)
else ifeq (2,$(SYM))
CXXFLAGS := -g $(CXXFLAGS) -fsanitize=thread -fno-omit-frame-pointer
CFLAGS := -g $(CFLAGS) -fsanitize=thread -fno-omit-frame-pointer
FCFLAGS := -g $(FCFLAGS) -fsanitize=thread -fno-omit-frame-pointer
LDFLAGS := -g $(LDFLAGS) -fsanitize=thread -ltsan -fno-omit-frame-pointer
#ELDFLAGS := -pie
else
CXXFLAGS := -g3 $(CXXFLAGS)
CFLAGS := -g3 $(CFLAGS)
FCFLAGS := -g $(FCFLAGS)
endif
endif
ifeq (0,$(COMPATIBLE))
ifneq (0,$(shell echo "$$((1<=$(GCC)))"))
OMPFLAG = -fopenmp
endif
endif
ifeq (,$(OMPFLAG))
ifneq (,$(filter environment% override command%,$(origin OMP)))
OMPFLAG = -fopenmp
endif
endif
# account for missing TLS/OMP
ifeq (,$(OMPFLAG))
THREADS ?= 0