[json-glib] Improve the build-api compatibility script



commit e62986163d47ac54812728e7cc545b8af0af7356
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Wed Apr 12 16:33:00 2017 +0100

    Improve the build-api compatibility script
    
    Currently, the configure script is mostly meant for the convenience of
    GNOME Continuous, but with minimal changes we can make it an appropriate
    wrapper to the autotools-like build-api.
    
    We can ensure that Meson is invoked with the location of the build
    directory, as well as the source directory; we can also ensure that the
    Makefile wrapper around Ninja is capable to calling Ninja with the
    location of the generated build.ninja file.
    
    Finally, we can generate a simple `check` target that calls `mesontest`
    in the build directory.
    
    These changes allow building JSON-GLib following the usual sequence:
    
      ./configure …
      make
      make check
      make install
    
    While keeping all the build-related files under a build directory
    (except for the generated Makefile, which can be safely ignored).

 .gitignore |    3 +++
 configure  |   26 +++++++++++++++++++++-----
 2 files changed, 24 insertions(+), 5 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index a01ee28..f68a1e0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,4 @@
 .*.swp
+*~
+Makefile
+_build
diff --git a/configure b/configure
index b2a0754..67947eb 100755
--- a/configure
+++ b/configure
@@ -2,11 +2,10 @@
 # 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 Emmanuele Bassi
+# Copyright 2016, 2017 Emmanuele Bassi
 # Licensed under the new-BSD license (http://www.opensource.org/licenses/bsd-license.php)
 
 # Build API variables:
-# buildapi-variable-require-builddir
 
 # Little helper function for reading args from the commandline.
 # it automatically handles -a b and -a=b variants, and returns 1 if
@@ -52,8 +51,8 @@ sanitycheck() {
     exit 1
 }
 
-
 sanitycheck MESON 'meson'
+sanitycheck MESONTEST 'mesontest'
 sanitycheck NINJA 'ninja' 'ninja-build'
 
 enable_docs='-Denable-gtk-doc=false'
@@ -98,15 +97,31 @@ 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}
+       CC="\$(CC)" CXX="\$(CXX)" ${NINJA} ${NINJA_OPT}
 
 install:
-       DESTDIR="\$(DESTDIR)" ${NINJA} install
+       DESTDIR="\$(DESTDIR)" ${NINJA} ${NINJA_OPT} install
+
+check:
+       ${MESONTEST} ${NINJA_OPT}
 END
 
 echo "Summary:"
@@ -138,6 +153,7 @@ exec ${MESON} \
        ${enable_docs} \
        ${enable_man} \
        ${enable_introspection} \
+       ${builddir} \
        ${srcdir}
 
 # vim: ai ts=8 noet sts=2 ft=sh


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]