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