Skip to content

Commit

Permalink
build: Allow simple fixed library names.
Browse files Browse the repository at this point in the history
This is the current state of OpenBLAS library naming for the pkgsrc
packages (NetBSD and cross-platform).

The idea is to be able to

1) be able to have a stable library name to expect from the build
2) install multiple variants next to each other (single-threaded, parallel)

For this, the new switch FIXED_LIBNAME is introduced. The build uses

make FIXED_LIBNAME=1 LIBNAMESUFFIX=openmp

In the case of 64 bit indices, it uses

make FIXED_LIBNAME=1 LIBNAMESUFFIX=openmp  INTERFACE64=1 LIBSOBASENAME=openblas64

This results in what I assumed to be the intention of the name variables to
begin with, namely primary predictable library names like

libopenblas_openmp.so
libopenblas64_openmp.so

(As pkgsrc keeps a list of expected file names resulting from a build on the user
machine, too funky names with CPU model in there and symlinks are too funky.)

I see that the naming scheme of the 64 bit indices lib is still under discussion, along
with symbol suffix. So far, we use the names without renamed symbols. They are
all installable at the same time and user software can choose which one to use, also
using the pkg-config file (which could be handled more elegantly). Without an established
convention, I didn't think like we should make the call. Depends on what downstream
packages use at some point.

I don't say that I do not cause more mess than necessary, or that I fully understand
the already pesent mess. Just throwing this suggestion out there. Maybe my the
FIXED_LIBNAME switch or something along that can be included. Or we work out
something better that fulfills the demands of a pkgsrc installation.

See the github mirror of pgksrc for the patches in use.

https://github.com/NetBSD/pkgsrc/tree/trunk/math/openblas
https://github.com/NetBSD/pkgsrc/tree/trunk/math/openblas64
https://github.com/NetBSD/pkgsrc/tree/trunk/math/openblas_openmp
https://github.com/NetBSD/pkgsrc/tree/trunk/math/openblas64_openmp
https://github.com/NetBSD/pkgsrc/tree/trunk/math/openblas_pthread
https://github.com/NetBSD/pkgsrc/tree/trunk/math/openblas64_pthread

Also, I hope I didn't break any other configuration.

And, lastly, one idea: If we settle on OpenMP always and the ILP64 symbols with suffix, we
could just get away with building _one_ libopenmp.so (with libtool versioning, perhaps,
libopenblas.so.0.4.33 and symlinks …). That would also be great and lots of
Makefile machinery could go. Until then, please consider my hack on top;-)
  • Loading branch information
drhpc committed Oct 8, 2023
1 parent 974cd11 commit a2cc3e6
Show file tree
Hide file tree
Showing 6 changed files with 2,313 additions and 8 deletions.
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,28 @@ shared : libs netlib $(RELA)
ifneq ($(NO_SHARED), 1)
ifeq ($(OSNAME), $(filter $(OSNAME),Linux SunOS Android Haiku FreeBSD DragonFly))
@$(MAKE) -C exports so
ifneq ($(LIBSONAME), $(LIBPREFIX).so)
@ln -fs $(LIBSONAME) $(LIBPREFIX).so
endif
ifneq ($(LIBSONAME), $(LIBPREFIX).so.$(MAJOR_VERSION))
@ln -fs $(LIBSONAME) $(LIBPREFIX).so.$(MAJOR_VERSION)
endif
endif
ifeq ($(OSNAME), $(filter $(OSNAME),OpenBSD NetBSD))
@$(MAKE) -C exports so
ifneq ($(LIBSONAME), $(LIBPREFIX).so)
@ln -fs $(LIBSONAME) $(LIBPREFIX).so
endif
endif
ifeq ($(OSNAME), Darwin)
@$(MAKE) -C exports dyn
ifneq ($(LIBDYNNAME), $(LIBPREFIX).dylib)
@ln -fs $(LIBDYNNAME) $(LIBPREFIX).dylib
endif
ifneq ($(LIBDYNNAME), $(LIBPREFIX).$(MAJOR_VERSION).dylib)
@ln -fs $(LIBDYNNAME) $(LIBPREFIX).$(MAJOR_VERSION).dylib
endif
endif
ifeq ($(OSNAME), WINNT)
@$(MAKE) -C exports dll
endif
Expand Down Expand Up @@ -209,13 +219,17 @@ endif
ifdef USE_THREAD
@echo USE_THREAD=$(USE_THREAD) >> Makefile.conf_last
endif
ifneq ($(LIBNAME), $(LIBPREFIX).$(LIBSUFFIX))
@-ln -fs $(LIBNAME) $(LIBPREFIX).$(LIBSUFFIX)
endif
@touch lib.grd

prof : prof_blas prof_lapack

prof_blas :
ifneq ($(LIBNAME_P), $(LIBPREFIX)_p.$(LIBSUFFIX))
ln -fs $(LIBNAME_P) $(LIBPREFIX)_p.$(LIBSUFFIX)
endif
for d in $(SUBDIRS) ; \
do if test -d $$d; then \
$(MAKE) -C $$d prof || exit 1 ; \
Expand All @@ -226,15 +240,19 @@ ifeq ($(DYNAMIC_ARCH), 1)
endif

blas :
ifneq ($(LIBNAME), $(LIBPREFIX).$(LIBSUFFIX))
ln -fs $(LIBNAME) $(LIBPREFIX).$(LIBSUFFIX)
endif
for d in $(BLASDIRS) ; \
do if test -d $$d; then \
$(MAKE) -C $$d libs || exit 1 ; \
fi; \
done

hpl :
ifneq ($(LIBNAME), $(LIBPREFIX).$(LIBSUFFIX))
ln -fs $(LIBNAME) $(LIBPREFIX).$(LIBSUFFIX)
endif
for d in $(BLASDIRS) ../laswp exports ; \
do if test -d $$d; then \
$(MAKE) -C $$d $(@F) || exit 1 ; \
Expand All @@ -248,7 +266,9 @@ ifeq ($(DYNAMIC_ARCH), 1)
endif

hpl_p :
ifneq ($(LIBNAME_P), $(LIBPREFIX)_p.$(LIBSUFFIX))
ln -fs $(LIBNAME_P) $(LIBPREFIX)_p.$(LIBSUFFIX)
endif
for d in $(SUBDIRS) ../laswp exports ; \
do if test -d $$d; then \
$(MAKE) -C $$d $(@F) || exit 1 ; \
Expand Down
26 changes: 19 additions & 7 deletions Makefile.install
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ PKG_EXTRALIB := $(EXTRALIB)
ifeq ($(INTERFACE64),1)
SUFFIX64=64
endif
PKGFILE="$(DESTDIR)$(OPENBLAS_PKGCONFIG_DIR)/$(LIBSONAMEBASE)$(SUFFIX64).pc"
PKGFILE="$(DESTDIR)$(OPENBLAS_PKGCONFIG_DIR)/$(LIBNAMEBASE).pc"

ifeq ($(USE_OPENMP), 1)
ifeq ($(C_COMPILER), PGI)
Expand Down Expand Up @@ -90,29 +90,37 @@ endif
ifneq ($(NO_STATIC),1)
@echo Copying the static library to $(DESTDIR)$(OPENBLAS_LIBRARY_DIR)
@install -m644 $(LIBNAME) "$(DESTDIR)$(OPENBLAS_LIBRARY_DIR)"
ifneq ($(LIBNAME), $(LIBPREFIX).$(LIBSUFFIX))
@cd "$(DESTDIR)$(OPENBLAS_LIBRARY_DIR)" ; \
ln -fs $(LIBNAME) $(LIBPREFIX).$(LIBSUFFIX)
endif
endif
#for install shared library
ifneq ($(NO_SHARED),1)
@echo Copying the shared library to $(DESTDIR)$(OPENBLAS_LIBRARY_DIR)
ifeq ($(OSNAME), $(filter $(OSNAME),Linux SunOS Android Haiku FreeBSD DragonFly))
@install -m755 $(LIBSONAME) "$(DESTDIR)$(OPENBLAS_LIBRARY_DIR)"
@cd "$(DESTDIR)$(OPENBLAS_LIBRARY_DIR)" ; \
ln -fs $(LIBSONAME) $(LIBPREFIX).so ; \
ln -fs $(LIBSONAME) $(LIBPREFIX).so.$(MAJOR_VERSION)
if ! test $(LIBSONAME) = $(LIBPREFIX).so; then \
ln -fs $(LIBSONAME) $(LIBPREFIX).so ; fi ; \
if ! test $(LIBSONAME) = $(LIBPREFIX).so.$(MAJOR_VERSION); then \
ln -fs $(LIBSONAME) $(LIBPREFIX).so.$(MAJOR_VERSION); fi
endif

