Merge pull request #1656 from xianyi/develop
[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 ifeq ($(DYNAMIC_OLDER), 1)
157         @echo DYNAMIC_OLDER=1 >> Makefile.conf_last
158 endif   
159 endif
160 ifdef USE_THREAD
161         @echo USE_THREAD=$(USE_THREAD) >>  Makefile.conf_last
162 endif
163         @touch lib.grd
164
165 prof : prof_blas prof_lapack
166
167 prof_blas :
168         ln -fs $(LIBNAME_P) $(LIBPREFIX)_p.$(LIBSUFFIX)
169         for d in $(SUBDIRS) ; \
170         do if test -d $$d; then \
171           $(MAKE) -C $$d prof || exit 1 ; \
172         fi; \
173         done
174 ifeq ($(DYNAMIC_ARCH), 1)
175           $(MAKE) -C kernel commonprof || exit 1
176 endif
177
178 blas :
179         ln -fs $(LIBNAME) $(LIBPREFIX).$(LIBSUFFIX)
180         for d in $(BLASDIRS) ; \
181         do if test -d $$d; then \
182           $(MAKE) -C $$d libs || exit 1 ; \
183         fi; \
184         done
185
186 hpl :
187         ln -fs $(LIBNAME) $(LIBPREFIX).$(LIBSUFFIX)
188         for d in $(BLASDIRS) ../laswp exports ; \
189         do if test -d $$d; then \
190           $(MAKE) -C $$d $(@F) || exit 1 ; \
191         fi; \
192         done
193 ifeq ($(DYNAMIC_ARCH), 1)
194           $(MAKE) -C kernel commonlibs || exit 1
195         for d in $(DYNAMIC_CORE) ; \
196         do  $(MAKE) GOTOBLAS_MAKEFILE= -C kernel TARGET_CORE=$$d kernel || exit 1 ;\
197         done
198 endif
199
200 hpl_p :
201         ln -fs $(LIBNAME_P) $(LIBPREFIX)_p.$(LIBSUFFIX)
202         for d in $(SUBDIRS) ../laswp exports ; \
203         do if test -d $$d; then \
204           $(MAKE) -C $$d $(@F) || exit 1 ; \
205         fi; \
206         done
207
208 ifeq ($(NO_LAPACK), 1)
209 netlib :
210
211 else
212 netlib : lapack_prebuild
213 ifndef NOFORTRAN
214         @$(MAKE) -C $(NETLIB_LAPACK_DIR) lapacklib
215         @$(MAKE) -C $(NETLIB_LAPACK_DIR) tmglib
216 endif
217 ifndef NO_LAPACKE
218         @$(MAKE) -C $(NETLIB_LAPACK_DIR) lapackelib
219 endif
220 endif
221
222 ifeq ($(NO_LAPACK), 1)
223 re_lapack :
224
225 else
226 re_lapack :
227         @$(MAKE) -C relapack
228 endif
229
230 prof_lapack : lapack_prebuild
231         @$(MAKE) -C $(NETLIB_LAPACK_DIR) lapack_prof
232
233 lapack_prebuild :
234 ifndef NOFORTRAN
235         -@echo "FORTRAN     = $(FC)" > $(NETLIB_LAPACK_DIR)/make.inc
236         -@echo "OPTS        = $(LAPACK_FFLAGS)" >> $(NETLIB_LAPACK_DIR)/make.inc
237         -@echo "POPTS       = $(LAPACK_FPFLAGS)" >> $(NETLIB_LAPACK_DIR)/make.inc
238         -@echo "NOOPT       = -O0 $(LAPACK_NOOPT)" >> $(NETLIB_LAPACK_DIR)/make.inc
239         -@echo "PNOOPT      = $(LAPACK_FPFLAGS) -O0" >> $(NETLIB_LAPACK_DIR)/make.inc
240         -@echo "LOADOPTS    = $(FFLAGS) $(EXTRALIB)" >> $(NETLIB_LAPACK_DIR)/make.inc
241         -@echo "CC          = $(CC)" >> $(NETLIB_LAPACK_DIR)/make.inc
242         -@echo "override CFLAGS      = $(LAPACK_CFLAGS)" >> $(NETLIB_LAPACK_DIR)/make.inc
243         -@echo "ARCH        = $(AR)" >> $(NETLIB_LAPACK_DIR)/make.inc
244         -@echo "ARCHFLAGS   = $(ARFLAGS) -ru" >> $(NETLIB_LAPACK_DIR)/make.inc
245         -@echo "RANLIB      = $(RANLIB)" >> $(NETLIB_LAPACK_DIR)/make.inc
246         -@echo "LAPACKLIB   = ../$(LIBNAME)" >> $(NETLIB_LAPACK_DIR)/make.inc
247         -@echo "TMGLIB      = ../$(LIBNAME)" >> $(NETLIB_LAPACK_DIR)/make.inc
248         -@echo "BLASLIB     = ../../../$(LIBNAME)" >> $(NETLIB_LAPACK_DIR)/make.inc
249         -@echo "LAPACKELIB  = ../$(LIBNAME)" >> $(NETLIB_LAPACK_DIR)/make.inc
250         -@echo "LAPACKLIB_P = ../$(LIBNAME_P)" >> $(NETLIB_LAPACK_DIR)/make.inc
251         -@echo "SUFFIX      = $(SUFFIX)" >> $(NETLIB_LAPACK_DIR)/make.inc
252         -@echo "PSUFFIX     = $(PSUFFIX)" >> $(NETLIB_LAPACK_DIR)/make.inc
253         -@echo "CEXTRALIB   = $(EXTRALIB)" >> $(NETLIB_LAPACK_DIR)/make.inc
254 ifeq ($(F_COMPILER), GFORTRAN)
255         -@echo "TIMER       = INT_ETIME" >> $(NETLIB_LAPACK_DIR)/make.inc
256 ifdef SMP
257 ifeq ($(OSNAME), WINNT)
258         -@echo "LOADER      = $(FC)" >> $(NETLIB_LAPACK_DIR)/make.inc
259 else
260         -@echo "LOADER      = $(FC) -pthread" >> $(NETLIB_LAPACK_DIR)/make.inc
261 endif
262 else
263         -@echo "LOADER      = $(FC)" >> $(NETLIB_LAPACK_DIR)/make.inc
264 endif
265 else
266         -@echo "TIMER       = NONE" >> $(NETLIB_LAPACK_DIR)/make.inc
267         -@echo "LOADER      = $(FC)" >> $(NETLIB_LAPACK_DIR)/make.inc
268 endif
269 ifeq ($(BUILD_LAPACK_DEPRECATED), 1)
270         -@echo "BUILD_DEPRECATED      = 1" >> $(NETLIB_LAPACK_DIR)/make.inc
271 endif
272         -@echo "LAPACKE_WITH_TMG      = 1" >> $(NETLIB_LAPACK_DIR)/make.inc
273         -@cat  make.inc >> $(NETLIB_LAPACK_DIR)/make.inc
274 endif
275
276 large.tgz :
277 ifndef NOFORTRAN
278         if [ ! -a $< ]; then
279         -wget http://www.netlib.org/lapack/timing/large.tgz;
280         fi
281 endif
282
283 timing.tgz :
284 ifndef NOFORTRAN
285         if [ ! -a $< ]; then
286         -wget http://www.netlib.org/lapack/timing/timing.tgz;
287         fi
288 endif
289
290 lapack-timing : large.tgz timing.tgz
291 ifndef NOFORTRAN
292         (cd $(NETLIB_LAPACK_DIR); $(TAR) zxf ../timing.tgz TIMING)
293         (cd $(NETLIB_LAPACK_DIR)/TIMING; $(TAR) zxf ../../large.tgz )
294         $(MAKE) -C $(NETLIB_LAPACK_DIR)/TIMING
295 endif
296
297
298 lapack-test :
299         (cd $(NETLIB_LAPACK_DIR)/TESTING && rm -f x* *.out)
300         $(MAKE) -j 1 -C $(NETLIB_LAPACK_DIR)/TESTING/EIG xeigtstc  xeigtstd  xeigtsts  xeigtstz 
301         $(MAKE) -j 1 -C $(NETLIB_LAPACK_DIR)/TESTING/LIN xlintstc  xlintstd  xlintstds  xlintstrfd  xlintstrfz  xlintsts  xlintstz  xlintstzc xlintstrfs xlintstrfc
302 ifneq ($(CROSS), 1)
303         ( cd $(NETLIB_LAPACK_DIR)/INSTALL; make all; ./testlsame; ./testslamch; ./testdlamch; \
304         ./testsecond; ./testdsecnd; ./testieee; ./testversion )
305         (cd $(NETLIB_LAPACK_DIR); ./lapack_testing.py -r )
306 endif
307
308 lapack-runtest:
309         ( cd $(NETLIB_LAPACK_DIR)/INSTALL; ./testlsame; ./testslamch; ./testdlamch; \
310         ./testsecond; ./testdsecnd; ./testieee; ./testversion )
311         (cd $(NETLIB_LAPACK_DIR); ./lapack_testing.py -r )
312
313
314 blas-test:
315         (cd $(NETLIB_LAPACK_DIR)/BLAS/TESTING && rm -f x* *.out)
316         $(MAKE) -j 1 -C $(NETLIB_LAPACK_DIR) blas_testing
317         (cd $(NETLIB_LAPACK_DIR)/BLAS/TESTING && cat *.out)
318
319
320 dummy :
321
322 install :
323         $(MAKE) -f Makefile.install install
324
325 clean ::
326         @for d in $(SUBDIRS_ALL) ; \
327         do if test -d $$d; then \
328           $(MAKE) -C $$d $(@F) || exit 1 ; \
329         fi; \
330         done
331 #ifdef DYNAMIC_ARCH
332         @$(MAKE) -C kernel clean
333 #endif
334         @$(MAKE) -C reference clean
335         @rm -f *.$(LIBSUFFIX) *.so *~ *.exe getarch getarch_2nd *.dll *.lib *.$(SUFFIX) *.dwf $(LIBPREFIX).$(LIBSUFFIX) $(LIBPREFIX)_p.$(LIBSUFFIX) $(LIBPREFIX).so.$(MAJOR_VERSION) *.lnk myconfig.h
336 ifeq ($(OSNAME), Darwin)
337         @rm -rf getarch.dSYM getarch_2nd.dSYM
338 endif
339         @rm -f Makefile.conf config.h Makefile_kernel.conf config_kernel.h st* *.dylib
340         @touch $(NETLIB_LAPACK_DIR)/make.inc
341         @$(MAKE) -C $(NETLIB_LAPACK_DIR) clean
342         @rm -f $(NETLIB_LAPACK_DIR)/make.inc $(NETLIB_LAPACK_DIR)/lapacke/include/lapacke_mangling.h
343         @$(MAKE) -C relapack clean
344         @rm -f *.grd Makefile.conf_last config_last.h
345         @(cd $(NETLIB_LAPACK_DIR)/TESTING && rm -f x* *.out testing_results.txt)
346         @echo Done.