1dnl
2dnl PAC_RUN_LOG mimics _AC_RUN_LOG which is autoconf internal routine.
3dnl We also make sure PAC_RUN_LOG can be used in AS_IF, so the last
4dnl test command should have terminating ]), i.e. without newline before ]).
5dnl
6AC_DEFUN([PAC_RUNLOG],[
7{ AS_ECHO(["$as_me:$LINENO: $1"]) >&AS_MESSAGE_LOG_FD
8  (eval $1) 2>&AS_MESSAGE_LOG_FD
9  ac_status=$?
10  AS_ECHO(["$as_me:$LINENO: \$? = $ac_status"]) >&AS_MESSAGE_LOG_FD
11  test $ac_status = 0; }])
12dnl
13dnl PAC_COMMAND_IFELSE is written to replace AC_TRY_EVAL with added logging
14dnl to config.log, i.e. AC_TRY_EVAL does not log anything to config.log.
15dnl If autoconf provides AC_COMMAND_IFELSE or AC_EVAL_IFELSE,
16dnl AC_COMMAND_IFELSE dnl should be replaced by the official autoconf macros.
17dnl
18dnl PAC_COMMAND_IFELSE(COMMMAND,[ACTION-IF-RUN-OK],[ACTION-IF-RUN-FAIL])
19dnl
20AC_DEFUN([PAC_COMMAND_IFELSE],[
21dnl Should use _AC_DO_TOKENS but use AC_RUN_LOG instead
22dnl because _AC_XX is autoconf's undocumented macro.
23AS_IF([PAC_RUNLOG([$1])],[
24    $2
25],[
26    AS_ECHO(["$as_me: program exited with status $ac_status"]) >&AS_MESSAGE_LOG_FD
27    m4_ifvaln([$3],[
28        (exit $ac_status)
29        $3
30    ])
31])
32])
33dnl
34dnl
35dnl
36AC_DEFUN([PAC_EVAL_IFELSE],[
37dnl Should use _AC_DO_TOKENS but use AC_RUN_LOG instead
38dnl because _AC_XX is autoconf's undocumented macro.
39AS_IF([PAC_RUNLOG([$$1])],[
40    $2
41],[
42    AS_ECHO(["$as_me: program exited with status $ac_status"]) >&AS_MESSAGE_LOG_FD
43    m4_ifvaln([$3],[
44        (exit $ac_status)
45        $3
46    ])
47])
48])
49dnl
50dnl
51dnl
52AC_DEFUN([PAC_RUNLOG_IFELSE],[
53dnl pac_TESTLOG is the internal temporary logfile for this macro.
54pac_TESTLOG="pac_test.log"
55rm -f $pac_TESTLOG
56PAC_COMMAND_IFELSE([$1 > $pac_TESTLOG],[
57    ifelse([$2],[],[],[$2])
58],[
59    AS_ECHO(["*** $1 :"]) >&AS_MESSAGE_LOG_FD
60    cat $pac_TESTLOG >&AS_MESSAGE_LOG_FD
61    ifelse([$3],[],[],[$3])
62])
63rm -f $pac_TESTLOG
64])
65dnl
66dnl
67dnl
68dnl PAS_VAR_COPY -  A portable layer that mimics AS_VAR_COPY when it is not
69dnl                 defined as in older autoconf, e.g. 2.63 and older.
70dnl                 This macro is absolutely necessary, because AS_VAR_GET in
71dnl                 some newer autoconf, e.g. 2.64, seems to be totally broken,
72dnl                 or behave very different from older autoconf, i.e. 2.63.
73dnl
74AC_DEFUN([PAS_VAR_COPY],[
75m4_ifdef([AS_VAR_COPY], [AS_VAR_COPY([$1],[$2])], [$1=AS_VAR_GET([$2])])
76])
77dnl
78dnl
79dnl
80dnl PAC_VAR_PUSHVAL(VARNAME, [LastSavedValue]))
81dnl
82dnl Save the content of the shell variable, VARNAME, onto a stack.
83dnl The saved value of VARNAME is restorable with respect to the nesting
84dnl of the macro.
85dnl
86dnl The Last saved value of VARNAME on the stack is stored in shell variable
87dnl pac_LastSavedValueOf_$VARNAME if the 2nd argument is NOT supplied.
88dnl If the 2nd argument is present, the last saved value will be stored
89dnl in the 2nd argument instead.
90dnl
91dnl The First saved value of VARNAME on the stack is stored in shell variable
92dnl dnl pac_FirstSavedValueOf_$VARNAME.
93dnl
94AC_DEFUN([PAC_VAR_PUSHVAL],[
95# START of PUSHVAL
96dnl define local m4-name pac_stk_level.
97AS_VAR_PUSHDEF([pac_stk_level], [pac_stk_$1_level])
98AS_VAR_SET_IF([pac_stk_level],[
99    dnl autoconf < 2.64 does not have AS_VAR_ARITH, so use expr instead.
100    AS_VAR_SET([pac_stk_level], [`expr $pac_stk_level + 1`])
101],[
102    AS_VAR_SET([pac_stk_level], [0])
103])
104dnl AS_ECHO_N(["PUSHVAL: pac_stk_level = $pac_stk_level, "])
105dnl Save the content of VARNAME, i.e. $VARNAME, onto the stack.
106AS_VAR_SET([pac_stk_$1_$pac_stk_level],[$$1])
107AS_VAR_IF([pac_stk_level], [0], [
108    dnl Save the 1st pushed value of VARNAME as pac_FirstSavedValueOf_$VARNAME
109    PAS_VAR_COPY([pac_FirstSavedValueOf_$1],[pac_stk_$1_$pac_stk_level])
110])
111ifelse([$2],[],[
112    dnl Save the last pushed value of VARNAME as pac_LastSavedValueOf_$VARNAME
113    PAS_VAR_COPY([pac_LastSavedValueOf_$1],[pac_stk_$1_$pac_stk_level])
114    dnl AS_ECHO(["pac_LastSavedValueOf_$1 = $pac_LastSavedValueOf_$1"])
115],[
116    dnl Save the last pushed value of VARNAME as $2
117    PAS_VAR_COPY([$2],[pac_stk_$1_$pac_stk_level])
118    dnl AS_ECHO(["$2 = $$2"])
119])
120AS_VAR_POPDEF([pac_stk_level])
121# END of PUSHVAL
122])
123dnl
124dnl
125dnl
126dnl PAC_VAR_POPVAL(VARNAME)
127dnl
128dnl Restore variable, VARNAME, from the stack.
129dnl This macro is safe with respect to the nesting.
130dnl Some minimal checking of nesting balance of PAC_VAR_PUSH[POP]VAL()
131dnl is done here.
132dnl
133AC_DEFUN([PAC_VAR_POPVAL],[
134# START of POPVAL
135dnl define local m4-name pac_stk_level.
136AS_VAR_PUSHDEF([pac_stk_level], [pac_stk_$1_level])
137AS_VAR_SET_IF([pac_stk_level],[
138    AS_VAR_IF([pac_stk_level],[-1],[
139        AC_MSG_WARN(["Imbalance of PUSHVAL/POPVAL of $1"])
140    ],[
141        dnl AS_ECHO_N(["POPVAL: pac_stk_level = $pac_stk_level, "])
142        PAS_VAR_COPY([$1],[pac_stk_$1_$pac_stk_level])
143        dnl AS_ECHO(["popped_val = $$1"])
144        dnl autoconf < 2.64 does not have AS_VAR_ARITH, so use expr instead.
145        AS_VAR_SET([pac_stk_level], [`expr $pac_stk_level - 1`])
146    ])
147],[
148    AC_MSG_WARN(["Uninitialized PUSHVAL/POPVAL of $1"])
149])
150AS_VAR_POPDEF([pac_stk_level])
151# END of POPVAL
152])
153dnl
154dnl
155dnl
156dnl PAC_COMPILE_IFELSE_LOG is a wrapper around AC_COMPILE_IFELSE with the
157dnl output of ac_compile to a specified logfile instead of AS_MESSAGE_LOG_FD
158dnl
159dnl PAC_COMPILE_IFELSE_LOG(logfilename, input,
160dnl                        [action-if-true], [action-if-false])
161dnl
162dnl where input, [action-if-true] and [action-if-false] are used
163dnl in AC_COMPILE_IFELSE(input, [action-if-true], [action-if-false]).
164dnl This macro is nesting safe.
165dnl
166AC_DEFUN([PAC_COMPILE_IFELSE_LOG],[
167dnl
168dnl Instead of defining our own ac_compile and do AC_TRY_EVAL
169dnl on these variables.  We modify ac_compile used by AC_*_IFELSE
170dnl by piping the output of the command to a logfile.  The reason is that
171dnl 1) AC_TRY_EVAL is discouraged by Autoconf. 2) defining our ac_compile
172dnl could mess up the usage and order of *CFLAGS, LDFLAGS and LIBS in
173dnl these commands, i.e. deviate from how GNU standard uses these variables.
174dnl
175dnl Replace ">&AS_MESSAGE_LOG_FD" by "> FILE 2>&1" in ac_compile.
176dnl Save a copy of ac_compile on a stack
177dnl which is safe through nested invocations of this macro.
178PAC_VAR_PUSHVAL([ac_compile])
179dnl Modify ac_compile based on the unmodified ac_compile.
180ac_compile="`echo $pac_FirstSavedValueOf_ac_compile | sed -e 's|>.*$|> $1 2>\&1|g'`"
181AC_COMPILE_IFELSE([$2],[
182    ifelse([$3],[],[:],[$3])
183],[
184    ifelse([$4],[],[:],[$4])
185])
186dnl Restore the original ac_compile from the stack.
187PAC_VAR_POPVAL([ac_compile])
188])
189dnl
190dnl
191dnl
192dnl PAC_LINK_IFELSE_LOG is a wrapper around AC_LINK_IFELSE with the
193dnl output of ac_link to a specified logfile instead of AS_MESSAGE_LOG_FD
194dnl
195dnl PAC_LINK_IFELSE_LOG(logfilename, input,
196dnl                     [action-if-true], [action-if-false])
197dnl
198dnl where input, [action-if-true] and [action-if-false] are used
199dnl in AC_LINK_IFELSE(input, [action-if-true], [action-if-false]).
200dnl This macro is nesting safe.
201dnl
202AC_DEFUN([PAC_LINK_IFELSE_LOG],[
203dnl
204dnl Instead of defining our own ac_link and do AC_TRY_EVAL
205dnl on these variables.  We modify ac_link used by AC_*_IFELSE
206dnl by piping the output of the command to a logfile.  The reason is that
207dnl 1) AC_TRY_EVAL is discouraged by Autoconf. 2) defining our ac_link
208dnl could mess up the usage and order of *CFLAGS, LDFLAGS and LIBS in
209dnl these commands, i.e. deviate from how GNU standard uses these variables.
210dnl
211dnl Replace ">&AS_MESSAGE_LOG_FD" by "> FILE 2>&1" in ac_link.
212dnl Save a copy of ac_link on a stack
213dnl which is safe through nested invocations of this macro.
214PAC_VAR_PUSHVAL([ac_link])
215dnl Modify ac_link based on the unmodified ac_link.
216ac_link="`echo $pac_FirstSavedValueOf_ac_link | sed -e 's|>.*$|> $1 2>\&1|g'`"
217dnl
218AC_LINK_IFELSE([$2],[
219    ifelse([$3],[],[:],[$3])
220],[
221    ifelse([$4],[],[:],[$4])
222])
223dnl Restore the original ac_link from the stack.
224PAC_VAR_POPVAL([ac_link])
225])
226dnl
227dnl
228dnl
229dnl PAC_COMPLINK_IFELSE (input1, input2, [action-if-true], [action-if-false])
230dnl
231dnl where input1 and input2 are either AC_LANG_SOURCE or AC_LANG_PROGRAM
232dnl enclosed input programs.
233dnl
234dnl The macro first compiles input1 and uses the object file created
235dnl as part of LIBS during linking.  This macro is nesting safe.
236dnl
237AC_DEFUN([PAC_COMPLINK_IFELSE],[
238AC_COMPILE_IFELSE([$1],[
239    PAC_RUNLOG([mv conftest.$OBJEXT pac_conftest.$OBJEXT])
240    PAC_VAR_PUSHVAL([LIBS])
241    LIBS="pac_conftest.$OBJEXT $pac_FirstSavedValueOf_LIBS"
242    AC_LINK_IFELSE([$2],[
243        ifelse([$3],[],[:],[$3])
244    ],[
245        ifelse([$4],[],[:],[$4])
246    ])
247    PAC_VAR_POPVAL([LIBS])
248    rm -f pac_conftest.$OBJEXT
249],[
250    ifelse([$4],[],[:],[$4])
251])
252])
253