[libgepub] Port to meson build system
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgepub] Port to meson build system
- Date: Tue, 23 May 2017 12:45:10 +0000 (UTC)
commit 97b173c8149105631277dee71c44feb8d2d86a40
Author: Iñigo Martínez <inigomartinez gmail com>
Date: Tue May 23 13:37:45 2017 +0200
Port to meson build system
https://bugzilla.gnome.org/show_bug.cgi?id=782994
configure_meson | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++
libgepub/meson.build | 115 ++++++++++++++++++++++++++++++++
meson.build | 133 +++++++++++++++++++++++++++++++++++++
meson_options.txt | 1 +
tests/meson.build | 20 ++++++
5 files changed, 449 insertions(+), 0 deletions(-)
---
diff --git a/configure_meson b/configure_meson
new file mode 100755
index 0000000..8ac2753
--- /dev/null
+++ b/configure_meson
@@ -0,0 +1,180 @@
+#!/bin/bash
+# configure script adapter for Meson
+# Based on build-api: https://github.com/cgwalters/build-api
+# Copyright 2010, 2011, 2013 Colin Walters <walters verbum org>
+# Copyright 2016, 2017 Emmanuele Bassi
+# Copyright 2017 Iñigo Martínez <inigomartinez gmail com>
+# Licensed under the new-BSD license (http://www.opensource.org/licenses/bsd-license.php)
+
+# Build API variables:
+
+# Little helper function for reading args from the commandline.
+# it automatically handles -a b and -a=b variants, and returns 1 if
+# we need to shift $3.
+read_arg() {
+ # $1 = arg name
+ # $2 = arg value
+ # $3 = arg parameter
+ local rematch='^[^=]*=(.*)$'
+ if [[ $2 =~ $rematch ]]; then
+ read "$1" <<< "${BASH_REMATCH[1]}"
+ else
+ read "$1" <<< "$3"
+ # There is no way to shift our callers args, so
+ # return 1 to indicate they should do it instead.
+ return 1
+ fi
+}
+
+sanitycheck() {
+ # $1 = arg name
+ # $1 = arg command
+ # $2 = arg alternates
+ local cmd=$( which $2 2>/dev/null )
+
+ if [ -x "$cmd" ]; then
+ read "$1" <<< "$cmd"
+ return 0
+ fi
+
+ test -z $3 || {
+ for alt in $3; do
+ cmd=$( which $alt 2>/dev/null )
+
+ if [ -x "$cmd" ]; then
+ read "$1" <<< "$cmd"
+ return 0
+ fi
+ done
+ }
+
+ echo -e "\e[1;31mERROR\e[0m: Command '$2' not found"
+ exit 1
+}
+
+checkoption() {
+ # $1 = arg
+ option="${1#*--}"
+ action="${option%%-*}"
+ name="${option#*-}"
+ if [ ${default_options[$name]+_} ]; then
+ case "$action" in
+ enable) meson_options[$name]=true;;
+ disable) meson_options[$name]=false;;
+ *) echo -e "\e[1;33mINFO\e[0m: Ignoring unknown action '$action'";;
+ esac
+ else
+ echo -e "\e[1;33mINFO\e[0m: Ignoring unknown option '$option'"
+ fi
+}
+
+echooption() {
+ # $1 = option
+ if [ ${meson_options[$1]+_} ]; then
+ echo ${meson_options[$1]}
+ elif [ ${default_options[$1]+_} ]; then
+ echo ${default_options[$1]}
+ fi
+}
+
+sanitycheck MESON 'meson'
+sanitycheck MESONTEST 'mesontest'
+sanitycheck NINJA 'ninja' 'ninja-build'
+
+declare -A default_options=(
+ ['introspection']=true
+)
+
+declare -A meson_options
+
+while (($# > 0)); do
+ case "${1%%=*}" in
+ --prefix) read_arg prefix "$@" || shift;;
+ --bindir) read_arg bindir "$@" || shift;;
+ --sbindir) read_arg sbindir "$@" || shift;;
+ --libexecdir) read_arg libexecdir "$@" || shift;;
+ --datarootdir) read_arg datarootdir "$@" || shift;;
+ --datadir) read_arg datadir "$@" || shift;;
+ --sysconfdir) read_arg sysconfdir "$@" || shift;;
+ --libdir) read_arg libdir "$@" || shift;;
+ --mandir) read_arg mandir "$@" || shift;;
+ --includedir) read_arg includedir "$@" || shift;;
+ *) checkoption $1;;
+ esac
+ shift
+done
+
+# Defaults
+test -z ${prefix} && prefix="/usr/local"
+test -z ${bindir} && bindir=${prefix}/bin
+test -z ${sbindir} && sbindir=${prefix}/sbin
+test -z ${libexecdir} && libexecdir=${prefix}/bin
+test -z ${datarootdir} && datarootdir=${prefix}/share
+test -z ${datadir} && datadir=${datarootdir}
+test -z ${sysconfdir} && sysconfdir=${prefix}/etc
+test -z ${libdir} && libdir=${prefix}/lib
+test -z ${mandir} && mandir=${prefix}/share/man
+test -z ${includedir} && includedir=${prefix}/include
+
+# The source directory is the location of this file
+srcdir=$(dirname $0)
+
+# The build directory is the current location
+builddir=`pwd`
+
+# If we're calling this file from the source directory then
+# we automatically create a build directory and ensure that
+# both Meson and Ninja invocations are relative to that
+# location
+if [[ -f "${builddir}/meson.build" ]]; then
+ mkdir -p _build
+ builddir="${builddir}/_build"
+ NINJA_OPT="-C ${builddir}"
+fi
+
+# Wrapper Makefile for Ninja
+cat > Makefile <<END
+# Generated by configure; do not edit
+
+all:
+ CC="\$(CC)" CXX="\$(CXX)" ${NINJA} ${NINJA_OPT}
+
+install:
+ DESTDIR="\$(DESTDIR)" ${NINJA} ${NINJA_OPT} install
+
+check:
+ ${MESONTEST} ${NINJA_OPT}
+END
+
+echo "
+
+ libgepub
+ ========
+
+ meson: ${MESON}
+ ninja: ${NINJA}
+ prefix: ${prefix}
+ compiler: ${CC}
+ global flags: ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}
+ introspection: $(echooption introspection)
+
+ Now type '${NINJA} -C ${builddir}' to build
+"
+
+cmd_options=""
+for key in "${!meson_options[@]}"; do
+ cmd_options="$cmd_options -Denable-$key=${meson_options[$key]}"
+done
+
+exec ${MESON} \
+ --prefix=${prefix} \
+ --libdir=${libdir} \
+ --libexecdir=${libexecdir} \
+ --datadir=${datadir} \
+ --sysconfdir=${sysconfdir} \
+ --bindir=${bindir} \
+ --includedir=${includedir} \
+ --mandir=${mandir} \
+ ${cmd_options} \
+ ${builddir} \
+ ${srcdir}
diff --git a/libgepub/meson.build b/libgepub/meson.build
new file mode 100644
index 0000000..7b74292
--- /dev/null
+++ b/libgepub/meson.build
@@ -0,0 +1,115 @@
+headers = [
+ 'gepub-widget.h',
+ 'gepub-archive.h',
+ 'gepub-text-chunk.h',
+ 'gepub-doc.h',
+ 'gepub.h'
+]
+
+install_headers(
+ headers,
+ subdir: gepub_pkgincludedir
+)
+
+private_headers = [
+ 'gepub-utils.h'
+]
+
+sources = [
+ 'gepub-widget.c',
+ 'gepub-archive.c',
+ 'gepub-text-chunk.c',
+ 'gepub-doc.c',
+ 'gepub-utils.c'
+]
+
+ldflags = [
+ '-no-undefined',
+ '-export-symbols-regex "^gepub_*"'
+]
+
+gepub_ldflags = []
+
+if host_machine.system().contains('linux')
+ foreach ldflag: ldflags
+ if cc.has_argument(ldflag)
+ gepub_ldflags += ldflag
+ endif
+ endforeach
+endif
+
+libtype = get_option('default_library')
+
+if libtype == 'static'
+ libgepub = static_library(
+ 'gepub',
+ sources: sources + headers + private_headers,
+ include_directories: top_inc,
+ dependencies: gepub_dep,
+ link_args: gepub_ldflags,
+ install: true,
+ install_dir: gepub_libdir
+ )
+else
+ libgepub = shared_library(
+ 'gepub',
+ sources: sources + headers + private_headers,
+ version: libversion,
+ soversion: soversion,
+ include_directories: top_inc,
+ dependencies: gepub_dep,
+ link_args: gepub_ldflags,
+ install: true,
+ install_dir: gepub_libdir
+ )
+endif
+
+libgepub_dep = declare_dependency(
+ link_with: libgepub,
+ include_directories: include_directories('.'),
+ dependencies: gepub_dep
+)
+
+pkg.generate(
+ libraries: libgepub,
+ version: gepub_version,
+ name: meson.project_name(),
+ description: 'epub Documents library',
+ filebase: meson.project_name(),
+ subdirs: meson.project_name(),
+ requires: 'gio-2.0',
+ requires_private: [
+ 'libxml-2.0',
+ 'libarchive'
+ ]
+)
+
+if get_option('enable-introspection') and libtype == 'shared'
+ gir_inc = [
+ 'GObject-2.0',
+ 'libxml2-2.0',
+ 'WebKit2-4.0'
+ ]
+
+ gir_extra_args = [
+ '--warn-all'
+ ]
+
+ gir_dir = join_paths(gepub_datadir, '@0@-@1@'.format('gir', gepub_gir_version))
+ typelib_dir = join_paths(gepub_libdir, '@0@-@1@'.format('girepository', gepub_gir_version))
+
+ gnome.generate_gir(
+ libgepub,
+ sources: sources + headers + private_headers,
+ namespace: gepub_gir_ns,
+ nsversion: gepub_version,
+ identifier_prefix: gepub_gir_ns,
+ symbol_prefix: gepub_gir_ns.to_lower(),
+ includes: gir_inc,
+ include_directories: top_inc,
+ install: true,
+ install_dir_gir: gir_dir,
+ install_dir_typelib: typelib_dir,
+ extra_args: gir_extra_args
+ )
+endif
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..eff8b50
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,133 @@
+project(
+ 'libgepub', 'c',
+ version: '0.4',
+ license: 'LGPL2+',
+ default_options: [
+ 'buildtype=debugoptimized',
+ 'c_std=gnu99',
+ 'warning_level=1'
+ ],
+ meson_version: '>= 0.38.1'
+)
+
+gepub_version = meson.project_version()
+version_array = gepub_version.split('.')
+gepub_major_version = version_array[0].to_int()
+gepub_minor_version = version_array[1].to_int()
+
+gepub_gir_ns = 'Gepub'
+gepub_gir_version = '1.0'
+
+gepub_prefix = get_option('prefix')
+gepub_datadir = join_paths(gepub_prefix, get_option('datadir'))
+gepub_libdir = join_paths(gepub_prefix, get_option('libdir'))
+gepub_includedir = join_paths(gepub_prefix, get_option('includedir'))
+
+gepub_pkgincludedir = join_paths(gepub_includedir, meson.project_name())
+
+soversion = 0
+current = 0
+revision = 0
+libversion = '@0@.@1@.@2@'.format(soversion, current, revision)
+
+cc = meson.get_compiler('c')
+
+conf = configuration_data()
+
+# package
+conf.set_quoted('PACKAGE', meson.project_name())
+conf.set_quoted('PACKAGE_BUGREPORT', 'danigm wadobo com')
+conf.set_quoted('PACKAGE_NAME', meson.project_name())
+conf.set_quoted('PACKAGE_STRING', '@0@ @1@'.format(meson.project_name(), gepub_version))
+conf.set_quoted('PACKAGE_TARNAME', meson.project_name())
+conf.set_quoted('PACKAGE_URL', '')
+conf.set_quoted('PACKAGE_VERSION', gepub_version)
+conf.set_quoted('PACKAGE_API_VERSION', gepub_version)
+conf.set_quoted('VERSION', gepub_version)
+
+# headers
+conf.set('HAVE_DLFCN_H', cc.has_header('dlfcn.h'))
+conf.set('HAVE_INTTYPES_H', cc.has_header('inttypes.h'))
+conf.set('HAVE_MEMORY_H', cc.has_header('memory.h'))
+conf.set('HAVE_STDINT_H', cc.has_header('stdint.h'))
+conf.set('HAVE_STDLIB_H', cc.has_header('stdlib.h'))
+conf.set('HAVE_STRINGS_H', cc.has_header('strings.h'))
+conf.set('HAVE_STRING_H', cc.has_header('string.h'))
+conf.set('HAVE_SYS_STAT_H', cc.has_header('sys/stat.h'))
+conf.set('HAVE_SYS_TYPES_H', cc.has_header('sys/types.h'))
+conf.set('HAVE_UNISTD_H', cc.has_header('unistd.h'))
+
+# Compiler flags
+test_cflags = [
+ '-fno-strict-aliasing',
+ '-Wall',
+ '-Warray-bounds',
+ '-Wcast-align',
+ '-Wdeclaration-after-statement',
+ '-Wextra',
+ '-Wformat-nonliteral',
+ '-Wformat-security',
+ '-Wformat=2',
+ '-Wimplicit-function-declaration',
+ '-Winit-self',
+ '-Winline',
+ '-Wmissing-declarations',
+ '-Wmissing-format-attribute',
+ '-Wmissing-include-dirs',
+ '-Wmissing-noreturn',
+ '-Wmissing-prototypes',
+ '-Wnested-externs',
+ '-Wno-error=missing-field-initializers',
+ '-Wno-error=unused-parameter',
+ '-Wno-missing-field-initializers',
+ '-Wno-unused-parameter',
+ '-Wold-style-definition',
+ '-Wpacked',
+ '-Wpointer-arith',
+ '-Wredundant-decls',
+ '-Wreturn-type',
+ '-Wshadow',
+ '-Wsign-compare',
+ '-Wstrict-aliasing',
+ '-Wstrict-prototypes',
+ '-Wswitch-default',
+ '-Wswitch-enum',
+ '-Wundef',
+ '-Wunused-but-set-variable',
+ '-Wwrite-strings'
+]
+
+common_flags = [
+ '-DHAVE_CONFIG_H'
+]
+
+foreach cflag: test_cflags
+ if cc.has_argument(cflag)
+ common_flags += [cflag]
+ endif
+endforeach
+
+add_global_arguments(common_flags, language: 'c')
+
+gepub_dep = [
+ dependency('webkit2gtk-4.0'),
+ dependency('libsoup-2.4'),
+ dependency('glib-2.0'),
+ dependency('gobject-2.0'),
+ dependency('gio-2.0'),
+ dependency('libxml-2.0'),
+ dependency('libarchive')
+]
+
+configure_file(
+ output : 'config.h',
+ configuration : conf
+)
+
+gnome = import('gnome')
+pkg = import('pkgconfig')
+
+top_inc = include_directories('.')
+
+subdir('libgepub')
+subdir('tests')
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..cdb100d
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1 @@
+option('enable-introspection', type: 'boolean', value: true, description: 'Enable GObject Introspection
(depends on GObject)')
diff --git a/tests/meson.build b/tests/meson.build
new file mode 100644
index 0000000..b6bdd14
--- /dev/null
+++ b/tests/meson.build
@@ -0,0 +1,20 @@
+gepub_tests = [
+ 'test-gepub'
+]
+
+gepub_test_dep = [
+ gepub_dep,
+ libgepub_dep,
+ dependency('gtk+-3.0')
+]
+
+foreach gepub_test: gepub_tests
+ exe = executable(
+ gepub_test,
+ '@0@.c'.format(gepub_test),
+ include_directories: top_inc,
+ dependencies: gepub_test_dep
+ )
+
+ test(gepub_test, exe)
+endforeach
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]