From 442f3017543ffc770ad5d6b4391dc403abfff9bb Mon Sep 17 00:00:00 2001 From: Julian Sparber Date: Sat, 23 Sep 2017 13:48:38 +0200 Subject: [PATCH] [build] switch to meson as build system --- configure | 176 +++++++++++++++ {src => data}/org.gtk.teleportapp.gschema.xml | 0 {src => data}/teleportapp.gresource.xml | 0 meson.build | 206 ++++++++++++++++++ meson_post_install.py | 15 ++ org.gtk.teleportapp.json | 63 ++++++ src/meson.build | 114 ++++++++++ 7 files changed, 574 insertions(+) create mode 100755 configure rename {src => data}/org.gtk.teleportapp.gschema.xml (100%) rename {src => data}/teleportapp.gresource.xml (100%) create mode 100644 meson.build create mode 100644 meson_post_install.py create mode 100644 org.gtk.teleportapp.json create mode 100644 src/meson.build diff --git a/configure b/configure new file mode 100755 index 0000000..6ee3185 --- /dev/null +++ b/configure @@ -0,0 +1,176 @@ +#!/bin/bash +# configure script adapter for Meson +# Based on build-api: https://github.com/cgwalters/build-api +# Copyright 2010, 2011, 2013 Colin Walters +# Copyright 2016, 2017 Emmanuele Bassi +# Copyright 2017 Iñigo Martínez +# 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=( + ['gtk-doc']=false + ['tracing']=false +) + +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 <= 0.41.0' +) + +teleportapp_version = meson.project_version() +version_array = teleportapp_version.split('.') +teleportapp_major_version = version_array[0].to_int() +teleportapp_minor_version = version_array[1].to_int() +teleportapp_micro_version = version_array[2].to_int() + +teleportapp_gir_namespace = 'Gtd' +teleportapp_gir_version = '1.0' + +teleportapp_prefix = get_option('prefix') +teleportapp_bindir = join_paths(teleportapp_prefix, get_option('bindir')) +teleportapp_datadir = join_paths(teleportapp_prefix, get_option('datadir')) +teleportapp_includedir = join_paths(teleportapp_prefix, get_option('includedir')) +teleportapp_libdir = join_paths(teleportapp_prefix, get_option('libdir')) +teleportapp_libexecdir = join_paths(teleportapp_prefix, get_option('libexecdir')) +teleportapp_localedir = join_paths(teleportapp_prefix, get_option('localedir')) + +teleportapp_pkgdatadir = join_paths(teleportapp_datadir, meson.project_name()) +teleportapp_pkgincludedir = join_paths(teleportapp_includedir, meson.project_name()) +teleportapp_pkglibdir = join_paths(teleportapp_libdir, meson.project_name()) + +teleportapp_pluginsdir = join_paths(teleportapp_pkglibdir, 'plugins') +teleportapp_schemadir = join_paths(teleportapp_datadir, 'glib-2.0', 'schemas') + +soversion = 0 +current = 0 +revision = 0 +libversion = '@0@.@1@.@2@'.format(soversion, current, revision) + +teleportapp_debug = get_option('buildtype').contains('debug') + +cc = meson.get_compiler('c') + +config_h = configuration_data() + +config_h.set_quoted('GETTEXT_PACKAGE', meson.project_name()) + +# debug options +config_h.set('GNOME_TODO_ENABLE_DEBUG', teleportapp_debug) +config_h.set('NDEBUG', not teleportapp_debug) + +# package +set_defines = [ + ['PACKAGE', meson.project_name()], + ['PACKAGE_BUGREPORT', 'http://bugzilla.gnome.org/enter_bug.cgi?product=' + meson.project_name()], + ['PACKAGE_NAME', meson.project_name()], + ['PACKAGE_STRING', '@0@ @1@'.format(meson.project_name(), teleportapp_version)], + ['PACKAGE_TARNAME', meson.project_name()], + ['PACKAGE_URL', 'https://wiki.gnome.org/Apps/Todo'], + ['PACKAGE_VERSION', teleportapp_version], + ['VERSION', teleportapp_version], + # i18n + ['GETTEXT_PACKAGE', meson.project_name()] +] + +foreach define: set_defines + config_h.set_quoted(define[0], define[1]) +endforeach + +# headers +check_headers = [ + ['HAVE_DLFCN_H', 'dlfcn.h'], + ['HAVE_INTTYPES_H', 'inttypes.h'], + ['HAVE_LOCALE_H', 'locale.h'], + ['HAVE_MEMORY_H', 'memory.h'], + ['HAVE_STDINT_H', 'stdint.h'], + ['HAVE_STDLIB_H', 'stdlib.h'], + ['HAVE_STRINGS_H', 'strings.h'], + ['HAVE_STRING_H', 'string.h'], + ['HAVE_SYS_STAT_H', 'sys/stat.h'], + ['HAVE_SYS_TYPES_H', 'sys/types.h'], + ['HAVE_UNISTD_H', 'unistd.h'] +] + +foreach header: check_headers + config_h.set(header[0], cc.has_header(header[1])) +endforeach + +# functions +check_functions = [ + # i18n + ['HAVE_DCGETTEXT', 'dcgettext'], + ['HAVE_GETTEXT', 'gettext'], + ['HAVE_ICONV', 'iconv'] +] + +if host_machine.system().contains('darwin') + check_functions += [ + ['HAVE_CFLOCALECOPYCURRENT', 'CFLocaleCopyCurrent'], + ['HAVE_CFPREFERENCESCOPYAPPVALUE', 'CFPreferencesCopyAppValue'] + ] +endif + +foreach func: check_functions + config_h.set(func[0], cc.has_function(func[1])) +endforeach + +# compiler flags +common_flags = ['-DHAVE_CONFIG_H'] +compiler_flags = [] + +if teleportapp_debug + test_cflags = [ + '-fno-strict-aliasing', + '-Wcast-align', + '-Wdeclaration-after-statement', + '-Wformat=2', + '-Winit-self', + '-Winline', + '-Wmissing-declarations', + '-Wmissing-format-attribute', + '-Wmissing-include-dirs', + '-Wmissing-noreturn', + '-Wmissing-prototypes', + '-Wnested-externs', + '-Wno-error=unused-parameter', + '-Wno-error=missing-field-initializers', + '-Wno-missing-field-initializers', + '-Wno-unused-parameter', + '-Wold-style-definition', + '-Wpacked', + '-Wredundant-decls', + '-Wshadow', + '-Wstrict-prototypes', + '-Wswitch-enum', + '-Wundef', + '-Wunused-but-set-variable', + '-Wwrite-strings', + ] + + foreach cflag: test_cflags + if cc.has_argument(cflag) + compiler_flags += [cflag] + endif + endforeach +endif + +add_project_arguments(common_flags + compiler_flags, language: 'c') + +glib_dep = dependency('glib-2.0', version: '>= 2.43.4') +gtk_dep = dependency('gtk+-3.0', version: '>= 3.22.0') + +teleportapp_deps = [ + glib_dep, + gtk_dep, + dependency('gio-2.0', version: '>= 2.43.4'), + dependency('libsoup-2.4'), + dependency('avahi-client'), + cc.find_library('m', required: true) +] + +configure_file( + output: 'config.h', + configuration: config_h +) + +gnome = import('gnome') +i18n = import('i18n') +pkg = import('pkgconfig') + +top_inc = include_directories('.') +#src_inc = include_directories('src', 'src/engine', 'src/interfaces', 'src/notification') +src_inc = include_directories('src') + +data_dir = join_paths(meson.source_root(), 'data') +#po_dir = join_paths(meson.source_root(), 'po') + +#subdir('plugins') +subdir('src') +#subdir('data') +#subdir('po') + +#enable_gtk_doc = get_option('enable-gtk-doc') +#if enable_gtk_doc +# subdir('doc/reference') +#endif + +meson.add_install_script('meson_post_install.py') + +output = '\n teleportapp ' + teleportapp_version + '\n' +output += ' ==================\n\n' +output += ' prefix: ' + teleportapp_prefix + '\n' +output += ' compiler: ' + cc.get_id() + '\n' +output += ' global flags: ' + ' '.join(compiler_flags) + ' '.join(get_option('c_link_args')) + '\n' +output += ' release: ' + (not teleportapp_debug).to_string() + '\n' +#output += ' documentation: ' + enable_gtk_doc.to_string() + '\n' +output += ' Plugins:\n\n' +#output += ' Dark theme .............. ' + get_option('enable-dark-theme-plugin').to_string() + '\n' +#output += ' Run in Background ....... ' + get_option('enable-background-plugin').to_string() + '\n' +#output += ' Scheduled panel ......... ' + get_option('enable-scheduled-panel-plugin').to_string() + '\n' +#output += ' Score ................... ' + get_option('enable-score-plugin').to_string() + '\n' +#output += ' Today panel ............. ' + get_option('enable-today-panel-plugin').to_string() + '\n' +#output += ' Unscheduled panel ....... ' + get_option('enable-unscheduled-panel-plugin').to_string() + '\n' +#output += ' Todo.txt ................ ' + get_option('enable-teleport-txt-plugin').to_string() + '\n' +#output += ' Todoist ................. ' + get_option('enable-teleport-plugin').to_string() + '\n' +#output += ' Now type \'ninja -C ' + meson.build_root() + '\' to build ' + meson.project_name() +message(output) diff --git a/meson_post_install.py b/meson_post_install.py new file mode 100644 index 0000000..bf320a9 --- /dev/null +++ b/meson_post_install.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 + +import os +import subprocess + +install_prefix = os.environ['MESON_INSTALL_PREFIX'] +icondir = os.path.join(install_prefix, 'share', 'icons', 'hicolor') +schemadir = os.path.join(install_prefix, 'share', 'glib-2.0', 'schemas') + +if not os.environ.get('DESTDIR'): + print('Update icon cache...') + subprocess.call(['gtk-update-icon-cache', '-f', '-t', icondir]) + + print('Compiling gsettings schemas...') + subprocess.call(['glib-compile-schemas', schemadir]) diff --git a/org.gtk.teleportapp.json b/org.gtk.teleportapp.json new file mode 100644 index 0000000..ae17828 --- /dev/null +++ b/org.gtk.teleportapp.json @@ -0,0 +1,63 @@ +{ + "app-id": "org.gtk.teleportapp", + "runtime": "org.gnome.Platform", + "runtime-version": "master", + "sdk": "org.gnome.Sdk", + "command": "teleportapp", + "tags": ["devel"], + "desktop-file-name-prefix": "(Development) ", + "finish-args": [ + "--share=network", + "--share=ipc", + "--socket=x11", + "--socket=wayland", + "--filesystem=xdg-run/dconf", + "--filesystem=~/.config/dconf:ro", + "--talk-name=ca.desrt.dconf", + "--env=DCONF_USER_CONFIG_DIR=.config/dconf" + ], + "build-options" : { + "cflags": "-O2 -g", + "cxxflags": "-O2 -g", + "env": { + "V": "1" + } + }, + "cleanup": ["/include", "/lib/pkgconfig", + "/share/pkgconfig", "/share/aclocal", + "/man", "/share/man", "/share/gtk-doc", + "/share/vala", + "*.la", "*.a"], + "modules": [ + { + "name": "teleportapp", + "sources": [ + { + "type": "archive", + "url": "http://127.0.0.1:8080/teleportapp.tar.xz", + "sha256": "8456e351d41b75b906673ef08f4afe3b130b243d558b666d466e85d4f2634eeb" + } + ] + }, + { + "name": "libsoup", + "sources": [ + { + "type": "archive", + "url": "https://download.gnome.org/sources/libsoup/2.60/libsoup-2.60.0.tar.xz", + "sha256": "b324edbecda0884143c0853b4a2bd5bd37fb3761f12f293c621ff34b9acdc84c" + } + ] + }, + { + "name": "avahi-client", + "sources": [ + { + "type": "archive", + "url": "http://avahi.org/download/avahi-0.7.tar.gz", + "sha256": "57a99b5dfe7fdae794e3d1ee7a62973a368e91e414bd0dfa5d84434de5b14804" + } + ] + } + ] +} diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..a989f1f --- /dev/null +++ b/src/meson.build @@ -0,0 +1,114 @@ + +headers = files( + 'browser.h', + 'get.h', + 'publish.h', + 'server.h', + 'teleportappwin.h', + 'teleportpeer.h', + 'teleportapp.h' +) + +install_headers(headers, subdir: meson.project_name()) + + +################ +# Source files # +################ + +sources = files( + 'browser.c', + 'get.c', + 'publish.c', + 'server.c', + 'teleportapp.c', + 'teleportappwin.c', + 'teleportpeer.c', + 'main.c' +) + +sources += gnome.compile_resources( + 'gtd-resources', + join_paths(data_dir, 'teleportapp.gresource.xml'), + source_dir: [ data_dir, join_paths(meson.build_root(), 'plugins') ], + c_name: 'teleportapp', +# dependencies: plugins_confs, + export: true +) + +#enum = 'gtd-enum-types' + +#sources += gnome.mkenums( +# enum, +# sources: enum_headers, +# c_template: enum + '.c.template', +# h_template: enum + '.h.template' +#) + +incs = [ + top_inc, + include_directories( +# 'engine', +# 'provider', +# 'notification', +# 'interfaces', +# 'views' + ) +] + +cflags = [ + '-DPACKAGE_DATA_DIR="@0@"'.format(teleportapp_pkgdatadir), + '-DPACKAGE_LIB_DIR="@0@"'.format(teleportapp_pkglibdir), + '-DPACKAGE_LOCALE_DIR="@0@"'.format(teleportapp_localedir), + '-DPACKAGE_SRC_DIR="@0@"'.format(meson.current_source_dir()), + '-DUI_DATA_DIR="@0@"'.format(join_paths(teleportapp_pkgdatadir, 'style')) +] + +ldflags = [ '-Wl,--export-dynamic' ] + +#if host_machine.system().contains('linux') +# foreach ldflag: plugins_ldflags +# if cc.has_argument(ldflag) +# ldflags += ldflag +# endif +# endforeach +#endif + + +############### +# teleportapp # +############### + +teleportapp = executable( + meson.project_name(), + sources, + include_directories: incs, + dependencies: teleportapp_deps, + c_args: cflags, + #link_with: plugins_libs, + link_args: ldflags, + install: true, + install_dir: teleportapp_bindir +) + + +################### +# Private library # +################### + +libgtd = shared_library( + 'gtd', + sources: sources, + version: libversion, + soversion: soversion, + include_directories: incs, + dependencies: teleportapp_deps, + c_args: cflags +) + +libgtd_dep = declare_dependency( + link_with: libgtd, + include_directories: src_inc, + dependencies: teleportapp_deps +) +