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