Index: mesonbuild/build.py
--- mesonbuild/build.py.orig
+++ mesonbuild/build.py
@@ -35,7 +35,7 @@ from .mesonlib import (
     File, MesonException, MachineChoice, PerMachine, OrderedSet, listify,
     extract_as_list, typeslistify, stringlistify, classify_unity_sources,
     get_filenames_templates_dict, substitute_values, has_path_sep,
-    OptionKey, PerMachineDefaultable, OptionOverrideProxy,
+    OptionKey, PerMachineDefaultable, OptionOverrideProxy, is_openbsd,
     MesonBugException
 )
 from .compilers import (
@@ -2261,6 +2261,26 @@ class SharedLibrary(BuildTarget):
             elif self.soversion:
                 # If unspecified, pick the soversion
                 self.darwin_versions = 2 * [self.soversion]
+        if is_openbsd():
+            self.libversion = os.getenv('LIB' + self.name + '_VERSION')
+            if (self.libversion is None and
+                    self.soversion is not None and
+                    len(self.soversion) != 0 and
+                    str(os.getenv('MODMESON_PORT_BUILD')).casefold() == 'yes'):
+                self.libversion = '0.0'
+            if self.libversion is not None:
+                self.ltversion_orig = self.ltversion if self.ltversion is not None else self.soversion
+                self.ltversion = self.libversion.format(self)
+                self.soversion = self.ltversion
+                shared_libs_log = os.path.join(self.environment.get_build_dir(), 'shared_libs.log')
+                if not os.path.isfile(shared_libs_log):
+                    f = open(shared_libs_log, 'w+')
+                    f.write("# SHARED_LIBS+= {:<25}<obsd version> # <orig version>\n".format("<libname>"))
+                    f.close
+                f = open(shared_libs_log, 'a')
+                f.write("SHARED_LIBS += {:<25} {} # {}\n".format(self.name, \
+                        self.soversion, self.ltversion_orig))
+                f.close
 
         # Visual Studio module-definitions file
         if 'vs_module_defs' in kwargs:
@@ -2332,6 +2352,8 @@ class SharedLibrary(BuildTarget):
         # filename. If ltversion != soversion we create an soversion alias:
         # libfoo.so.0 -> libfoo.so.0.100.0
         # Where libfoo.so.0.100.0 is the actual library
+        if is_openbsd() and self.libversion is not None:
+            return {}
         if self.suffix == 'so' and self.ltversion and self.ltversion != self.soversion:
             alias_tpl = self.filename_tpl.replace('ltversion', 'soversion')
             ltversion_filename = alias_tpl.format(self)
