summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitlab-ci.yml91
-rw-r--r--Makefile.am2
-rw-r--r--meson.build178
-rw-r--r--meson.options4
-rw-r--r--xshmfence.pc.in6
5 files changed, 274 insertions, 7 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 96343ef..1a96458 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -30,8 +30,15 @@ variables:
# The tag should be updated each time the list of packages is updated.
# Changing a tag forces the associated image to be rebuilt.
# Note: the tag has no meaning, we use a date format purely for readability
- FDO_DISTRIBUTION_TAG: '2022-07-17.0'
- FDO_DISTRIBUTION_PACKAGES: 'git gcc pkgconf autoconf automake libtool make xorg-util-macros xorgproto'
+ FDO_DISTRIBUTION_TAG: '2025-02-15.0'
+ # minimal set of packages required to build and install either way
+ BASE_PACKAGES: 'git gcc clang pkgconf xorgproto'
+ # packages needed to build and install with each set of tools
+ AUTOTOOLS_PACKAGES: 'autoconf automake libtool make xorg-util-macros'
+ MESON_PACKAGES: 'meson ninja'
+ # extra packages we need for comparing autotools & meson builds
+ EXTRA_PACKAGES: 'diffoscope diffutils findutils jq'
+ FDO_DISTRIBUTION_PACKAGES: $BASE_PACKAGES $AUTOTOOLS_PACKAGES $MESON_PACKAGES $EXTRA_PACKAGES
#
@@ -81,9 +88,9 @@ container-prep:
#
-# The default build, runs on the image built above.
+# The autotools build, runs on the image built above.
#
-build:
+autotools:
stage: build
extends:
- .fdo.distribution-image@arch
@@ -95,4 +102,80 @@ build:
- make
- make check
- make distcheck
+ - mv libxshmfence*.tar.gz ..
- popd > /dev/null
+ artifacts:
+ paths:
+ - libxshmfence*.tar.gz
+
+#
+# The meson build, runs on the image built above.
+#
+.meson_build:
+ stage: build
+ extends:
+ - .fdo.distribution-image@arch
+ script:
+ - CC="${CC}" meson setup _builddir --prefix="$PWD/_install"
+ - meson compile -C _builddir
+ - meson test -C _builddir
+ - meson install -C _builddir
+
+# Run meson build with different compilers
+meson:
+ extends:
+ - .meson_build
+ parallel:
+ matrix:
+ - CC: ["gcc", "clang"]
+
+
+meson from tarball:
+ extends:
+ - .fdo.distribution-image@arch
+ stage: test
+ script:
+ - mkdir -p _tarball_build
+ - tar xf libxshmfence-*.tar.gz -C _tarball_build
+ - cd _tarball_build/libxshmfence-*
+ - meson setup _builddir
+ - meson compile -C _builddir
+ - meson test -C _builddir
+ needs:
+ - autotools
+
+compare meson and autotools:
+ extends:
+ - .fdo.distribution-image@arch
+ stage: test
+ script:
+ - mkdir -p $PWD/_meson_inst $PWD/_autotools_inst
+ - CFLAGS="-O2"
+ meson setup builddir --prefix=/usr --buildtype=plain
+ -Ddefault_library=shared
+ - meson compile -C builddir -v
+ - DESTDIR=$PWD/_meson_inst meson install -C builddir
+ - ./autogen.sh --prefix=/usr --enable-shared --disable-static
+ CFLAGS="-O2 -D_FILE_OFFSET_BITS=64"
+ - make V=1 && make install DESTDIR=$PWD/_autotools_inst
+ # get rid of expected differences between the two
+ - rm -f $PWD/_autotools_inst/usr/lib/lib*.la
+ - rm -f $PWD/_autotools_inst/usr/lib/libxshmfence.so
+ - ln -s libxshmfence.so.1 $PWD/_autotools_inst/usr/lib/libxshmfence.so
+ - sed -i -e 's/{exec_prefix}/{prefix}/' -e '/exec_prefix/d'
+ -e '/^Libs.private:\( \)*$/d'
+ _autotools_inst/usr/lib/pkgconfig/xshmfence.pc
+ - find $PWD/_meson_inst $PWD/_autotools_inst
+ -exec touch -h -r $PWD/_meson_inst/ {} \+
+ - diffoscope --text-color=always _autotools_inst _meson_inst
+
+check versions are in sync:
+ extends:
+ - .fdo.distribution-image@arch
+ stage: test
+ script:
+ - autoreconf -ivf
+ - ./configure --version | head -n 1 | sed -e 's/libxshmfence configure //' > autotools.version
+ - meson introspect meson.build --projectinfo | jq -r '.version' > meson.version
+ - diff -u autotools.version meson.version ||
+ (echo "ERROR - autotools and meson versions not in sync" && false)
diff --git a/Makefile.am b/Makefile.am
index 1d7043b..74a06a8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -25,7 +25,7 @@ SUBDIRS = src test
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = xshmfence.pc
-EXTRA_DIST = xshmfence.pc.in ChangeLog README.md
+EXTRA_DIST = xshmfence.pc.in ChangeLog README.md meson.build meson.options
MAINTAINERCLEANFILES = ChangeLog
.PHONY: ChangeLog
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..68e4f79
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,178 @@
+# SPDX-License-Identifier: MIT
+#
+# Copyright (c) 2025, Oracle and/or its affiliates.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
+#
+
+
+project(
+ 'libxshmfence',
+ 'c',
+ version: '1.3.3',
+ license: 'HPND-sell-variant',
+ license_files: 'COPYING',
+ meson_version: '>= 1.3.0',
+)
+
+# Replacement for XORG_DEFAULT_OPTIONS
+cc = meson.get_compiler('c')
+if cc.has_argument('-fno-strict-aliasing')
+ add_project_arguments('-fno-strict-aliasing', language: 'c')
+endif
+
+conf = configuration_data()
+
+# Replaces AC_USE_SYSTEM_EXTENSIONS
+if host_machine.system() == 'sunos'
+ system_extensions = '__EXTENSIONS__'
+else
+ system_extensions = '_GNU_SOURCE'
+endif
+conf.set(system_extensions, 1,
+ description: 'Enable non-standardized system API extensions')
+
+futex = false
+if cc.has_header('linux/futex.h', required: get_option('futex'))
+ futex = true
+elif cc.has_header('sys/umtx.h', required: get_option('futex'),
+ prefix: ['#include <errno.h>', '#include <sys/types.h>'])
+ futex = true
+ conf.set('HAVE_UMTX', 1, description: 'Use umtx')
+endif
+
+if futex
+ pthread = false
+ conf.set('HAVE_FUTEX', 1, description: 'Use futexes')
+else
+ pthread = true
+ conf.set('HAVE_PTHREAD', 1, description: 'Use pthread primitives')
+endif
+summary('Synchronization method', futex ? 'futexes' : 'pthread primitives')
+
+if pthread
+ thread_dep = cc.find_library('pthread')
+ cc.has_function('pthread_create', dependencies: thread_dep,
+ prefix: '#include <pthread.h>', required: true)
+else
+ thread_dep = dependency('', required: false)
+endif
+
+xproto_dep = dependency('xproto', required: true)
+
+if cc.has_function('memfd_create', required: false,
+ prefix: ['#define ' + system_extensions,
+ '#include <sys/mman.h>'])
+ conf.set('HAVE_MEMFD_CREATE', 1)
+endif
+
+if cc.has_function('mkostemp', required: false,
+ prefix: ['#define ' + system_extensions,
+ '#include <stdlib.h>', '#include <fcntl.h>'])
+ conf.set('HAVE_MKOSTEMP', 1)
+endif
+
+if cc.has_header_symbol('<asm/unistd.h>', '__NR_memfd_create', required: false,
+ prefix: '#define ' + system_extensions)
+ conf.set('HAVE_DECL___NR_MEMFD_CREATE', 1)
+endif
+
+if cc.has_header('sys/memfd.h', required: false)
+ conf.set('HAVE_MEMFD_H', 1, description: 'Has sys/memfd.h header')
+endif
+
+if get_option('visibility').allowed()
+ visibility = 'hidden'
+else
+ visibility = 'default'
+endif
+summary('Symbol visibility', visibility)
+
+#
+# Locate a suitable tmp file system for creating shared memory files
+#
+
+shmdir = get_option('shared-memory-dir')
+if shmdir == 'auto'
+ if meson.is_cross_build()
+ error('Must specify -Dshared-memory-dir=<path> when cross-compiling')
+ endif
+ shmdirs=['/run/shm', '/dev/shm', '/var/tmp', '/tmp']
+ fs = import('fs')
+ foreach dir: shmdirs
+ if fs.is_dir(dir)
+ shmdir = dir
+ break
+ endif
+ endforeach
+ if shmdir == 'auto'
+ error('No directory found for shared memory temp files.')
+ endif
+elif shmdir.startswith('/') == false
+ error('Invalid directory specified for -Dshared-memory-dir:', shmdir)
+endif
+
+conf.set_quoted('SHMDIR', shmdir,
+ description: 'Directory for shared memory temp files')
+summary('Shared memory dir', shmdir)
+
+configure_file(output: 'config.h', configuration: conf)
+add_project_arguments('-DHAVE_CONFIG_H', language : 'c')
+
+libxshmfence_sources = ['src/xshmfence_alloc.c']
+if pthread
+ libxshmfence_sources += 'src/xshmfence_pthread.c'
+endif
+if futex
+ libxshmfence_sources += 'src/xshmfence_futex.c'
+endif
+
+libxshmfence = library(
+ 'xshmfence',
+ libxshmfence_sources,
+ dependencies: [thread_dep, xproto_dep],
+ gnu_symbol_visibility: visibility,
+ include_directories: 'src',
+ version: '1.0.0',
+ install: true,
+)
+
+install_headers(
+ 'src/xshmfence.h',
+ subdir: 'X11',
+)
+
+xshmfence_test = executable(
+ 'xshmfence_test',
+ 'test/xshmfence_test.c',
+ include_directories: 'src',
+ dependencies: thread_dep,
+ link_with: libxshmfence,
+)
+test('xshmfence_test', xshmfence_test)
+
+pkg = import('pkgconfig')
+pkg.generate(
+ libxshmfence,
+ description: 'The X Shared Memory Fence Library',
+ filebase: 'xshmfence',
+ url: 'https://gitlab.freedesktop.org/xorg/lib/libxshmfence',
+ requires: 'xproto'
+)
diff --git a/meson.options b/meson.options
new file mode 100644
index 0000000..89e4f1a
--- /dev/null
+++ b/meson.options
@@ -0,0 +1,4 @@
+option('futex', type: 'feature', description: 'Enable futexes')
+option('visibility', type: 'feature', description: 'Enable symbol visibility')
+option('shared-memory-dir', type: 'string', value: 'auto',
+ description: 'Path to directory in a world-writable temporary directory for anonymous shared memory')
diff --git a/xshmfence.pc.in b/xshmfence.pc.in
index a139fab..7c314ed 100644
--- a/xshmfence.pc.in
+++ b/xshmfence.pc.in
@@ -1,11 +1,13 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
-libdir=@libdir@
includedir=@includedir@
+libdir=@libdir@
Name: xshmfence
Description: The X Shared Memory Fence Library
+URL: https://gitlab.freedesktop.org/xorg/lib/libxshmfence
Version: @PACKAGE_VERSION@
-Cflags: -I${includedir} @XPROTO_CFLAGS@
+Requires: xproto
Libs: -L${libdir} -lxshmfence
Libs.private: @PTHREAD_LIBS@
+Cflags: -I${includedir}