[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: building an ATLAS .so



Greetings!  You can check out the Debian atlas package if you'd like.
This builds shared libs, all atlas libs, and optimized blas and lapack
libs.  

Here is the debian/rules Makefile that governs the atlas build for the
Debian package:

=============================================================================
#!/usr/bin/make -f
#-*- makefile -*-
# Made with the aid of dh_make, by Craig Small
# Sample debian/rules that uses debhelper. GNU copyright 1997 by Joey Hess.
# This version is for a hypothetical package that builds an
# architecture-dependant package, as well as an architecture-independant
# package.

package=atlas

version=$(shell expr `pwd` : '.*-\([0-9.]*\)')
version_major=$(shell expr `pwd` : '.*-\([0-9]*\).[0-9.]*')

SO=2
MIN=3
VER=$(SO).$(MIN)

# Uncomment this to turn on verbose mode. 
#export DH_VERBOSE=1

# This is the debhelper compatability version to use.
export DH_COMPAT=1

ARCHT:=$(shell echo $$(dpkg --print-architecture))
DTR:=$(shell echo $$(pwd)/debian/test/test_results.$(ARCHT))

ELIBS:=atlas f77blas cblas lapack_atlas
TPROGS:=xsl3blastst xdl3blastst xcl3blastst xzl3blastst xsl2blastst xdl2blastst xcl2blastst xzl2blastst xslutst xdlutst xclutst xzlutst xsllttst xdllttst xcllttst xzllttst xslutstF xdlutstF xclutstF xzlutstF xsllttstF xdllttstF xcllttstF xzllttstF
FPROGS:=xsblat1 xdblat1 xcblat1 xzblat1 xsblat2 xdblat2 xcblat2 xzblat2 xsblat3 xdblat3 xcblat3 xzblat3
CPROGS:=xscblat1 xdcblat1 xccblat1 xzcblat1 xscblat2 xdcblat2 xccblat2 xzcblat2 xscblat3 xdcblat3 xccblat3 xzcblat3
HEADERS=cblas.h atlas_misc.h atlas_enum.h


#
# until g77 can compile complex abs1()
#
AF77:=$(shell echo `pwd`/debian/a.f77)
ifeq ($(ARCHT),alpha)
MF77:=$(AF77)
MF90OPTS:=
else
MF77:=$(F77)
MF90OPTS:=-ff90
endif


blas: blas-stamp 
blas-stamp: 

	dh_testdir

	apt-get source blas
	set -e;\
	cd blas* ; \
	debian/rules build;\
	i=$$(ls -1 libblas.so.[0123456789]*[.0123456789]*);\
	j=$$(echo $$i | sed 's,\(\.so\.[0123456789]*\)[.0123456789]*$$,\1,1');\
	ln -snf $$i $$j;\
	ln -snf $$j libblas.so

	touch blas-stamp

lapack: blas-stamp lapack-stamp
lapack-stamp: blas-stamp


	dh_testdir

	apt-get source lapack
	(set -e ;\
		chmod +x $(AF77);\
		cd lapack* ; \
		if [ -d SRC/sho ] ; then cp -p SRC/sho/*.o SRC ; fi ;\
		$(MAKE) lapacklib LIBTYPE=shared FORTRAN=$(MF77) F90OPTS=$(MF90OPTS);\
		if ! [ -d SRC/sho ] ; then mkdir SRC/sho ; fi ;\
		cp -p SRC/*.o SRC/sho ;\
		$(MAKE) clean;\
		if [ -d SRC/sto ] ; then cp -p SRC/sto/*.o SRC ; fi;\
		$(MAKE) lapacklib LIBTYPE=static FORTRAN=$(MF77) F90OPTS=$(MF90OPTS);\
		if ! [ -d SRC/sto ] ; then mkdir SRC/sto ; fi ;\
		cp -p SRC/*.o SRC/sto;\
	)

	touch lapack-stamp


startup: lapack-stamp startup-stamp
startup-stamp: lapack-stamp
	dh_testdir

	chmod +x debian/config.expect
	debian/config.expect
	cat Make.Linux | sed -e "s, TOPdir = \(.*\), TOPdir = $$(pwd),1" -e "s, FLAPACKlib = , FLAPACKlib = $$(find `pwd`/lapack* -name liblapack.a),1" >foo
	mv foo Make.Linux
	cat Make.Linux | sed \
		-e 's, F77FLAGS = \(.*\), F77FLAGS = \1 -fPIC,1' \
		-e 's, CCFLAGS = \(.*\), CCFLAGS = \1 -fPIC,1' \
		-e 's, MMFLAGS = \(.*\), MMFLAGS = \1 -fPIC,1' \
		-e 's, XCCFLAGS = \(.*\), XCCFLAGS = \1 -fPIC,1' \
                -e "s, ARCH = Linux, ARCH = Linux_fpic,1" \
		> Make.Linux_fpic
	-make killall arch=Linux
	-make killall arch=Linux_fpic
	make startup arch=Linux
	ln -s ATLrun.Linux CONFIG/ATLrun.Linux_fpic
	make startup arch=Linux_fpic

	if [ "$(ARCHT)" = "alpha" ] ; then\
		set -e;\
		for i in Linux Linux_fpic; do\
			cd tune/blas/gemm/$$i;\
			cat Makefile  | awk '/^mmsearch.o / {i=1;print;next} {if (i) {printf("\t$$(XCC) $$(OJ) $$$$(echo $$(XCCFLAGS) | sed '\''s,\-O[23456] ,-g ,1'\'') ../mmsearch.c\n");i=0} else print}' >foo;\
			mv foo Makefile;\
			cd ../../../..;\
			cd bin/$$i;\
			cat Makefile | awk '/^.l2blastst\.o / {i=1;print;next} {if (i==1) {i=2;print;next} if (i) {printf("\t%s %s %s %s $$$$(echo %s | sed '\''s,\-O[23456] ,-g ,1'\'') %s %s\n",$$1,$$2,$$3,$$4,$$5,$$6,$$7);i=0} else print}' >foo;\
			mv foo Makefile;\
			cd ../..;\
			cat Make.$$i | sed \
				-e 's, F77FLAGS = \(.*\), F77FLAGS = \1 -DWALL,1' \
				-e 's, CCFLAGS = \(.*\), CCFLAGS = \1 -DWALL,1' \
				-e 's, MMFLAGS = \(.*\), MMFLAGS = \1 -DWALL,1' \
				-e 's, XCCFLAGS = \(.*\), XCCFLAGS = \1 -DWALL,1' \
				>foo;\
			mv foo Make.$$i;\
		done;\
	fi
	touch startup-stamp


build: startup-stamp build-stamp
build-stamp: startup-stamp
	dh_testdir

	if [ -f lib/Linux_fpic/liblapack_atlas.a ] ; then mv lib/Linux_fpic/liblapack_atlas.a lib/Linux_fpic/liblapack.a ; fi
	if [ -f lib/Linux/liblapack_atlas.a ] ; then mv lib/Linux/liblapack_atlas.a lib/Linux/liblapack.a ; fi

	make install arch=Linux
	make install arch=Linux_fpic

	if [ -f lib/Linux_fpic/liblapack.a ] ; then mv lib/Linux_fpic/liblapack.a lib/Linux_fpic/liblapack_atlas.a ; fi
	if [ -f lib/Linux/liblapack.a ] ; then mv lib/Linux/liblapack.a lib/Linux/liblapack_atlas.a ; fi

	mkdir tmp;\
	cd tmp;\
	ar x ../lib/Linux_fpic/libatlas.a;\
	ar x ../lib/Linux_fpic/libf77blas.a;\
	cc -shared -Wl,-soname=libblas.so.$(SO) -o ../lib/Linux_fpic/libblas.so.$(VER) *.o;\
	cd ..;\
	rm -fr tmp;

	mkdir tmp;\
	cd tmp;\
	cp ../lapack*/SRC/sho/*.o . ;\
	ar x ../lib/Linux_fpic/liblapack_atlas.a;\
	ar x ../lib/Linux_fpic/libcblas.a;\
	cc -shared -Wl,-soname=liblapack.so.$(SO) -o ../lib/Linux_fpic/liblapack.so.$(VER) *.o;\
	cd ..;\
	rm -fr tmp;

	mkdir tmp;\
	cd tmp;\
	ar x ../lib/Linux/libatlas.a;\
	ar x ../lib/Linux/libf77blas.a;\
	rm -f ../lib/Linux/libblas.a;\
	ar r ../lib/Linux/libblas.a *.o ;\
	cd ..;\
	rm -fr tmp;

	mkdir tmp;\
	cd tmp;\
	ar x ../lapack*/liblapack.a;\
	ar x ../lib/Linux/liblapack_atlas.a;\
	ar x ../lib/Linux/libcblas.a;\
	rm -f ../lib/Linux/liblapack.a;\
	ar r ../lib/Linux/liblapack.a *.o ;\
	cd ..;\
	rm -fr tmp;

	set -e;\
	for i in $(ELIBS) ; do \
		mkdir tmp;\
		cd tmp;\
		ar x ../lib/Linux_fpic/lib$${i}.a;\
		rm -f ilaenv.o;\
		cc -shared -Wl,-soname=lib$${i}.so.$(SO) -o ../lib/Linux_fpic/lib$${i}.so.$(VER) *.o;\
		ln -snf lib$${i}.so.$(VER) ../lib/Linux_fpic/lib$${i}.so.$(SO);\
		ln -snf lib$${i}.so.$(SO) ../lib/Linux_fpic/lib$${i}.so;\
		cd ..;\
		rm -fr tmp;\
	done

	cd bin/Linux_fpic;\
	set -e;\
	ln -snf liblapack_atlas.a ../../lib/Linux_fpic/liblapack.a;\
	for i in $(TPROGS) ; do \
		echo $${i};\
		j=$$(make $${i} | \
			awk '/\-o '$${i}'/ {i=1} \
			/make\[/ {i=0} \
			{if (i) a=a " " $$0} END {print a}' | \
			sed -e 's,\\ *,,g' \
			    -e "s,[^ ]*libatlas.a.*libatlas.a,-L ../../lib/Linux_fpic/ -latlas,g" \
			    -e "s,[^ ]*libblas.a,-L $$(dirname $$(cat ../../Make.Linux | grep ' BLASlib =' | awk '{print $$3}')) -lblas,g" \
			    -e "s,[^ ]*libf77blas.a,-L ../../lib/Linux_fpic -lf77blas,g" \
			    -e "s,[^ ]*libcblas.a,-L ../../lib/Linux_fpic -lcblas,g" \
			    -e "s,[^ ]*/Linux_fpic/liblapack.a,-L ../../lib/Linux_fpic -llapack_atlas -lf77blas,g" \
			    -e "s,[^ ]*lapack-[^ /]*/liblapack.a,-L $$(dirname $$(cat ../../Make.Linux | grep ' FLAPACKlib =' | awk '{print $$3}')) -llapack,g" \
			    -e "s,[^ ]*libatlas.a,-L ../../lib/Linux_fpic -latlas,g") ;\
		echo Relinking ... $${j};\
		( eval $$j );\
	done; \
	rm -f lib/Linux_fpic/liblapack.a

	cd interfaces/blas/F77/testing/Linux_fpic;\
	set -e;\
	chmod +x $(AF77);\
	for i in $(FPROGS) ; do \
		echo $${i};\
		j=$$(make $${i} F77=$(MF77)| \
			awk '/\-o '$${i}'/ {i=1} \
			/make\[/ {i=0} \
			{if (i) a=a " " $$0} END {print a}' | \
			sed -e 's,\\ *,,g' \
			    -e "s,[^ ]*libatlas.a.*libatlas.a,-L ../../../../../lib/Linux_fpic/ -latlas,g" \
			    -e "s,[^ ]*libf77blas.a,-L ../../../../../lib/Linux_fpic -lf77blas,g" \
			    -e "s,[^ ]*libcblas.a,-L ../../../../../lib/Linux_fpic -lcblas,g" \
			    -e "s,[^ ]*liblapack.a,-L ../../../../../lib/Linux_fpic -llapack_atlas -lf77blas,g" \
			    -e "s,[^ ]*libatlas.a,-L ../../../../../lib/Linux_fpic -latlas,g") ;\
		echo Relinking ... $${j};\
		( eval $$j );\
	done; 

	cd interfaces/blas/C/testing/Linux_fpic;\
	set -e;\
	chmod +x $(AF77);\
	for i in $(CPROGS) ; do \
		echo $${i};\
		j=$$(make $${i} F77=$(MF77) | \
			awk '/\-o '$${i}'/ {i=1} \
			/make\[/ {i=0} \
			{if (i) a=a " " $$0} END {print a}' | \
			sed -e 's,\\ *,,g' \
			    -e "s,[^ ]*libatlas.a.*libatlas.a,-L ../../../../../lib/Linux_fpic/ -latlas,g" \
			    -e "s,[^ ]*libf77blas.a,-L ../../../../../lib/Linux_fpic -lf77blas,g" \
			    -e "s,[^ ]*libcblas.a,-L ../../../../../lib/Linux_fpic -lcblas,g" \
			    -e "s,[^ ]*liblapack.a,-L ../../../../../lib/Linux_fpic -llapack_atlas -lf77blas,g" \
			    -e "s,[^ ]*libatlas.a,-L ../../../../../lib/Linux_fpic -latlas,g") ;\
		echo Relinking ... $${j};\
		( eval $$j );\
	done; 

	touch build-stamp


test: build-stamp test-stamp
test-stamp: build-stamp

	rm -rf $$(dirname $(DTR))
	mkdir -p $$(dirname $(DTR))
	echo "These atlas libraries were built on the following machine:" >$(DTR)
	cat /proc/cpuinfo >>$(DTR)
	( set -e; \
	cd interfaces/blas/F77/testing/Linux_fpic;\
	export LD_LIBRARY_PATH=../../../../../lib/Linux_fpic ;\
	for i in s d c z ; do \
		for j in 2 3 ; do \
			echo "Now testing ./x$${i}blat$${j} < ../$${i}blat$${j}.dat";\
			./x$${i}blat$${j} < ../$${i}blat$${j}.dat ;\
		done;\
		echo "Now testing ./x$${i}blat1";\
		./x$${i}blat1 ;\
	done; \
	echo "TEST1 DONE";\
	) | tee --append $(DTR)
	grep "TEST1 DONE" $(DTR) >/dev/null
	( set -e; \
	cd interfaces/blas/C/testing/Linux_fpic;\
	export LD_LIBRARY_PATH=../../../../../lib/Linux_fpic ;\
	for i in s d c z ; do \
		for j in 2 3 ; do \
			echo "Now testing ./x$${i}cblat$${j} < ../c_$${i}blat$${j}.dat" ;\
			./x$${i}cblat$${j} < ../c_$${i}blat$${j}.dat;\
		done;\
		echo "Now testing ./x$${i}cblat1";\
		./x$${i}cblat1 ;\
	done; \
	echo "TEST2 DONE";\
	) | tee --append $(DTR)
	grep "TEST2 DONE" $(DTR) >/dev/null
	( set -e;\
	cd bin/Linux_fpic;\
	export LD_LIBRARY_PATH=../../lib/Linux_fpic:$$(dirname $$(cat ../../Make.Linux | grep ' FLAPACKlib =' | awk '{print $$3}')):$$(dirname $$(cat ../../Make.Linux | grep ' BLASlib =' | awk '{print $$3}'));\
	for i in s d c z ; do\
		echo "Now testing ./x$${i}l2blastst";\
		./x$${i}l2blastst -R all -n 1000 -m 1000 -F 200;\
		echo "Now testing ./x$${i}l3blastst";\
		./x$${i}l3blastst -R all -n 1000 -m 1000;\
		echo "Now testing ./x$${i}lutst";\
		./x$${i}lutst;\
		echo "Now testing ./x$${i}llttst";\
		./x$${i}llttst;\
		echo "Now tesing ./x$${i}lutstF";\
		./x$${i}lutstF;\
		echo "Now testing ./x$${i}llttstF";\
		./x$${i}llttstF;\
	done ;\
	echo "TEST3 DONE";\
	) | tee --append $(DTR)
	grep "TEST3 DONE" $(DTR) >/dev/null
	touch test-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f test-stamp build-stamp install-stamp startup-stamp lapack-stamp blas-stamp

	-make killall arch=Linux
	-make killall arch=Linux_fpic
	rm -f CONFIG/ConfDump.log
	rm -f CONFIG/ARCHS/ConfDump.log
	rm -fr $$(find CONFIG/ARCHS/* -type d -maxdepth 1)
	rm -f tst.o xconfig
	rm -f Make.Linux Make.Linux_fpic
	rm -rf blas* lapack*
	rm -rf $$(dirname $(DTR))
	rm -f CONFIG/ATLrun.Linux CONFIG/ATLrun.Linux_fpic

	dh_clean

install: test-stamp install-stamp
install-stamp: test-stamp
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	set -e;\
	for i in $(ELIBS) ; do \
		install lib/Linux_fpic/lib$${i}.so.$(VER) `pwd`/debian/tmp/usr/lib ;\
		ln -s lib$${i}.so.$(VER) `pwd`/debian/tmp/usr/lib/lib$${i}.so.$(SO); \
		ln -s lib$${i}.so.$(SO) `pwd`/debian/tmp/usr/lib/lib$${i}.so ;\
		install lib/Linux/lib$${i}.a `pwd`/debian/tmp/usr/lib/lib$${i}.a ;\
	done

	install lib/Linux_fpic/libblas.so.$(VER) `pwd`/debian/tmp/usr/lib/atlas/libblas.so.$(VER)
	ln -s libblas.so.$(VER) `pwd`/debian/tmp/usr/lib/atlas/libblas.so.$(SO)
	ln -s libblas.so.$(SO) `pwd`/debian/tmp/usr/lib/atlas/libblas.so
	install lib/Linux/libblas.a `pwd`/debian/tmp/usr/lib/atlas/libblas.a

	install lib/Linux_fpic/liblapack.so.$(VER) `pwd`/debian/tmp/usr/lib/atlas/liblapack.so.$(VER)
	ln -s liblapack.so.$(VER) `pwd`/debian/tmp/usr/lib/atlas/liblapack.so.$(SO)
	ln -s liblapack.so.$(SO) `pwd`/debian/tmp/usr/lib/atlas/liblapack.so
	install lib/Linux/liblapack.a `pwd`/debian/tmp/usr/lib/atlas/liblapack.a

	set -e;\
	for i in $(TPROGS) ; do \
		install bin/Linux_fpic/$${i} `pwd`/debian/tmp/usr/lib/atlas ;\
	done

	set -e;\
	for i in $(FPROGS) ; do \
		install interfaces/blas/F77/testing/Linux_fpic/$${i} `pwd`/debian/tmp/usr/lib/atlas ;\
	done

	set -e;\
	for i in $(CPROGS) ; do \
		install interfaces/blas/C/testing/Linux_fpic/$${i} `pwd`/debian/tmp/usr/lib/atlas ;\
	done

	set -e;\
	for i in $(HEADERS) ; do \
		install -m 0644 include/$${i} `pwd`/debian/tmp/usr/include ; \
	done

	dh_movefiles

	touch install-stamp

# Build architecture-independent files here.
binary-indep: build install
	dh_testversion
	dh_testdir -i
	dh_testroot -i
	dh_installdocs -i
	dh_installexamples -i
	dh_installmanpages -i
	dh_installinfo -i
	dh_undocumented 
	dh_installchangelogs -i 
	dh_strip -i
	dh_link -i
	dh_compress -i
	dh_fixperms -i
	dh_makeshlibs -i
	dh_installdeb -i
	dh_shlibdeps -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

# Build architecture-dependent files here.
binary-arch: build install
	dh_testversion
	dh_testdir -a
	dh_testroot -a
	dh_installdocs -a
	dh_installexamples -a
	dh_installmanpages -a
	dh_installinfo -a
	dh_undocumented -patlas-test $(TPROGS:=.1) $(FPROGS:=.1) $(CPROGS:=.1)
	dh_installchangelogs -a 
	dh_strip -a
	dh_link -a
	dh_compress -a
	dh_fixperms -a
	dh_makeshlibs -a
	dh_installdeb -a
	LD_LIBRARY_PATH=$$(dirname $$(cat Make.Linux | grep ' BLASlib =' | awk '{print $$3}')):$$(dirname $$(cat Make.Linux | grep ' FLAPACKlib =' | awk '{print $$3}')):`pwd`/lib/Linux_fpic dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

source diff:                                                                  
	@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false

binary:  binary-arch # binary-indep 
.PHONY: build clean binary-indep binary-arch binary install
=============================================================================

R Clint Whaley <rwhaley@cs.utk.edu> writes:

> Guys,
> 
> I just got a message in a help request wanting to know how to build ATLAS
> into a .so instead of a .a.  I've never done it, but I know some of you have.
> If anyone wants to answer this, I'll point him at the web archive.  If you
> want to avoid going on record there (where the guy might send questions
> directly to you), I can forward it on, without your @, instead.  Anyway,
> it might wind up helping me as well: adding a auto build to .so has been
> on my agenda for a long time, and maybe someday I'll get to it . . .
> 
> Thanks,
> Clint
> 
> 

-- 
Camm Maguire			     			camm@enhanced.com
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah