2092 |
23 Oct 09 |
peter |
## $Id$ |
2092 |
23 Oct 09 |
peter |
2 |
# |
4359 |
23 Aug 23 |
peter |
# Copyright (C) 2009, 2010, 2012, 2013, 2014, 2018, 2020, 2023 Peter Johansson |
2092 |
23 Oct 09 |
peter |
4 |
# |
2092 |
23 Oct 09 |
peter |
# This file is part of the yat library, http://dev.thep.lu.se/yat |
2092 |
23 Oct 09 |
peter |
6 |
# |
2092 |
23 Oct 09 |
peter |
# The yat library is free software; you can redistribute it and/or |
2092 |
23 Oct 09 |
peter |
# modify it under the terms of the GNU General Public License as |
2092 |
23 Oct 09 |
peter |
# published by the Free Software Foundation; either version 3 of the |
2092 |
23 Oct 09 |
peter |
# License, or (at your option) any later version. |
2092 |
23 Oct 09 |
peter |
11 |
# |
2092 |
23 Oct 09 |
peter |
# The yat library is distributed in the hope that it will be useful, |
2092 |
23 Oct 09 |
peter |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
2092 |
23 Oct 09 |
peter |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2092 |
23 Oct 09 |
peter |
# General Public License for more details. |
2092 |
23 Oct 09 |
peter |
16 |
# |
2092 |
23 Oct 09 |
peter |
# You should have received a copy of the GNU General Public License |
2092 |
23 Oct 09 |
peter |
# along with yat. If not, see <http://www.gnu.org/licenses/>. |
2092 |
23 Oct 09 |
peter |
19 |
# |
2092 |
23 Oct 09 |
peter |
20 |
|
2092 |
23 Oct 09 |
peter |
21 |
# |
2092 |
23 Oct 09 |
peter |
# This file contains some small useful macros. |
2092 |
23 Oct 09 |
peter |
23 |
# |
3728 |
16 Mar 18 |
peter |
# serial 4 (yat 0.16) |
2092 |
23 Oct 09 |
peter |
25 |
# |
2092 |
23 Oct 09 |
peter |
26 |
|
2092 |
23 Oct 09 |
peter |
27 |
|
2092 |
23 Oct 09 |
peter |
# YAT_ECHO_LOG(STRING) |
2725 |
18 Apr 12 |
peter |
29 |
# ==================== |
2092 |
23 Oct 09 |
peter |
# print STRING to config.log |
2092 |
23 Oct 09 |
peter |
31 |
AC_DEFUN([YAT_ECHO_LOG], |
2092 |
23 Oct 09 |
peter |
32 |
[ |
2092 |
23 Oct 09 |
peter |
33 |
AC_PREREQ([2.58]) |
2725 |
18 Apr 12 |
peter |
34 |
AS_ECHO(["$as_me:${as_lineno-$LINENO}: $1"]) >&AS_MESSAGE_LOG_FD |
2092 |
23 Oct 09 |
peter |
35 |
]) #YAT_ECHO_LOG |
2092 |
23 Oct 09 |
peter |
36 |
|
2092 |
23 Oct 09 |
peter |
37 |
|
2242 |
13 Apr 10 |
peter |
# YAT_RUN_LOG(COMMAND, [ACTION-IF-TRUE], [ACTION-IF-FALSE]) |
2725 |
18 Apr 12 |
peter |
39 |
# ========================================================= |
2092 |
23 Oct 09 |
peter |
# run COMMAND and log the output, set status in $yat_status and log |
2092 |
23 Oct 09 |
peter |
# it. If status is zero execute ACTION-IF-TRUE, else execute |
2092 |
23 Oct 09 |
peter |
# ACTION-IF-FALSE and log stderror from COMMAND |
2092 |
23 Oct 09 |
peter |
43 |
AC_DEFUN([YAT_RUN_LOG], |
2725 |
18 Apr 12 |
peter |
44 |
[ |
2092 |
23 Oct 09 |
peter |
45 |
AC_PREREQ([2.58]) |
2725 |
18 Apr 12 |
peter |
46 |
m4_pushdef([COMMAND], [$1]) |
2725 |
18 Apr 12 |
peter |
47 |
YAT_ECHO_LOG([COMMAND]) |
2725 |
18 Apr 12 |
peter |
48 |
COMMAND >&AS_MESSAGE_LOG_FD 2>conftest.err |
2725 |
18 Apr 12 |
peter |
49 |
yat_status=$? |
2092 |
23 Oct 09 |
peter |
50 |
YAT_ECHO_LOG([status: $yat_status]) |
3071 |
27 Aug 13 |
peter |
51 |
AS_IF([test $yat_status = 0], [$2], |
2092 |
23 Oct 09 |
peter |
52 |
[test -f conftest.err && cat conftest.err >&AS_MESSAGE_LOG_FD; $3]) |
2725 |
18 Apr 12 |
peter |
53 |
m4_popdef([COMMAND]) |
2725 |
18 Apr 12 |
peter |
54 |
]) #YAT_RUN_LOG |
3085 |
19 Sep 13 |
peter |
55 |
|
3085 |
19 Sep 13 |
peter |
56 |
|
3366 |
03 Dec 14 |
peter |
# YAT_SET_CONTAINS(set, value, [if-present], [if-not-present]) |
3366 |
03 Dec 14 |
peter |
58 |
# ============================================================ |
3366 |
03 Dec 14 |
peter |
# Loop over set (space-separated) and if value exists, execute |
3366 |
03 Dec 14 |
peter |
# if-present. otherwise execute if-not-present |
3366 |
03 Dec 14 |
peter |
61 |
AC_DEFUN([YAT_SET_CONTAINS], |
3366 |
03 Dec 14 |
peter |
62 |
[ |
3966 |
11 Aug 20 |
peter |
63 |
AS_IF([AS_ECHO([$1]) | tr ' ' '\n' | grep "^$2$" > /dev/null], [$3], [$4]) |
3366 |
03 Dec 14 |
peter |
64 |
]) #YAT_SET_CONTAINS |
3366 |
03 Dec 14 |
peter |
65 |
|
3366 |
03 Dec 14 |
peter |
66 |
|
3085 |
19 Sep 13 |
peter |
# YAT_VAR_REMOVE(VAR, LIST) |
3085 |
19 Sep 13 |
peter |
68 |
# ========================== |
3085 |
19 Sep 13 |
peter |
# Loop over LIST (space-separated) and for each value, remove value from VAR. |
3085 |
19 Sep 13 |
peter |
70 |
AC_DEFUN([YAT_VAR_REMOVE], |
3085 |
19 Sep 13 |
peter |
71 |
[ |
3085 |
19 Sep 13 |
peter |
72 |
AS_IF([test x"$2" != x], [ |
3085 |
19 Sep 13 |
peter |
73 |
for value in $2; do |
3085 |
19 Sep 13 |
peter |
74 |
APR_REMOVEFROM([$1], [$value]) |
3085 |
19 Sep 13 |
peter |
75 |
done |
3085 |
19 Sep 13 |
peter |
76 |
]) |
3085 |
19 Sep 13 |
peter |
77 |
]) |
3088 |
26 Sep 13 |
peter |
78 |
|
3088 |
26 Sep 13 |
peter |
# YAT_CHECK_LA_LIBS(CODE, LIBS, VALUE, VAR) |
3088 |
26 Sep 13 |
peter |
80 |
# ============================================ |
3088 |
26 Sep 13 |
peter |
# Check if we can create a libtool archive based on CODE linking with |
3088 |
26 Sep 13 |
peter |
# LIBS. If not, add VALUE to VAR. |
3088 |
26 Sep 13 |
peter |
83 |
AC_DEFUN([YAT_CHECK_LA_LIBS], |
3088 |
26 Sep 13 |
peter |
84 |
[ |
3088 |
26 Sep 13 |
peter |
85 |
save_LIBS=$LIBS |
3089 |
26 Sep 13 |
peter |
86 |
LIBS="$2" |
3088 |
26 Sep 13 |
peter |
87 |
AC_MSG_CHECKING([if libtool archive can be created with $LIBS]) |
3088 |
26 Sep 13 |
peter |
88 |
YAT_LT_LINK_LA_IFELSE([$1], |
3088 |
26 Sep 13 |
peter |
89 |
[AC_MSG_RESULT([yes])], |
3088 |
26 Sep 13 |
peter |
90 |
[AC_MSG_RESULT([no]) |
3088 |
26 Sep 13 |
peter |
91 |
$4="$$4 $3"]) |
3088 |
26 Sep 13 |
peter |
92 |
LIBS=$save_LIBS |
3088 |
26 Sep 13 |
peter |
93 |
]) |
3728 |
16 Mar 18 |
peter |
94 |
|
3728 |
16 Mar 18 |
peter |
# YAT_SEARCH_LIBS(function, libraries, [action-if-found], |
3728 |
16 Mar 18 |
peter |
# [action-if-not-found], [other-libraries]) |
3728 |
16 Mar 18 |
peter |
97 |
# ================================================================= |
3728 |
16 Mar 18 |
peter |
# Same as AC_SEARCH_LIBS, but do not append LIBS with found library |
3728 |
16 Mar 18 |
peter |
# (if-found). Found library is stored in $yat_cv_search_<function>, set |
3728 |
16 Mar 18 |
peter |
# to empty string if no library required, and set to no if no library |
3728 |
16 Mar 18 |
peter |
# found. |
3728 |
16 Mar 18 |
peter |
102 |
AC_DEFUN([YAT_SEARCH_LIBS], |
3728 |
16 Mar 18 |
peter |
103 |
[ |
3728 |
16 Mar 18 |
peter |
104 |
AS_VAR_PUSHDEF([yat_Search], [yat_cv_search_$1]) |
3728 |
16 Mar 18 |
peter |
dnl cache variable used in autoconf code (AC_SEARCH_LIBS) |
3728 |
16 Mar 18 |
peter |
106 |
AS_VAR_PUSHDEF([yat_ac_Search], [ac_cv_search_$1]) |
3728 |
16 Mar 18 |
peter |
107 |
yat_func_search_save_LIBS=$LIBS |
3728 |
16 Mar 18 |
peter |
108 |
|
3728 |
16 Mar 18 |
peter |
109 |
AC_SEARCH_LIBS([$1], [$2], [ |
3728 |
16 Mar 18 |
peter |
110 |
LIBS=$yat_func_search_save_LIBS |
3728 |
16 Mar 18 |
peter |
111 |
AS_VAR_IF([yat_ac_Search], ["none required"], [], [ |
3728 |
16 Mar 18 |
peter |
112 |
AS_VAR_COPY([yat_Search], [yat_ac_Search]) |
3728 |
16 Mar 18 |
peter |
113 |
]) |
3728 |
16 Mar 18 |
peter |
114 |
$3 |
3728 |
16 Mar 18 |
peter |
115 |
], [ |
3728 |
16 Mar 18 |
peter |
116 |
AS_VAR_COPY([yat_ac_Search], [yat_Search]) |
3728 |
16 Mar 18 |
peter |
117 |
$4 |
3728 |
16 Mar 18 |
peter |
118 |
], [$5]) |
3728 |
16 Mar 18 |
peter |
119 |
|
3728 |
16 Mar 18 |
peter |
120 |
AS_VAR_POPDEF([yat_ac_Search]) |
3728 |
16 Mar 18 |
peter |
121 |
AS_VAR_POPDEF([yat_Search]) |
3728 |
16 Mar 18 |
peter |
122 |
]) # YAT_SEARCH_LIBS |
4326 |
12 Mar 23 |
peter |
123 |
|
4326 |
12 Mar 23 |
peter |
124 |
|
4326 |
12 Mar 23 |
peter |
# YAT_AC_WRITE_TO_FILE([FILE-NAME], [CONTENT]) |
4326 |
12 Mar 23 |
peter |
126 |
# ============================================ |
4326 |
12 Mar 23 |
peter |
127 |
# |
4326 |
12 Mar 23 |
peter |
# When autoconf is run, create a file 'FILE-NAME' with CONTENT. |
4326 |
12 Mar 23 |
peter |
# Variables that need to be expanded by M4 cannot be quoted e.g. |
4326 |
12 Mar 23 |
peter |
# m4_define([my_text], [yada yada]) |
4326 |
12 Mar 23 |
peter |
# YAT_AC_WRITE_TO_FILE([foo.txt], [This is my example ]my_text[ and no less]) |
4326 |
12 Mar 23 |
peter |
132 |
# |
4326 |
12 Mar 23 |
peter |
# Within a macro definition, a dollar ($) followed by 0-9, #, @, or * |
4326 |
12 Mar 23 |
peter |
# is expanded by M4 and to avoid that one can use the pattern |
4326 |
12 Mar 23 |
peter |
# YAT_AC_WRITE_TO_FILE([foo.txt], [some prefix]$[1 and suffix]) |
4326 |
12 Mar 23 |
peter |
# which outputs: some prefix $1 and suffix |
4326 |
12 Mar 23 |
peter |
137 |
AC_DEFUN([YAT_AC_WRITE_TO_FILE], |
4326 |
12 Mar 23 |
peter |
138 |
[ |
4326 |
12 Mar 23 |
peter |
139 |
_YAT_AC_WRITE_TO_FILE([$1], [$2], [write]) |
4326 |
12 Mar 23 |
peter |
140 |
]) |
4326 |
12 Mar 23 |
peter |
141 |
|
4326 |
12 Mar 23 |
peter |
142 |
|
4326 |
12 Mar 23 |
peter |
# YAT_AC_APPEND_TO_FILE([FILE-NAME], [CONTENT]) |
4326 |
12 Mar 23 |
peter |
144 |
# ============================================= |
4326 |
12 Mar 23 |
peter |
145 |
# |
4326 |
12 Mar 23 |
peter |
# Same as YAT_AC_WRITE_TO_FILE but append to file instead |
4326 |
12 Mar 23 |
peter |
147 |
AC_DEFUN([YAT_AC_APPEND_TO_FILE], |
4326 |
12 Mar 23 |
peter |
148 |
[ |
4326 |
12 Mar 23 |
peter |
149 |
_YAT_AC_WRITE_TO_FILE([$1], [$2], [append]) |
4326 |
12 Mar 23 |
peter |
150 |
]) |
4326 |
12 Mar 23 |
peter |
151 |
|
4326 |
12 Mar 23 |
peter |
152 |
|
4326 |
12 Mar 23 |
peter |
# _YAT_AC_WRITE_TO_FILE([FILE-NAME], [CONTENT], [MODE]) |
4326 |
12 Mar 23 |
peter |
154 |
# ===================================================== |
4326 |
12 Mar 23 |
peter |
155 |
AC_DEFUN([_YAT_AC_WRITE_TO_FILE], |
4326 |
12 Mar 23 |
peter |
156 |
[m4_define([yat_DIRECTION_OP], [m4_case([$3], [write], [>], |
4326 |
12 Mar 23 |
peter |
157 |
[append], [>>], |
4326 |
12 Mar 23 |
peter |
158 |
[m4_fatal([invalid mode $3])])]) |
4326 |
12 Mar 23 |
peter |
159 |
m4_syscmd([cat ]yat_DIRECTION_OP[ $1 << '_yat_EOF' |
4326 |
12 Mar 23 |
peter |
160 |
$2 |
4326 |
12 Mar 23 |
peter |
161 |
_yat_EOF |
4326 |
12 Mar 23 |
peter |
162 |
]) |
4326 |
12 Mar 23 |
peter |
dnl abort if syscmd failed |
4326 |
12 Mar 23 |
peter |
164 |
m4_if(m4_sysval, [0], [], [m4_fatal([$0: cannot write: $1])]) |
4326 |
12 Mar 23 |
peter |
165 |
]) |