ifeq ($(OSNAME), $(filter $(OSNAME),OpenBSD NetBSD))
@cp $(LIBSONAME) "$(DESTDIR)$(OPENBLAS_LIBRARY_DIR)"
ifneq ($(LIBSONAME), $(LIBPREFIX).so)
@cd "$(DESTDIR)$(OPENBLAS_LIBRARY_DIR)" ; \
ln -fs $(LIBSONAME) $(LIBPREFIX).so
endif
endif
ifeq ($(OSNAME), Darwin)
@-cp $(LIBDYNNAME) "$(DESTDIR)$(OPENBLAS_LIBRARY_DIR)"
@-install_name_tool -id "$(OPENBLAS_LIBRARY_DIR)/$(LIBPREFIX).$(MAJOR_VERSION).dylib" "$(DESTDIR)$(OPENBLAS_LIBRARY_DIR)/$(LIBDYNNAME)"
@cd "$(DESTDIR)$(OPENBLAS_LIBRARY_DIR)" ; \
if ! test $(LIBDYNNAME) = $(LIBPREFIX).dylib; then \
ln -fs $(LIBDYNNAME) $(LIBPREFIX).dylib ; \
fi ; \
ln -fs $(LIBDYNNAME) $(LIBPREFIX).$(MAJOR_VERSION).dylib
endif
ifeq ($(OSNAME), WINNT)
Expand Down Expand Up @@ -140,16 +148,20 @@ endif
ifneq ($(NO_STATIC),1)
@echo Copying the static library to $(DESTDIR)$(OPENBLAS_LIBRARY_DIR)
@installbsd -c -m 644 $(LIBNAME) "$(DESTDIR)$(OPENBLAS_LIBRARY_DIR)"
ifneq ($(LIBNAME), $(LIBPREFIX).$(LIBSUFFIX))
@cd "$(DESTDIR)$(OPENBLAS_LIBRARY_DIR)" ; \
ln -fs $(LIBNAME) $(LIBPREFIX).$(LIBSUFFIX)
endif
endif
#for install shared library
ifneq ($(NO_SHARED),1)
@echo Copying the shared library to $(DESTDIR)$(OPENBLAS_LIBRARY_DIR)
@installbsd -c -m 755 $(LIBSONAME) "$(DESTDIR)$(OPENBLAS_LIBRARY_DIR)"
@cd "$(DESTDIR)$(OPENBLAS_LIBRARY_DIR)" ; \
ln -fs $(LIBSONAME) $(LIBPREFIX).so ; \
ln -fs $(LIBSONAME) $(LIBPREFIX).so.$(MAJOR_VERSION)
if ! test $(LIBSONAME) = $(LIBPREFIX).so; then \
ln -fs $(LIBSONAME) $(LIBPREFIX).so ; fi ; \
if ! test $(LIBSONAME) = $(LIBPREFIX).so.$(MAJOR_VERSION); then \
ln -fs $(LIBSONAME) $(LIBPREFIX).so.$(MAJOR_VERSION); fi
endif

endif
Expand All @@ -158,7 +170,7 @@ endif
ifeq ($(INTERFACE64),1)
SUFFIX64=64
endif
PKGFILE="$(DESTDIR)$(OPENBLAS_PKGCONFIG_DIR)/$(LIBSONAMEBASE)$(SUFFIX64).pc"
PKGFILE="$(DESTDIR)$(OPENBLAS_PKGCONFIG_DIR)/$(LIBNAMEBASE).pc"

@echo Generating $(LIBSONAMEBASE)$(SUFFIX64).pc in "$(DESTDIR)$(OPENBLAS_PKGCONFIG_DIR)"
@echo 'libdir='$(OPENBLAS_LIBRARY_DIR) > "$(PKGFILE)"
Expand All @@ -167,7 +179,7 @@ endif
@echo 'openblas_config= USE_64BITINT='$(INTERFACE64) 'DYNAMIC_ARCH='$(DYNAMIC_ARCH) 'DYNAMIC_OLDER='$(DYNAMIC_OLDER) 'NO_CBLAS='$(NO_CBLAS) 'NO_LAPACK='$(NO_LAPACK) 'NO_LAPACKE='$(NO_LAPACKE) 'NO_AFFINITY='$(NO_AFFINITY) 'USE_OPENMP='$(USE_OPENMP) $(CORE) 'MAX_THREADS='$(NUM_THREADS)>> "$(PKGFILE)"
@echo 'version='$(VERSION) >> "$(PKGFILE)"
@echo 'extralib='$(PKG_EXTRALIB) >> "$(PKGFILE)"
@cat openblas.pc.in >> "$(PKGFILE)"
@cat openblas.pc.in | sed -e 's,-lopenblas\b,-l$(LIBNAMEBASE),' >> "$(PKGFILE)"


#Generating OpenBLASConfig.cmake
Expand Down
Loading

0 comments on commit a2cc3e6

Please sign in to comment.