-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquickhatch.m4
187 lines (176 loc) · 7.15 KB
/
quickhatch.m4
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# quickhatch.m4
# QH_ARG_ENABLE(PARAMETER, DEFAULT_VALUE)
# ----------------------------------------------------------
# Wrapper around AC_ARG_ENABLE
# e.g.: QH_ARG_ENABLE([foo], [no])
# will generate a configure option --enable-foo. The option's argument will be
# stored in enable_foo. The default value for the option will be no.
AC_DEFUN([QH_ARG_ENABLE],
[
AC_ARG_ENABLE([m4_translit([$1], [_], [-])],
[AS_HELP_STRING([--enable-m4_translit([$1], [_], [-])],
[enable $1 (default=$2)])],
[enable_[]$1=$enableval],
[enable_[]$1=$2])
]) # QH_ARG_ENABLE
# QH_ARG_WITH(PARAMETER, DEFAULT_VALUE)
# ----------------------------------------------------------
# Wrapper around AC_ARG_WITH
# e.g.: QH_ARG_WITH([foo], [bar])
# will generate a configure option --with-foo. The option's argument will be
# stored in with_foo. The default value for the option will be bar.
AC_DEFUN([QH_ARG_WITH],
[
AC_ARG_WITH([m4_translit([$1], [_], [-])],
[AS_HELP_STRING([--with-m4_translit([$1], [_], [-])],
[with $1 (default=$2)])],
[with_[]$1=$withval],
[with_[]$1=$2])
]) # QH_ARG_WITH
# QH_ENABLE_DEBUG(VARIABLE, [DEFINE_SYMBOL])
# ------------------------------------------
# Add configure option (--enable-debug). If enabled, add compiler flags
# -g and -O0 to VARIABLE. If DEFINE_SYMBOL is given, call
# AC_DEFINE([DEFINE_SYMBOL], [1], [enable debug]).
#
AC_DEFUN([QH_ENABLE_DEBUG],
[
AC_ARG_ENABLE([debug],
[AS_HELP_STRING([--enable-debug],
[enable debug (default=no)])],
[qh_enable_debug=$enableval],
[qh_enable_debug=no])
AS_IF([test "x$qh_enable_debug" = xyes],
[gl_WARN_ADD([-g], [$1])
gl_WARN_ADD([-O0], [$1])
m4_ifval([$2], [AC_DEFINE([$2], [1], [enable debug])])])
]) # QH_ENABLE_DEBUG
# QH_ENABLE_WARN_ERROR([VARIABLE = WARN_CFLAGS/WARN_CXXFLAGS])
# ------------------------------------------------------------
# Add configure option (--enable-warn-error) to make the compiler treat
# warnings as errors. If enabled, add -Werror to VARIABLE which defaults to
# WARN_CFLAGS/WARN_CXXFLAGS.
#
AC_DEFUN([QH_ENABLE_WARN_ERROR],
[
AC_ARG_ENABLE([warn-error],
[AS_HELP_STRING([--enable-warn-error],
[treat compiler warnings as errors (default=no)])],
[qh_enable_warn_error=$enableval],
[qh_enable_warn_error=no])
AS_IF([test "x$qh_enable_warn_error" = xyes],
[gl_WARN_ADD([-Werror], [$1])])
]) # QH_ENABLE_WARN_ERROR
# QH_MANYWARN_ALL_GCC([VARIABLE = WARN_CFLAGS/WARN_CXXFLAGS],
# [NOWARN_VARIABLE = QH_NOWARN])
# -----------------------------------------------------------
# Add all documented GCC warning parameters to variable VARIABLE
# which defaults to WARN_CFLAGS/WARN_CXXFLAGS. Exclude warnings
# contained in NOWARN_VARIABLE which defaults to QH_NOWARN.
#
AC_DEFUN([QH_MANYWARN_ALL_GCC],
[
gl_MANYWARN_ALL_GCC([qh_all_warnings])
gl_MANYWARN_COMPLEMENT([qh_warnings],
[$qh_all_warnings],
[m4_if([$2], [], [$QH_NOWARN], [$$2])])
for qh_warn in $qh_warnings; do
gl_WARN_ADD([$qh_warn], [$1])
done
]) # QH_MANYWARN_ALL_GCC
# QH_PKG_CHECK_EXISTS(MODULE, SYSTEM-PACKAGE)
# ----------------------------------------------------------
# Call PKG_CHECK_EXISTS with MODULE. If MODULE does not
# exist, call AC_MSG_ERROR with a message indicating that
# SYSTEM-PACKAGE could not be found.
#
AC_DEFUN([QH_PKG_CHECK_EXISTS],
[
AC_REQUIRE([PKG_PROG_PKG_CONFIG])
AC_MSG_CHECKING([for pkg-config module $1])
PKG_CHECK_EXISTS([$1],
[AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([no])
AC_MSG_ERROR([Could not find system package $2])])
]) # QH_PKG_CHECK_EXISTS
# QH_RPM_VERSION_RELEASE('VERSION RELEASE',
# [VERSION_VARIABLE = QH_RPM_VERSION],
# [RELEASE_VARIABLE = QH_RPM_RELEASE])
# ----------------------------------------------------------
# Set variables containing RPM Version and Release tags.
AC_DEFUN([QH_RPM_VERSION_RELEASE],
[
m4_define([qh_vr], m4_split($1))
AC_SUBST(m4_if([$2], [], [QH_RPM_VERSION], [$$2]), [m4_argn([1], qh_vr)])
AC_SUBST(m4_if([$3], [], [QH_RPM_RELEASE], [$$3]), [m4_argn([2], qh_vr)])
]) # QH_RPM_VERSION_RELEASE
# QH_VAR_ENSURE(VARIABLE, DESCRIPTION, VALUE-IF-NOT-SET)
# ----------------------------------------------------------
# Ensure the literal shell VARIABLE is set, and make it
# precious by passing to AC_ARG_VAR along with DESCRIPTION.
# If not set, set the contents to the shell expansion of
# VALUE-IF-NOT-SET.
AC_DEFUN([QH_VAR_ENSURE],
[
AC_ARG_VAR([$1],[$2])
AC_MSG_CHECKING([if $1 is set])
AS_VAR_SET_IF([$1],
[AC_MSG_RESULT([$$1])],
[AC_MSG_RESULT([no])
AS_ECHO_N(['setting $1 to default value... '])
AS_VAR_SET([$1],[$3])
AS_IF([test "x$$1" = x],
[AC_MSG_RESULT([empty])
AC_MSG_WARN([$1 set to empty value!])],
[AC_MSG_RESULT([$$1])])])
]) # QH_VAR_ENSURE
# QH_REQUIRE_PROG(VARIABLE, PROGS-TO-CHECK, DESCRIPTION)
# ----------------------------------------------------------
# Ensure one of the programs PROGS-TO-CHECK exists in PATH. Set VARIABLE to
# absolute path of the first program found in PROGS-TO-CHECK, and make it
# precious by passing to AC_ARG_VAR along with DESCRIPTION.
AC_DEFUN([QH_REQUIRE_PROG],
[
AC_ARG_VAR([$1],[$3])
AC_PATH_PROGS([$1],[$2])
AS_IF([test "x$$1" = x], [AC_MSG_ERROR([failed to find program: $2])])
]) # QH_REQUIRE_PROG
# QH_COMPILER_C_VERSION_MAJOR(VARIABLE, DESCRIPTION, COMPILER)
# ----------------------------------------------------------
# Set VARIABLE to value of C COMPILER's major version number, and make it
# precious by passing to AC_ARG_VAR along with DESCRIPTION.
# Supported compilers: clang, gcc
AC_DEFUN([QH_COMPILER_C_VERSION_MAJOR],
[
AC_ARG_VAR([$1],[$2])
AC_MSG_CHECKING([if $1 is set])
AS_VAR_SET_IF([$1],
[AC_MSG_RESULT([$$1])],
[AC_MSG_RESULT([no])
AC_LANG_PUSH([C])
AS_VAR_COPY([_qh_cc], [CC])
AS_VAR_SET([CC], [$3])
AS_ECHO_N(['setting $1 to computed value... '])
AS_CASE([$3],
[*gcc*], [AC_COMPUTE_INT([$1], [__GNUC__])],
[*clang*], [AC_COMPUTE_INT([$1], [__clang_major__])],
[AC_MSG_ERROR([unsupported compiler: $3])])
AS_IF([test "x$$1" = x],
[AC_MSG_RESULT([empty])
AC_MSG_WARN([$1 set to empty value!])],
[AC_MSG_RESULT([$$1])])
AS_VAR_COPY([CC], [_qh_cc])
AC_LANG_POP([C])])
]) # QH_COMPILER_C_VERSION_MAJOR
# QH_OS_RELEASE
# ----------------------------------------------------------
# Find the system os-release file and source it.
AC_DEFUN([QH_OS_RELEASE],
[
AC_CHECK_FILE([/etc/os-release],
[. /etc/os-release],
[AC_CHECK_FILE([/usr/lib/os-release],
[. /usr/lib/os-release],
[AC_MSG_ERROR([failed to find os-release file])])]
)
]) # QH_OS_RELEASE