summaryrefslogtreecommitdiff
path: root/m4/stp_option.m4
blob: 3c476a78c79ec69676180110e3aabd0a1bcdc606 (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
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
# This file is part of Gutenprint.                     -*- Autoconf -*-
# Convenience macros.
# Copyright 2001-2002 Roger Leigh
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
# 02111-1307, USA.


## Table of Contents:
## 1. Option handling
## 2. Conditionals


## ------------------ ##
## 1. Option handling ##
## ------------------ ##


## STP_ARG_WITH_DETAILED [(NAME, [NAME_OPTION], HELP, [HELP_OPTION],
## VARIABLE, DEFAULT, [OPTION_TRUE], [OPTION_FALSE])]
## -------------------------------------------------------------------
## Create a standardised configure option.
## NAME		Option name i.e. --with-foo or --enable-foo.
## NAME_OPTION	Optional input for use with NAME (informational).
## HELP		Help string to display.
## HELP_OPTION	Additional defaults information in addition to
##		DEFAULT.
## VARIABLE	Variable to set with command-line results.
## DEFAULT	Default value of VARIABLE.
## OPTION_TRUE	case statement body if an option is supplied.
##		This replaces the default actions.
## OPTION_FALSE Shell commands to run if no option is supplied.

AC_DEFUN([STP_ARG_WITH_DETAILED],
[# create custom command-line --with option
AC_MSG_CHECKING([whether to $3])
AC_ARG_WITH($1,
            [AC_HELP_STRING([--with-$1]m4_if([$2], , , [$2]),
              [$3 ]m4_if([$4], , , [$4 ])[@<:@]$6[@:>@])],
            [case "${withval}" in
            m4_if([$7], ,[
                yes) [$5]="yes" ; AC_MSG_RESULT(${[$5]}) ;;
                no) [$5]="no" ; AC_MSG_RESULT(${[$5]}) ;;
                *) AC_MSG_RESULT([unknown])
                   AC_MSG_ERROR([bad value ${withval} for --with-$1]) ;;
	    ], [$7])
	    esac],
            [if test -z "${[$5]}" ; then
               [$5]="$6"
             fi
             AC_MSG_RESULT(${[$5]}) ; m4_if([$8], , , [$8])])
if test -z "${[$5]}" ; then
  [$5]="$6"
fi
])


## STP_ARG_ENABLE_DETAILED [(NAME, [NAME_OPTION], HELP, [HELP_OPTION],
## VARIABLE, DEFAULT, [OPTION_TRUE], [OPTION_FALSE])]
## -------------------------------------------------------------------
## Create a standardised configure option.
## Identical to ATP_ARG_WITH_DETAILED.
AC_DEFUN([STP_ARG_ENABLE_DETAILED],
[# create custom command-line --enable option
AC_MSG_CHECKING([whether to $3])
AC_ARG_ENABLE($1,
            [AC_HELP_STRING([--enable-$1]m4_if([$2], , , [$2]),
              [$3 ]m4_if([$4], , , [$4 ])[@<:@]$6[@:>@])],
            [case "${enableval}" in
            m4_if([$7], ,[
                yes) [$5]="yes" ; AC_MSG_RESULT(${[$5]}) ;;
                no) [$5]="no" ; AC_MSG_RESULT(${[$5]}) ;;
                *) AC_MSG_RESULT([unknown])
                   AC_MSG_ERROR([bad value ${enableval} for --enable-$1]) ;;
	    ], [$7])
	    esac],
            [if test -z "${[$5]}" ; then
               [$5]="$6"
             fi
             AC_MSG_RESULT(${[$5]}) ; m4_if([$8], , , [$8])])
if test -z "${[$5]}" ; then
  [$5]="$6"
fi
])


## STP_ARG_WITH (NAME, HELP, VARIABLE, DEFAULT, [OPTION_TRUE], [OPTION_FALSE])
## ---------------------------------------------------------------------------
## NAME           Option name i.e. --with-foo or --enable-foo.
## HELP           Help string to display.
## VARIABLE       Variable to set with command-line results.
## DEFAULT        Default value of VARIABLE.
## OPTION_TRUE    case statement body if an option is supplied.
##                This replaces the default actions.
## OPTION_FALSE   shell commands to run if no option is supplied.
AC_DEFUN([STP_ARG_WITH],
[STP_ARG_WITH_DETAILED([$1], , [$2], , [$3], [$4], [$5], [$6])])

## STP_ARG_ENABLE (NAME, HELP, VARIABLE, DEFAULT, [OPTION_TRUE], [OPTION_FALSE])
## -----------------------------------------------------------------------------
## Identical to STP_ARG_WITH.
AC_DEFUN([STP_ARG_ENABLE],
[STP_ARG_ENABLE_DETAILED([$1], , [$2], , [$3], [$4], [$5], [$6])])




## --------------- ##
## 2. Conditionals ##
## --------------- ##


# STP_CONDITIONAL (OPTION)
# ------------------------
# Define automake conditional based on STP_ARG* results.  Until
# automake uses autoconf traces, this breaks automake
AC_DEFUN([STP_CONDITIONAL],
[AM_CONDITIONAL(BUILD_$1, test x${BUILD_$1} = xyes)])


## STP_ADD_COMPILER_ARG (ARG, COMPILER, VARIABLE)
## ---------------------------------------------------------------------------
## ARG            Compiler option
## COMPILER       Compiler name
## VARIABLE       Variable to add option to (default CFLAGS).
AC_DEFUN([STP_ADD_COMPILER_ARG],[
  AC_MSG_CHECKING(if m4_ifval([$2], [$2 ], [${CC} ])supports $1)
  stp_acOLDCFLAGS="${CFLAGS}"
  NCFLAGS="${m4_ifval([$3], [$3], [CFLAGS])} $1"
  CFLAGS="$NCFLAGS -Werror"
  AC_TRY_COMPILE(,,
      [ AC_MSG_RESULT(yes);
        stp_newCFLAGS="$NCFLAGS"],
      [ AC_MSG_RESULT(no);
	stp_newCFLAGS="$stp_acOLDCFLAGS"])
  CFLAGS="$stp_acOLDCFLAGS"
  m4_ifval([$3], [$3], [CFLAGS])="${stp_newCFLAGS}"
])

## STP_ADD_FIRST_COMPILER_ARG (ARGS, COMPILER, VARIABLE)
## ---------------------------------------------------------------------------
## ARGS           Compiler options
## COMPILER       Compiler name
## VARIABLE       Variable to add option to (default CFLAGS).
AC_DEFUN([STP_ADD_FIRST_COMPILER_ARG],[
  for stp_ac_arg in $1 ; do
    stp_ac_save_CFLAGS="${m4_ifval([$3], [$3], [CFLAGS])}"
    STP_ADD_COMPILER_ARG([${stp_ac_arg}], [$2], [$3])
    test "${stp_ac_save_CFLAGS}" != "${m4_ifval([$3], [$3], [CFLAGS])}" && break
  done
])

## STP_ADD_COMPILER_ARGS (ARGS, COMPILER, VARIABLE)
## ---------------------------------------------------------------------------
## ARGS           Compiler options
## COMPILER       Compiler name
## VARIABLE       Variable to add option to (default CFLAGS).
AC_DEFUN([STP_ADD_COMPILER_ARGS],[
  for stp_ac_arg in $1 ; do
    STP_ADD_COMPILER_ARG([${stp_ac_arg}], [$2], [$3])
  done
])