summaryrefslogtreecommitdiff
path: root/m4/libo_externals.m4
blob: 7f2b04305c4795a82d6e70d15a1bdf7149eb0954 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
dnl -*- Mode: Autoconf; tab-width: 4; indent-tabs-mode: nil; fill-column: 102 -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# <$1 lowercase variable part - used for variables and configure switches>
# <$2 uppercase variable part - used for configure.ac and make variables>
# <$3 pkg-config query string>
# [$4 if optional, default to: enabled, disabled or fixed (default: fixed)]
# [$5 which is preferred: (fixed-|test-)system or (fixed-)internal or system-if-linux (default: internal)]
# [$6 ignore $with_system_libs: TRUE or blank (default: blank/false)]
#
# $4 fixed: fixed-enabled, as fixed-disabled makes no sense.
# $5 test-system: follows $test_system_$1, ignores $with_system_libs; no configure switch
#
# Used configure.ac variables:
#  - $2_(CFLAGS|LIBS)_internal: must be filled to match the internal build
#  - enable_$1: should normally not be set manually; use test_$1 instead
#  - found_$1: other tests already provided external $2_CFLAGS and $2_LIBS
#  - test_$1: set to no, if the feature shouldn't be tested at all
#  - test_system_$1: set to no, if the system library should not be used
#
# There is currently the AC_SUBST redundancy of
#   (SYSTEM_$2,TRUE) == (,$(filter $2,$(BUILD_TYPE)))
#

m4_define([csm_default_with], [
    if test "${with_system_$1+set}" != set -a "${with_system_libs+set}" = set -a "$3" != TRUE; then
        with_system_$1="$with_system_libs";
    else
        with_system_$1="$2"
    fi
])

m4_define([csm_check_required], [
    m4_ifblank([$2],[m4_fatal([$][$1 ($2) must not be blank and $4])])
    m4_if([$2],[$3],,[m4_fatal([$][$1 ($2) $3 must be $4])])
])

AC_DEFUN([libo_CHECK_SYSTEM_MODULE], [
# validate arguments as possible
csm_check_required([1],[$1],m4_tolower([$1]),[lowercase])
csm_check_required([2],[$2],m4_toupper([$2]),[uppercase])
m4_ifblank([$3],[m4_fatal([$][3 is the pkg-config query and must not be blank])])
m4_if([$6],[TRUE],[],[m4_ifnblank([$6],[m4_fatal([$][6 must be TRUE or blank])])])
m4_if(
    [$4],[enabled],[
        AC_ARG_ENABLE([$1],
            AS_HELP_STRING([--disable-$1],[Disable $1 support.]),
        ,[enable_$1="yes"])
    ],[$4],[disabled],[
        AC_ARG_ENABLE([$1],
            AS_HELP_STRING([--enable-$1],[Enable $1 support.]),
        ,[enable_$1="no"])
    ],[
        m4_if([$4],[fixed],,[m4_ifnblank([$4],
              [m4_fatal([$$4 ($4) must be "enabled", "disabled", "fixed" or empty (=fixed)])])])
        enable_$1="yes";
])
m4_if(
    [$5],[system],[
        AC_ARG_WITH(system-$1,
            AS_HELP_STRING([--without-system-$1],[Build and bundle the internal $1.]),
        ,[csm_default_with($1,yes,$6)])
    ],[$5],[test-system],[
        with_system_$1="$test_system_$1"
    ],[$5],[fixed-system],[
        with_system_$1=yes
    ],[$5],[fixed-internal],[
        with_system_$1=no
    ],[$5],[system-if-linux],[
        AC_ARG_WITH(system-$1,
            AS_HELP_STRING([--with-system-$1],[Use $1 from the operating system.]),
        ,[case "$_os" in
            Linux)
                with_system_nss=yes
            ;;
            *)
                with_system_nss=no
            ;;
          esac])
    ],[
        m4_if([$5],[internal],,[m4_ifnblank([$5],
              [m4_fatal([$$5 ($5) must be "(fixed-|test-)system", "(fixed-)internal", "system-if-linux" or empty (=internal)])])])
        AC_ARG_WITH(system-$1,
            AS_HELP_STRING([--with-system-$1],[Use $1 from the operating system.]),
        ,[csm_default_with($1,no,$6)])
])

AC_MSG_CHECKING([which $1 to use])
if test "$test_$1" != no -a "$found_$1" != yes -a "$enable_$1" != no; then
    ENABLE_$2=TRUE
    if test "$with_system_$1" = yes -a "$test_system_$1" != no; then
        AC_MSG_RESULT([external])
        SYSTEM_$2=TRUE
        PKG_CHECK_MODULES([$2], [$3])
        $2_CFLAGS=$(printf '%s' "${$2_CFLAGS}" | sed -e "s/-I/${ISYSTEM?}/g")
        FilterLibs "${$2_LIBS}"
        $2_LIBS="$filteredlibs"
    else
        AC_MSG_RESULT([internal])
        SYSTEM_$2=
        $2_CFLAGS="${$2_CFLAGS_internal}"
        $2_LIBS="${$2_LIBS_internal}"
        BUILD_TYPE="$BUILD_TYPE $2"
    fi
else
    if test "$found_$1" = yes -a "$enable_$1" != no -a "$with_system_$1" = yes; then
        AC_MSG_RESULT([external])
        ENABLE_$2=TRUE
        SYSTEM_$2=TRUE
    else
        ENABLE_$2=
        SYSTEM_$2=
        $2_CFLAGS=
        $2_LIBS=
        if test "$test_$1" != no -a "$enable_$1" = no; then
            AC_MSG_RESULT([disabled])
        else
            AC_MSG_RESULT([not tested])
        fi
    fi
fi
AC_SUBST([ENABLE_$2])
AC_SUBST([SYSTEM_$2])
AC_SUBST([$2_CFLAGS])
AC_SUBST([$2_LIBS])
])

dnl vim:set shiftwidth=4 softtabstop=4 expandtab: