Debian Codegraph @

m4local/stp_option.m4

raw
1 # This file is part of Gutenprint. -*- Autoconf -*-
2 # Convenience macros.
3 # Copyright 2001-2002 Roger Leigh
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
8 # any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
17 # 02111-1307, USA.
18
19 ## Table of Contents:
20 ## 1. Option handling
21 ## 2. Conditionals
22
23
24 ## ------------------ ##
25 ## 1. Option handling ##
26 ## ------------------ ##
27
28
29 ## STP_ARG_WITH_DETAILED [(NAME, [NAME_OPTION], HELP, [HELP_OPTION],
30 ## VARIABLE, DEFAULT, [OPTION_TRUE], [OPTION_FALSE])]
31 ## -------------------------------------------------------------------
32 ## Create a standardised configure option.
33 ## NAME Option name i.e. --with-foo or --enable-foo.
34 ## NAME_OPTION Optional input for use with NAME (informational).
35 ## HELP Help string to display.
36 ## HELP_OPTION Additional defaults information in addition to
37 ## DEFAULT.
38 ## VARIABLE Variable to set with command-line results.
39 ## DEFAULT Default value of VARIABLE.
40 ## OPTION_TRUE case statement body if an option is supplied.
41 ## This replaces the default actions.
42 ## OPTION_FALSE Shell commands to run if no option is supplied.
43
44 AC_DEFUN([STP_ARG_WITH_DETAILED],
45 [# create custom command-line --with option
46 AC_MSG_CHECKING([whether to $3])
47 AC_ARG_WITH($1,
48 [AC_HELP_STRING([--with-$1]m4_if([$2], , , [$2]),
49 [$3 ]m4_if([$4], , , [$4 ])[@<:@]$6[@:>@])],
50 [case "${withval}" in
51 m4_if([$7], ,[
52 yes) [$5]="yes" ; AC_MSG_RESULT(${[$5]}) ;;
53 no) [$5]="no" ; AC_MSG_RESULT(${[$5]}) ;;
54 *) AC_MSG_RESULT([unknown])
55 AC_MSG_ERROR([bad value ${withval} for --with-$1]) ;;
56 ], [$7])
57 esac],
58 [if test -z "${[$5]}" ; then
59 [$5]="$6"
60 fi
61 AC_MSG_RESULT(${[$5]}) ; m4_if([$8], , , [$8])])
62 if test -z "${[$5]}" ; then
63 [$5]="$6"
64 fi
65 ])
66
67
68 ## STP_ARG_ENABLE_DETAILED [(NAME, [NAME_OPTION], HELP, [HELP_OPTION],
69 ## VARIABLE, DEFAULT, [OPTION_TRUE], [OPTION_FALSE])]
70 ## -------------------------------------------------------------------
71 ## Create a standardised configure option.
72 ## Identical to ATP_ARG_WITH_DETAILED.
73 AC_DEFUN([STP_ARG_ENABLE_DETAILED],
74 [# create custom command-line --enable option
75 AC_MSG_CHECKING([whether to $3])
76 AC_ARG_ENABLE($1,
77 [AC_HELP_STRING([--enable-$1]m4_if([$2], , , [$2]),
78 [$3 ]m4_if([$4], , , [$4 ])[@<:@]$6[@:>@])],
79 [case "${enableval}" in
80 m4_if([$7], ,[
81 yes) [$5]="yes" ; AC_MSG_RESULT(${[$5]}) ;;
82 no) [$5]="no" ; AC_MSG_RESULT(${[$5]}) ;;
83 *) AC_MSG_RESULT([unknown])
84 AC_MSG_ERROR([bad value ${enableval} for --enable-$1]) ;;
85 ], [$7])
86 esac],
87 [if test -z "${[$5]}" ; then
88 [$5]="$6"
89 fi
90 AC_MSG_RESULT(${[$5]}) ; m4_if([$8], , , [$8])])
91 if test -z "${[$5]}" ; then
92 [$5]="$6"
93 fi
94 ])
95
96
97 ## STP_ARG_WITH (NAME, HELP, VARIABLE, DEFAULT, [OPTION_TRUE], [OPTION_FALSE])
98 ## ---------------------------------------------------------------------------
99 ## NAME Option name i.e. --with-foo or --enable-foo.
100 ## HELP Help string to display.
101 ## VARIABLE Variable to set with command-line results.
102 ## DEFAULT Default value of VARIABLE.
103 ## OPTION_TRUE case statement body if an option is supplied.
104 ## This replaces the default actions.
105 ## OPTION_FALSE shell commands to run if no option is supplied.
106 AC_DEFUN([STP_ARG_WITH],
107 [STP_ARG_WITH_DETAILED([$1], , [$2], , [$3], [$4], [$5], [$6])])
108
109 ## STP_ARG_ENABLE (NAME, HELP, VARIABLE, DEFAULT, [OPTION_TRUE], [OPTION_FALSE])
110 ## -----------------------------------------------------------------------------
111 ## Identical to STP_ARG_WITH.
112 AC_DEFUN([STP_ARG_ENABLE],
113 [STP_ARG_ENABLE_DETAILED([$1], , [$2], , [$3], [$4], [$5], [$6])])
114
115
116
117
118 ## --------------- ##
119 ## 2. Conditionals ##
120 ## --------------- ##
121
122
123 # STP_CONDITIONAL (OPTION)
124 # ------------------------
125 # Define automake conditional based on STP_ARG* results. Until
126 # automake uses autoconf traces, this breaks automake
127 AC_DEFUN([STP_CONDITIONAL],
128 [AM_CONDITIONAL(BUILD_$1, test x${BUILD_$1} = xyes)])
129
130
131 ## STP_ADD_COMPILER_ARG (ARG, COMPILER, VARIABLE)
132 ## ---------------------------------------------------------------------------
133 ## ARG Compiler option
134 ## COMPILER Compiler name
135 ## VARIABLE Variable to add option to (default CFLAGS).
136 AC_DEFUN([STP_ADD_COMPILER_ARG],[
137 AC_MSG_CHECKING(if m4_ifval([$2], [$2 ], [${CC} ])supports $1)
138 stp_acOLDCFLAGS="${CFLAGS}"
139 NCFLAGS="${m4_ifval([$3], [$3], [CFLAGS])} $1"
140 CFLAGS="$NCFLAGS -Werror"
141 AC_TRY_COMPILE(,,
142 [ AC_MSG_RESULT(yes);
143 stp_newCFLAGS="$NCFLAGS"],
144 [ AC_MSG_RESULT(no);
145 stp_newCFLAGS="$stp_acOLDCFLAGS"])
146 CFLAGS="$stp_acOLDCFLAGS"
147 m4_ifval([$3], [$3], [CFLAGS])="${stp_newCFLAGS}"
148 ])
149
150 ## STP_ADD_FIRST_COMPILER_ARG (ARGS, COMPILER, VARIABLE)
151 ## ---------------------------------------------------------------------------
152 ## ARGS Compiler options
153 ## COMPILER Compiler name
154 ## VARIABLE Variable to add option to (default CFLAGS).
155 AC_DEFUN([STP_ADD_FIRST_COMPILER_ARG],[
156 for stp_ac_arg in $1 ; do
157 stp_ac_save_CFLAGS="${m4_ifval([$3], [$3], [CFLAGS])}"
158 STP_ADD_COMPILER_ARG([${stp_ac_arg}], [$2], [$3])
159 test "${stp_ac_save_CFLAGS}" != "${m4_ifval([$3], [$3], [CFLAGS])}" && break
160 done
161 ])
162
163 ## STP_ADD_COMPILER_ARGS (ARGS, COMPILER, VARIABLE)
164 ## ---------------------------------------------------------------------------
165 ## ARGS Compiler options
166 ## COMPILER Compiler name
167 ## VARIABLE Variable to add option to (default CFLAGS).
168 AC_DEFUN([STP_ADD_COMPILER_ARGS],[
169 for stp_ac_arg in $1 ; do
170 STP_ADD_COMPILER_ARG([${stp_ac_arg}], [$2], [$3])
171 done
172 ])