Merge pull request #1594 from martin-frbg/issue1593
[platform/upstream/openblas.git] / Makefile
1 TOPDIR  = .
2 include ./Makefile.system
3
4 BLASDIRS = interface driver/level2 driver/level3 driver/others
5
6 ifneq ($(DYNAMIC_ARCH), 1)
7 BLASDIRS += kernel
8 endif
9
10 ifdef SANITY_CHECK
11 BLASDIRS += reference
12 endif
13
14 SUBDIRS = $(BLASDIRS)
15 ifneq ($(NO_LAPACK), 1)
16 SUBDIRS += lapack
17 endif
18
19 RELA =
20 ifeq ($(BUILD_RELAPACK), 1)
21 RELA = re_lapack
22 endif
23
24 LAPACK_NOOPT := $(filter-out -O0 -O1 -O2 -O3 -Ofast,$(LAPACK_FFLAGS))
25
26 SUBDIRS_ALL = $(SUBDIRS) test ctest utest exports benchmark ../laswp ../bench
27
28 .PHONY : all libs netlib $(RELA) test ctest shared install
29 .NOTPARALLEL : all libs $(RELA) prof lapack-test install blas-test
30
31 all :: libs netlib $(RELA) tests shared
32         @echo
33         @echo " OpenBLAS build complete. ($(LIB_COMPONENTS))"
34         @echo
35         @echo "  OS               ... $(OSNAME)             "
36         @echo "  Architecture     ... $(ARCH)               "
37 ifndef BINARY64
38         @echo "  BINARY           ... 32bit                 "
39 else
40         @echo "  BINARY           ... 64bit                 "
41 endif
42
43 ifdef INTERFACE64
44 ifneq ($(INTERFACE64), 0)
45         @echo "  Use 64 bits int    (equivalent to \"-i8\" in Fortran)      "
46 endif
47 endif
48
49         @echo "  C compiler       ... $(C_COMPILER)  (command line : $(CC))"
50 ifndef NOFORTRAN
51         @echo "  Fortran compiler ... $(F_COMPILER)  (command line : $(FC))"
52 endif
53 ifneq ($(OSNAME), AIX)
54         @echo -n "  Library Name     ... $(LIBNAME)"
55 else
56         @echo "  Library Name     ... $(LIBNAME)"
57 endif
58
59 ifndef SMP
60         @echo " (Single threaded)  "
61 else
62         @echo " (Multi threaded; Max num-threads is $(NUM_THREADS))"
63 endif
64
65 ifeq ($(USE_OPENMP), 1)
66         @echo
67         @echo " Use OpenMP in the multithreading. Because of ignoring OPENBLAS_NUM_THREADS and GOTO_NUM_THREADS flags, "
68         @echo " you should use OMP_NUM_THREADS environment variable to control the number of threads."
69         @echo
70 endif
71
72 ifeq ($(OSNAME), Darwin)
73         @echo "WARNING: If you plan to use the dynamic library $(LIBDYNNAME), you must run:"
74         @echo
75         @echo "\"make PREFIX=/your_installation_path/ install\"."
76         @echo
77         @echo "(or set PREFIX in Makefile.rule and run make install."
78         @echo "If you want to move the .dylib to a new location later, make sure you change"
79         @echo "the internal name of the dylib with:"
80         @echo
81         @echo "install_name_tool -id /new/absolute/path/to/$(LIBDYNNAME) $(LIBDYNNAME)"
82 endif
83         @echo
84         @echo "To install the library, you can run \"make PREFIX=/path/to/your/installation install\"."
85         @echo
86
87 shared :
88 ifndef NO_SHARED
89 ifeq ($(OSNAME), $(filter $(OSNAME),Linux SunOS Android))
90         @$(MAKE) -C exports so
91         @ln -fs $(LIBSONAME) $(LIBPREFIX).so
92         @ln -fs $(LIBSONAME) $(LIBPREFIX).so.$(MAJOR_VERSION)
93 endif
94 ifeq ($(OSNAME), $(filter $(OSNAME),FreeBSD OpenBSD NetBSD DragonFly))
95         @$(MAKE) -C exports so
96         @ln -fs $(LIBSONAME) $(LIBPREFIX).so
97 endif
98 ifeq ($(OSNAME), Darwin)
99         @$(MAKE) -C exports dyn
100         @ln -fs $(LIBDYNNAME) $(LIBPREFIX).dylib
101 endif
102 ifeq ($(OSNAME), WINNT)
103         @$(MAKE) -C exports dll
104 endif
105 ifeq ($(OSNAME), CYGWIN_NT)
106         @$(MAKE) -C exports dll
107 endif
108 endif
109
110 tests :
111 ifndef NOFORTRAN
112         touch $(LIBNAME)
113 ifndef NO_FBLAS
114         $(MAKE) -C test all
115         $(MAKE) -C utest all
116 endif
117 ifndef NO_CBLAS
118         $(MAKE) -C ctest all
119 endif
120 endif
121
122 libs :
123 ifeq ($(CORE), UNKOWN)
124         $(error OpenBLAS: Detecting CPU failed. Please set TARGET explicitly, e.g. make TARGET=your_cpu_target. Please read README for the detail.)
125 endif
126 ifeq ($(NOFORTRAN), 1)
127         $(info OpenBLAS: Detecting fortran compiler failed. Cannot compile LAPACK. Only compile BLAS.)
128 endif
129 ifeq ($(NO_STATIC), 1)
130 ifeq ($(NO_SHARED), 1)
131         $(error OpenBLAS: neither static nor shared are enabled.)
132 endif
133 endif
134         @-ln -fs $(LIBNAME) $(LIBPREFIX).$(LIBSUFFIX)
135         @for d in $(SUBDIRS) ; \
136         do if test -d $$d; then \
137           $(MAKE) -C $$d $(@F) || exit 1 ; \
138         fi; \
139         done
140 #Save the config files for installation
141         @cp Makefile.conf Makefile.conf_last
142         @cp config.h config_last.h
143 ifdef QUAD_PRECISION
144         @echo "#define QUAD_PRECISION">> config_last.h
145 endif
146 ifeq ($(EXPRECISION), 1)
147         @echo "#define EXPRECISION">> config_last.h
148 endif
149 ##
150 ifeq ($(DYNAMIC_ARCH), 1)
151         @$(MAKE) -C kernel commonlibs || exit 1
152         @for d in $(DYNAMIC_CORE) ; \
153         do  $(MAKE) GOTOBLAS_MAKEFILE= -C kernel TARGET_CORE=$$d kernel || exit 1 ;\
154         done
155         @echo DYNAMIC_ARCH=1 >> Makefile.conf_last
156 endif
157 ifdef USE_THREAD
158         @echo USE_THREAD=$(USE_THREAD) >>  Makefile.conf_last
159 endif
160         @touch lib.grd
161
162 prof : prof_blas prof_lapack
163
164 prof_blas :
165         ln -fs $(LIBNAME_P) $(LIBPREFIX)_p.$(LIBSUFFIX)
166         for d in $(SUBDIRS) ; \
167         do if test -d $$d; then \
168           $(MAKE) -C $$d prof || exit 1 ; \
169         fi; \
170         done
171 ifeq ($(DYNAMIC_ARCH), 1)
172           $(MAKE) -C kernel commonprof || exit 1
173 endif
174
175 blas :
176         ln -fs $(LIBNAME) $(LIBPREFIX).$(LIBSUFFIX)
177         for d in $(BLASDIRS) ; \
178         do if test -d $$d; then \
179           $(MAKE) -C $$d libs || exit 1 ; \
180         fi; \
181         done
182
183 hpl :
184         ln -fs $(LIBNAME) $(LIBPREFIX).$(LIBSUFFIX)
185         for d in $(BLASDIRS) ../laswp exports ; \
186         do if test -d $$d; then \
187           $(MAKE) -C $$d $(@F) || exit 1 ; \
188         fi; \
189         done
190 ifeq ($(DYNAMIC_ARCH), 1)
191           $(MAKE) -C kernel commonlibs || exit 1
192         for d in $(DYNAMIC_CORE) ; \
193         do  $(MAKE) GOTOBLAS_MAKEFILE= -C kernel TARGET_CORE=$$d kernel || exit 1 ;\
194         done
195 endif
196
197 hpl_p :
198         ln -fs $(LIBNAME_P) $(LIBPREFIX)_p.$(LIBSUFFIX)
199         for d in $(SUBDIRS) ../laswp exports ; \
200         do if test -d $$d; then \
201           $(MAKE) -C $$d $(@F) || exit 1 ; \
202         fi; \
203         done
204
205 ifeq ($(NO_LAPACK), 1)
206 netlib :
207
208 else
209 netlib : lapack_prebuild
210 ifndef NOFORTRAN
211         @$(MAKE) -C $(NETLIB_LAPACK_DIR) lapacklib
212         @$(MAKE) -C $(NETLIB_LAPACK_DIR) tmglib
213 endif
214 ifndef NO_LAPACKE
215         @$(MAKE) -C $(NETLIB_LAPACK_DIR) lapackelib
216 endif
217 endif
218
219 ifeq ($(NO_LAPACK), 1)
220 re_lapack :
221
222 else
223 re_lapack :
224         @$(MAKE) -C relapack
225 endif
226
227 prof_lapack : lapack_prebuild
228         @$(MAKE) -C $(NETLIB_LAPACK_DIR) lapack_prof
229
230 lapack_prebuild :
231 ifndef NOFORTRAN
232         -@echo "FORTRAN     = $(FC)" > $(NETLIB_LAPACK_DIR)/make.inc
233         -@echo "OPTS        = $(LAPACK_FFLAGS)" >> $(NETLIB_LAPACK_DIR)/make.inc
234         -@echo "POPTS       = $(LAPACK_FPFLAGS)" >> $(NETLIB_LAPACK_DIR)/make.inc
235         -@echo "NOOPT       = -O0 $(LAPACK_NOOPT)" >> $(NETLIB_LAPACK_DIR)/make.inc
236         -@echo "PNOOPT      = $(LAPACK_FPFLAGS) -O0" >> $(NETLIB_LAPACK_DIR)/make.inc
237         -@echo "LOADOPTS    = $(FFLAGS) $(EXTRALIB)" >> $(NETLIB_LAPACK_DIR)/make.inc
238         -@echo "CC          = $(CC)" >> $(NETLIB_LAPACK_DIR)/make.inc
239         -@echo "override CFLAGS      = $(LAPACK_CFLAGS)" >> $(NETLIB_LAPACK_DIR)/make.inc
240         -@echo "ARCH        = $(AR)" >> $(NETLIB_LAPACK_DIR)/make.inc
241         -@echo "ARCHFLAGS   = $(ARFLAGS) -ru" >> $(NETLIB_LAPACK_DIR)/make.inc
242         -@echo "RANLIB      = $(RANLIB)" >> $(NETLIB_LAPACK_DIR)/make.inc
243         -@echo "LAPACKLIB   = ../$(LIBNAME)" >> $(NETLIB_LAPACK_DIR)/make.inc
244         -@echo "TMGLIB      = ../$(LIBNAME)" >> $(NETLIB_LAPACK_DIR)/make.inc
245         -@echo "BLASLIB     = ../../../$(LIBNAME)" >> $(NETLIB_LAPACK_DIR)/make.inc
246         -@echo "LAPACKELIB  = ../$(LIBNAME)" >> $(NETLIB_LAPACK_DIR)/make.inc
247         -@echo "LAPACKLIB_P = ../$(LIBNAME_P)" >> $(NETLIB_LAPACK_DIR)/make.inc
248         -@echo "SUFFIX      = $(SUFFIX)" >> $(NETLIB_LAPACK_DIR)/make.inc
249         -@echo "PSUFFIX     = $(PSUFFIX)" >> $(NETLIB_LAPACK_DIR)/make.inc
250         -@echo "CEXTRALIB   = $(EXTRALIB)" >> $(NETLIB_LAPACK_DIR)/make.inc
251 ifeq ($(F_COMPILER), GFORTRAN)
252         -@echo "TIMER       = INT_ETIME" >> $(NETLIB_LAPACK_DIR)/make.inc
253 ifdef SMP
254 ifeq ($(OSNAME), WINNT)
255         -@echo "LOADER      = $(FC)" >> $(NETLIB_LAPACK_DIR)/make.inc
256 else
257         -@echo "LOADER      = $(FC) -pthread" >> $(NETLIB_LAPACK_DIR)/make.inc
258 endif
259 else
260         -@echo "LOADER      = $(FC)" >> $(NETLIB_LAPACK_DIR)/make.inc
261 endif
262 else
263         -@echo "TIMER       = NONE" >> $(NETLIB_LAPACK_DIR)/make.inc
264         -@echo "LOADER      = $(FC)" >> $(NETLIB_LAPACK_DIR)/make.inc
265 endif
266 ifeq ($(BUILD_LAPACK_DEPRECATED), 1)
267         -@echo "BUILD_DEPRECATED      = 1" >> $(NETLIB_LAPACK_DIR)/make.inc
268 endif
269         -@echo "LAPACKE_WITH_TMG      = 1" >> $(NETLIB_LAPACK_DIR)/make.inc
270         -@cat  make.inc >> $(NETLIB_LAPACK_DIR)/make.inc
271 endif
272
273 large.tgz :
274 ifndef NOFORTRAN
275         if [ ! -a $< ]; then
276         -wget http://www.netlib.org/lapack/timing/large.tgz;
277         fi
278 endif
279
280 timing.tgz :
281 ifndef NOFORTRAN
282         if [ ! -a $< ]; then
283         -wget http://www.netlib.org/lapack/timing/timing.tgz;
284         fi
285 endif
286
287 lapack-timing : large.tgz timing.tgz
288 ifndef NOFORTRAN
289         (cd $(NETLIB_LAPACK_DIR); $(TAR) zxf ../timing.tgz TIMING)
290         (cd $(NETLIB_LAPACK_DIR)/TIMING; $(TAR) zxf ../../large.tgz )
291         $(MAKE) -C $(NETLIB_LAPACK_DIR)/TIMING
292 endif
293
294
295 lapack-test :
296         (cd $(NETLIB_LAPACK_DIR)/TESTING && rm -f x* *.out)
297         $(MAKE) -j 1 -C $(NETLIB_LAPACK_DIR)/TESTING/EIG xeigtstc  xeigtstd  xeigtsts  xeigtstz 
298         $(MAKE) -j 1 -C $(NETLIB_LAPACK_DIR)/TESTING/LIN xlintstc  xlintstd  xlintstds  xlintstrfd  xlintstrfz  xlintsts  xlintstz  xlintstzc xlintstrfs xlintstrfc
299 ifneq ($(CROSS), 1)
300         ( cd $(NETLIB_LAPACK_DIR)/INSTALL; make all; ./testlsame; ./testslamch; ./testdlamch; \
301         ./testsecond; ./testdsecnd; ./testieee; ./testversion )
302         (cd $(NETLIB_LAPACK_DIR); ./lapack_testing.py -r )
303 endif
304
305 lapack-runtest:
306         ( cd $(NETLIB_LAPACK_DIR)/INSTALL; ./testlsame; ./testslamch; ./testdlamch; \
307         ./testsecond; ./testdsecnd; ./testieee; ./testversion )
308         (cd $(NETLIB_LAPACK_DIR); ./lapack_testing.py -r )
309
310
311 blas-test:
312         (cd $(NETLIB_LAPACK_DIR)/BLAS/TESTING && rm -f x* *.out)
313         $(MAKE) -j 1 -C $(NETLIB_LAPACK_DIR) blas_testing
314         (cd $(NETLIB_LAPACK_DIR)/BLAS/TESTING && cat *.out)
315
316
317 dummy :
318
319 install :
320         $(MAKE) -f Makefile.install install
321
322 clean ::
323         @for d in $(SUBDIRS_ALL) ; \
324         do if test -d $$d; then \
325           $(MAKE) -C $$d $(@F) || exit 1 ; \
326         fi; \
327         done
328 #ifdef DYNAMIC_ARCH
329         @$(MAKE) -C kernel clean
330 #endif
331         @$(MAKE) -C reference clean
332         @rm -f *.$(LIBSUFFIX) *.so *~ *.exe getarch getarch_2nd *.dll *.lib *.$(SUFFIX) *.dwf $(LIBPREFIX).$(LIBSUFFIX) $(LIBPREFIX)_p.$(LIBSUFFIX) $(LIBPREFIX).so.$(MAJOR_VERSION) *.lnk myconfig.h
333 ifeq ($(OSNAME), Darwin)
334         @rm -rf getarch.dSYM getarch_2nd.dSYM
335 endif
336         @rm -f Makefile.conf config.h Makefile_kernel.conf config_kernel.h st* *.dylib
337         @touch $(NETLIB_LAPACK_DIR)/make.inc
338         @$(MAKE) -C $(NETLIB_LAPACK_DIR) clean
339         @rm -f $(NETLIB_LAPACK_DIR)/make.inc $(NETLIB_LAPACK_DIR)/lapacke/include/lapacke_mangling.h
340         @$(MAKE) -C relapack clean
341         @rm -f *.grd Makefile.conf_last config_last.h
342         @(cd $(NETLIB_LAPACK_DIR)/TESTING && rm -f x* *.out testing_results.txt)
343         @echo Done.