xorg.modules: Use a distinct checkout dir for libXfont2
[xorg-util-modular.git] / autogen-meson.sh
blobc5bdd91cdbaf5a10ec7ebfb944206e385c0f268d
1 #!/bin/bash
2 # configure script adapter for Meson
3 # Based on build-api: https://github.com/cgwalters/build-api
4 # Copyright 2010, 2011, 2013 Colin Walters <walters@verbum.org>
5 # Copyright 2016, 2017 Emmanuele Bassi
6 # Licensed under the new-BSD license (http://www.opensource.org/licenses/bsd-license.php)
8 # Build API variables:
10 # Little helper function for reading args from the commandline.
11 # it automatically handles -a b and -a=b variants, and returns 1 if
12 # we need to shift $3.
13 read_arg() {
14 # $1 = arg name
15 # $2 = arg value
16 # $3 = arg parameter
17 local rematch='^[^=]*=(.*)$'
18 if [[ $2 =~ $rematch ]]; then
19 read "$1" <<< "${BASH_REMATCH[1]}"
20 else
21 read "$1" <<< "$3"
22 # There is no way to shift our callers args, so
23 # return 1 to indicate they should do it instead.
24 return 1
28 sanitycheck() {
29 # $1 = arg name
30 # $1 = arg command
31 # $2 = arg alternates
32 local cmd=$( which $2 2>/dev/null )
34 if [ -x "$cmd" ]; then
35 read "$1" <<< "$cmd"
36 return 0
39 test -z $3 || {
40 for alt in $3; do
41 cmd=$( which $alt 2>/dev/null )
43 if [ -x "$cmd" ]; then
44 read "$1" <<< "$cmd"
45 return 0
47 done
50 echo -e "\e[1;31mERROR\e[0m: Command '$2' not found"
51 exit 1
54 sanitycheck MESON 'meson'
55 sanitycheck NINJA 'ninja' 'ninja-build'
57 declare -a enables[0]
59 while (($# > 0)); do
60 case "${1%%=*}" in
61 --prefix) read_arg prefix "$@" || shift;;
62 --bindir) read_arg bindir "$@" || shift;;
63 --sbindir) read_arg sbindir "$@" || shift;;
64 --libexecdir) read_arg libexecdir "$@" || shift;;
65 --datarootdir) read_arg datarootdir "$@" || shift;;
66 --datadir) read_arg datadir "$@" || shift;;
67 --sysconfdir) read_arg sysconfdir "$@" || shift;;
68 --libdir) read_arg libdir "$@" || shift;;
69 --mandir) read_arg mandir "$@" || shift;;
70 --includedir) read_arg includedir "$@" || shift;;
71 --enable-*) enables+=("-D${1/--enable-/}=true");;
72 --disable-*) enables+=("-D${1/--disable-/}=false");;
73 *) echo -e "\e[1;33mINFO\e[0m: Ignoring unknown option '$1'";;
74 esac
75 shift
76 done
78 # Defaults
79 test -z ${prefix} && prefix="/usr/local"
80 test -z ${bindir} && bindir=${prefix}/bin
81 test -z ${sbindir} && sbindir=${prefix}/sbin
82 test -z ${libexecdir} && libexecdir=${prefix}/bin
83 test -z ${datarootdir} && datarootdir=${prefix}/share
84 test -z ${datadir} && datadir=${datarootdir}
85 test -z ${sysconfdir} && sysconfdir=${prefix}/etc
86 test -z ${libdir} && libdir=${prefix}/lib
87 test -z ${mandir} && mandir=${prefix}/share/man
88 test -z ${includedir} && includedir=${prefix}/include
90 # The source directory is the location of this file
91 srcdir=$(dirname $0)
93 # The build directory is the current location
94 builddir=`pwd`
96 # If we're calling this file from the source directory then
97 # we automatically create a build directory and ensure that
98 # both Meson and Ninja invocations are relative to that
99 # location
100 if [[ -f "${builddir}/meson.build" ]]; then
101 mkdir -p _build
102 builddir="${builddir}/_build"
103 NINJA_OPT="-C ${builddir}"
106 # Wrapper Makefile for Ninja
107 cat > Makefile <<END
108 # Generated by configure; do not edit
110 all:
111 CC="\$(CC)" CXX="\$(CXX)" ${NINJA} ${NINJA_OPT}
113 install:
114 DESTDIR="\$(DESTDIR)" ${NINJA} ${NINJA_OPT} install
116 check:
117 ${MESON} test ${NINJA_OPT}
120 echo "Summary:"
121 echo " meson:....... ${MESON}"
122 echo " ninja:....... ${NINJA}"
123 echo " prefix:...... ${prefix}"
124 echo " bindir:...... ${bindir}"
125 echo " sbindir:..... ${sbindir}"
126 echo " libexecdir:.. ${libexecdir}"
127 echo " datarootdir:. ${datarootdir}"
128 echo " datadir:..... ${datadir}"
129 echo " sysconfdir:.. ${sysconfdir}"
130 echo " libdir:...... ${libdir}"
131 echo " mandir:...... ${mandir}"
132 echo " includedir:.. ${includedir}"
133 echo " extra: ${enables[@]}"
135 exec ${MESON} \
136 --prefix=${prefix} \
137 --libdir=${libdir} \
138 --libexecdir=${libexecdir} \
139 --datadir=${datadir} \
140 --sysconfdir=${sysconfdir} \
141 --bindir=${bindir} \
142 --includedir=${includedir} \
143 --mandir=${mandir} \
144 --default-library shared \
145 "${enables[@]}" \
146 ${builddir} \
147 ${srcdir}
149 # vim: ai ts=8 noet sts=2 ft=sh