libpldm: Explicit deprecated, stable and testing ABI classes

Experimenting with new APIs is important, but ABI stability of the
library is also important. We wish to have the freedom to add APIs
without being burdened by them being immediately set in stone.

We implement this wish by introducing three classes of ABI:

1. deprecated
2. stable
3. testing

These are enforced by corresponding function attributes:

1. LIBPLDM_ABI_DEPRECATED
2. LIBPLDM_ABI_STABLE
3. LIBPLDM_ABI_TESTING

Symbol visibility in the library is flipped to 'hidden' by default, so
one of these annotations must be used for the symbol to be exposed.

With these classes in place there are now clear points in time at which
we update the ABI dumps captured under the abi/ directory: When an API
is migrated from the 'testing' class to the 'stable' class, or when
removed from the 'deprecated' class.

Which classes of functions are exposed by the build is controlled by the
new 'abi' meson option. The option is of array type which contains the
list of ABI classes the build should consider. It defaults to enabling
all classes to provide test coverage in CI. The classes used should be
constrained to deprecated and stable (and not test) in any dependent
projects.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I25402e20c7be9c9f264f9ccd7ac36b384823734c
diff --git a/meson.build b/meson.build
index 80d0c93..0f8fa91 100644
--- a/meson.build
+++ b/meson.build
@@ -12,12 +12,34 @@
     meson_version: '>=0.63.0',
 )
 
-add_project_arguments('-D_DEFAULT_SOURCE',language:['c'])
+add_project_arguments('-D_DEFAULT_SOURCE', language: ['c'])
+
+compiler = meson.get_compiler('c')
+conf = configuration_data()
+if compiler.has_header('poll.h')
+  conf.set('PLDM_HAS_POLL', 1)
+endif
+
+# ABI control
+visible =  '__attribute__((visibility("default")))'
+if get_option('abi').contains('deprecated')
+  conf.set('LIBPLDM_ABI_DEPRECATED', visible)
+  add_project_arguments('-DLIBPLDM_API_DEPRECATED', language: ['c', 'cpp'])
+else
+  conf.set('LIBPLDM_ABI_DEPRECATED', '')
+endif
+conf.set('LIBPLDM_ABI_STABLE', visible) # Always expose the stable symbols
+if get_option('abi').contains('testing')
+  conf.set('LIBPLDM_ABI_TESTING', visible)
+  add_project_arguments('-DLIBPLDM_API_TESTING', language: ['c', 'cpp'])
+else
+  conf.set('LIBPLDM_ABI_TESTING', '')
+endif
 
 libpldm_sources = files()
 subdir('src')
 
-libpldm_include_dir = ['include', 'src']
+libpldm_include_dir = ['.', 'include', 'src']
 libpldm_headers = files()
 libpldm_transport_headers = files()
 
@@ -29,6 +51,7 @@
    implicit_include_directories: false,
    include_directories: libpldm_include_dir,
    version: meson.project_version(),
+   gnu_symbol_visibility: 'hidden',
    install: true
    )
 
@@ -52,11 +75,6 @@
   version: meson.project_version(),
   libraries: libpldm)
 
-compiler = meson.get_compiler('c')
-conf = configuration_data()
-if compiler.has_header('poll.h')
-  conf.set('PLDM_HAS_POLL', 1)
-endif
 configure_file(output: 'config.h',
   configuration: conf
 )