]> git.draconx.ca Git - dxcommon.git/blob - tests/scripts.at
gen-strtab.awk: Add a feature to disable l10n markings.
[dxcommon.git] / tests / scripts.at
1 dnl Copyright © 2021-2023 Nick Bowler
2 dnl
3 dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
4 dnl This is free software: you are free to do what the fuck you want to.
5 dnl There is NO WARRANTY, to the extent permitted by law.
6
7 AT_BANNER([Script tests])
8
9 AT_SETUP([gen-options.awk])
10 AT_KEYWORDS([gen-options awk script scripts])
11
12 AT_DATA([options.def],
13 [[--option-only
14 --option-with-val (5)
15 --option-with-flagval (&x, 5)
16 --option-with-arg=ARG
17 some "text" goes here
18 --option-with-optional-arg[=OPTIONAL]
19
20 hello
21 -a, --option-with-sopt
22
23 -b, --option-with-sopt-and-arg=SOPTARG
24 -c, --option-with-sopt-and-optional-arg[=SOPTOPTIONAL]
25 --option-with-arg-and-val=ARGVAL (42)
26 --option-with-arg-and-flagval=ARGFLAGVAL (&a[1], 'x')
27 --option-with-optional-arg-and-val[=OPTIONALARGVAL] (54)
28 --option-with-optional-arg-and-flagval[=OPTIONALFLAGVAL] (0, 0)
29 --with-sopt
30 Here is a help string
31     that has a line randomly indented
32 # with a comment
33     @&t@
34 and a blank line
35 --with-arg=ARG
36 do stuff with ARG
37 --flagval
38 ]])
39
40 AT_CHECK([$AWK -f "$builddir/scripts/gen-options.awk" <options.def >options.h])
41
42 AT_DATA([context.h],
43 [[struct option { const char *name; int has_arg; int *flag; int val; };
44 int x, a[5];
45 ]])
46
47 # test 0: sanity test
48 AT_DATA([test0.c],
49 [[#include "context.h"
50 #include "options.h"
51
52 static const char sopts[] = SOPT_STRING;
53 static const struct option opts[] = { LOPTS_INITIALIZER, {0} };
54
55 int main(void)
56 {
57   return 0;
58 }
59 ]])
60 AT_CHECK([$CC -o test0$EXEEXT test0.c && ./test0$EXEEXT], [0], [], [ignore])
61
62 # test 1: long option names and help text
63 AT_DATA([test1.c],
64 [[#include <stdio.h>
65 #include <stdlib.h>
66
67 #include "context.h"
68 #include "options.h"
69
70 static const struct option opts[] = { LOPTS_INITIALIZER };
71
72 int main(void)
73 {
74   unsigned i;
75
76   for (i = 0; i < sizeof opts / sizeof opts[0]; i++) {
77     struct lopt_help help = { "INVALID", "INVALID" };
78
79     if (!lopt_get_help(&opts[i], &help))
80       return EXIT_FAILURE;
81
82     printf("--%s", opts[i].name);
83     if (opts[i].has_arg)
84       printf("=%s", help.arg);
85     printf("\n%s", help.desc);
86     if (help.desc[0])
87       putchar('\n');
88   }
89
90   return 0;
91 }
92 ]])
93
94 # pick out interesting bits from the definitions file
95 sed -n '/^-/s/^.*--\([[^\= @<:@]]*\).*$/\1/p' options.def >options
96 sed -n '/^-/{
97   s/[[^=]]*\(=[[^@:>@ ]]*\).*$/\1/
98   s/^[[^=]].*//
99   s/^=//
100   p
101 }' options.def >argnames
102
103 AS_ECHO(["-"]) | sed -n '1s/^-.*//p
104 1,/^-/d
105 t clear
106 :clear
107 s/^-.*//p
108 t
109 s/^#.*//
110 s/^ *//
111 t next
112 :next
113 N
114 s/\n-.*//
115 t done
116 s/\n#.*//
117 s/\n */\n/g
118 t next
119 :done
120 s/"/\\\\"/g
121 s/[[^\n]][[^\n]]*/\\"&\\"/g
122 s/^\n*//
123 s/\n*$//
124 s/\n\n*/ /g
125 p
126 ' options.def - >helptext
127
128 exec 3<options 4<argnames 5<helptext 6>expout
129 while read opt <&3 && read arg <&4 && read help <&5; do
130   if test ${arg:+y}; then
131     AS_ECHO(["--$opt=$arg"]) >&6
132   else
133     AS_ECHO(["--$opt"]) >&6
134   fi
135   eval "set x $help"; shift
136   for arg
137   do
138     AS_ECHO(["$arg"]) >&6
139   done
140 done
141 exec 3<&- 4<&- 5<&- 6>&-
142
143 AT_CHECK([$CC -o test1$EXEEXT test1.c && ./test1$EXEEXT],
144   [0], [expout], [ignore])
145
146 # test 2: short option string
147 AT_DATA([test2.c],
148 [[#include <stdio.h>
149 #include <stdlib.h>
150
151 #include "context.h"
152 #include "options.h"
153
154 int main(void)
155 {
156   struct option lopts[] = {LOPTS_INITIALIZER};
157   unsigned i, j;
158
159   for (i = 0; i < sizeof SOPT_STRING - 1; i++) {
160     if (SOPT_STRING[i] != ':') {
161       for (j = 0; j < sizeof lopts / sizeof lopts[0]; j++) {
162         if (lopts[j].val == SOPT_STRING[i]) {
163           printf("--%s ", lopts[j].name);
164           break;
165         }
166       }
167     }
168     putchar(SOPT_STRING[i]);
169     if (SOPT_STRING[i+1] != ':')
170       putchar('\n');
171   }
172 }
173 ]])
174
175 sed -n '/^-/{
176   s/=.*/:/
177   s/[[@<:@]]/:/
178   s/^-\([[^-]]\)[[^:]]*/\1/p
179   s/^-.*//p
180 }' options.def >sopts
181
182 exec 3<options 4<sopts 5>expout
183 while read lopt <&3 && read sopt <&4; do
184   if test ${sopt:+y}; then
185     AS_ECHO(["--$lopt $sopt"]) >&5
186   fi
187 done
188 exec 3<&- 4<&- 5>&-
189
190 AT_CHECK([$CC -o test2$EXEEXT test2.c && ./test2$EXEEXT],
191   [0], [expout], [ignore])
192
193 # Check that all help strings are translatable
194 sed 's/\([[^\\]]\\\)" /\1\\n\\" /g' helptext >help-po
195 exec 3<options 4<argnames 5<help-po 6>expected.po
196 while read opt <&3 && read arg <&4 && read help <&5; do
197   if test ${arg:+y}; then
198     AS_ECHO(["msgctxt \"$opt\" msgid \"$arg\""]) >&6
199   fi
200   AS_ECHO(["msgctxt \"$opt\" msgid${help:+ }$help"]) >&6
201 done
202 exec 3<&- 4<&- 5<&- 6>&-
203
204 AT_CHECK([xgettext --keyword=PN_:1c,2 options.h
205   test -f messages.po || exit 77])
206
207 LC_ALL=C sort expected.po >expout
208 AT_CHECK([sed -n '/^msgctxt/{
209 t next
210 :next
211 N
212 s/\nmsgstr.*//
213 t done
214 s/\s*""//
215 s/\n/ /
216 t next
217 :done
218 p
219 }' messages.po | LC_ALL=C sort], [0], [expout])
220
221 AT_CLEANUP
222
223 AT_SETUP([gen-strtab.awk])
224 AT_KEYWORDS([gen-strtab awk script scripts])
225
226 AT_DATA([test.def],
227 [[
228 &a world
229 &b
230 hello world
231 &c
232 hello
233 world
234 &d world\n
235 &e
236 \\not a newline
237 &f
238 \not a newline
239 &g inline
240 continued
241 &h    no\
242 newline\
243 &i
244 \   leading whitespace
245 &j oneline
246 # with a comment
247 ]])
248
249 AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" <test.def >test.h])
250
251 sed -n 's/^[[&]]\([[^ ]]*\).*/\1/p' test.def >identifiers
252
253 # test 0: sanity test
254 AT_DATA([test0.c],
255 [[#include "test.h"
256 #include <stdio.h>
257
258 int main(void)
259 {
260   printf("---\n");
261 ]])
262 exec 3<identifiers 4>>test0.c
263 while read ident <&3; do
264   AS_ECHO(['  printf("%s\n---\n", '"strtab+$ident);"]) >&4
265 done
266 AS_ECHO(['  return 0;']) >&4
267 AS_ECHO(['}']) >&4
268 exec 3<&- 4>&-
269
270 AT_CHECK([$CC -o test0$EXEEXT test0.c && ./test0$EXEEXT], [0], [---
271 world
272 ---
273 hello world
274
275 ---
276 hello
277 world
278
279 ---
280 world
281
282 ---
283 \not a newline
284
285 ---
286
287 ot a newline
288
289 ---
290 inline
291 continued
292
293 ---
294 nonewline
295 ---
296    leading whitespace
297
298 ---
299 oneline
300 ---
301 ], [ignore])
302
303 AT_CLEANUP
304
305 AT_SETUP([gen-strtab.awk @nozero option])
306 AT_KEYWORDS([gen-strtab awk script scripts])
307
308 AT_DATA([test0.def],
309 [[&hello hello
310 ]])
311 AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" <test0.def >test0.h])
312
313 AT_DATA([test1.def],
314 [[@nozero
315 &hello hello
316 ]])
317 AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" <test1.def >test1.h])
318
319 AT_DATA([test.c],
320 [[#include <stdio.h>
321 #include HEADER
322 int main(void) { printf("%d %s\n", hello, strtab+hello); return 0; }
323 ]])
324 AT_CHECK([$CC -DHEADER='"test0.h"' -o test0$EXEEXT test.c && ./test0$EXEEXT],
325   [0], [[0 hello
326 ]])
327 AT_CHECK([$CC -DHEADER='"test1.h"' -o test1$EXEEXT test.c && ./test1$EXEEXT],
328   [0], [[1 hello
329 ]])
330
331 AT_CLEANUP
332
333 AT_SETUP([gen-strtab.awk l10n options])
334 AT_KEYWORDS([gen-strtab awk script scripts])
335
336 AT_DATA([l10n.sed], dnl (
337 [[/^#/b
338 s/.*N_(\([^)]*\)).*/\1/p
339 ]])
340
341 AT_DATA([test0.def],
342 [[&a hello world
343 &b world
344 &c goodbye
345 ]])
346 AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" <test0.def >test0.h])
347 AT_CHECK([sed -n -f l10n.sed test0.h | LC_ALL=C sort], [0],
348 [["goodbye"
349 "hello world"
350 "world"
351 ]])
352
353 AT_DATA([test1.def],
354 [[&a hello world
355 &&b world
356 &&c goodbye
357 ]])
358 AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" <test1.def >test1.h])
359 AT_CHECK([sed -n -f l10n.sed test1.h], [0],
360 [["hello world"
361 ]])
362
363 AT_DATA([test.c],
364 [[#include <stdio.h>
365 #include HEADER
366
367 int main(void)
368 {
369   printf("%s %s %s\n", strtab+a, strtab+b, strtab+c);
370   return 0;
371 }
372 ]])
373
374 AT_CHECK([$CC -DHEADER='"test0.h"' -o test0$EXEEXT test.c && ./test0$EXEEXT],
375   [0], [[hello world world goodbye
376 ]])
377
378 AT_CHECK([$CC -DHEADER='"test1.h"' -o test1$EXEEXT test.c && ./test1$EXEEXT],
379   [0], [[hello world world goodbye
380 ]])
381
382
383 AT_CLEANUP
384
385 AT_SETUP([gen-tree.awk])
386 AT_KEYWORDS([gen-tree awk script scripts])
387
388 AT_DATA([tree.def],
389 [[# comment
390 ROOT0
391   r0a, r0a_OFFSET
392     r0b, r0b_OFFSET
393       r0c
394     r0d
395   r0e, r0e_OFFSET
396     r0f
397     r0g
398 # comment
399 ROOT1
400   r1a, r1a_OFFSET
401     r1b, r1b_OFFSET
402       r1b
403       r1e
404       r1b
405   r1c, r1c_OFFSET
406     r1d, r1d_OFFSET
407       r1e
408       r1b
409       r1e
410 # comment
411 ]])
412
413 AT_CHECK([$AWK -f "$builddir/scripts/gen-tree.awk" <tree.def >tree.h])
414
415 AT_DATA([test0.c],
416 [[#include "tree.h"
417 #include <stdio.h>
418
419 struct tree { unsigned id, subtree; };
420
421 static const struct tree tree0[] = {
422   ROOT0_INITIALIZER
423 };
424 static const struct tree tree1[] = {
425   ROOT1_INITIALIZER
426 };
427
428 void print_subtree(const struct tree *root, unsigned offset, int depth)
429 {
430   const struct tree *node;
431
432   for (node = &root[offset]; node->id; node++) {
433     printf("%*s%s", 2*depth, "", &tree_strtab[node->id]);
434     if (node->subtree) {
435       printf(", %s_OFFSET\n", &tree_strtab[node->id]);
436       print_subtree(root, node->subtree, depth+1);
437     } else {
438       putchar('\n');
439     }
440   }
441 }
442
443 int main(void)
444 {
445   printf("ROOT0\n");
446   print_subtree(tree0, 0, 1);
447   printf("ROOT1\n");
448   print_subtree(tree1, 0, 1);
449   return 0;
450 }
451 ]])
452 sed '/^#/d' tree.def >expout
453 AT_CHECK([$CC -o test0$EXEEXT test0.c && ./test0$EXEEXT], [0], [expout])
454
455 AT_CLEANUP
456
457 # Test the gen-tree features that avoid creating string labels for nodes.
458 AT_SETUP([gen-tree.awk @nostrtab option])
459 AT_KEYWORDS([gen-tree awk script scripts])
460
461 AT_DATA([tree.def],
462 [[@nostrtab
463 ROOT
464  a 1, a_OFFSET
465   b 1
466   c 2
467  d 2, d_OFFSET
468   e 1
469   f 2
470 ]])
471 AT_CHECK([$AWK -f "$builddir/scripts/gen-tree.awk" <tree.def >tree.h])
472
473 AT_DATA([test0.c],
474 [[float tree_strtab = 0;
475 #define a []
476 #define b []
477 #define c []
478 #define e []
479 #define f []
480 #include "tree.h"
481 #include <stdio.h>
482
483 static struct { int num, offset; } root[] = { ROOT_INITIALIZER };
484
485 int main(void)
486 {
487   unsigned i;
488   for (i = 0; i < sizeof root / sizeof root[0]; i++) {
489     printf("%d, %d\n", root[i].num, root[i].offset);
490   }
491 }
492 ]])
493
494 AT_CHECK([$CC -o test0$EXEEXT test0.c && ./test0$EXEEXT], [0],
495 [[1, 3
496 2, 6
497 0, 0
498 1, 0
499 2, 0
500 0, 0
501 1, 0
502 2, 0
503 0, 0
504 ]])
505
506 AT_DATA([flat.def],
507 [[FLAT
508  a 1
509  b 2
510  c 3
511 @nostrtab
512 ]])
513 AT_CHECK([$AWK -f "$builddir/scripts/gen-tree.awk" <flat.def >flat.h])
514
515 sed -e 's/tree\.h/flat.h/' -e 's/ROOT/FLAT/' test0.c >test1.c
516 AT_CHECK([$CC -o test1$EXEEXT test1.c && ./test1$EXEEXT], [0],
517 [[1, 0
518 2, 0
519 3, 0
520 0, 0
521 ]])
522
523 AT_CLEANUP
524
525 AT_SETUP([join.awk])
526 AT_KEYWORDS([join awk script scripts])
527
528 JOIN="$AWK -f $builddir/scripts/join.awk --"
529
530 AT_DATA([a],
531 [[1 a
532 3 a1 x
533 3 a2 x
534 5 a
535 6 a
536 8 a1 x
537 8 a2 x
538 9 a1
539 9 a2
540 9 a3
541 ]])
542
543 AT_DATA([b],
544 [[2 b
545 2 b
546 3 b y
547 4 b
548 6 b1 y
549 6 b2 y
550 7 b
551 8 b1 y
552 8 b2 y
553 ]])
554
555 AT_CHECK([$JOIN a b], [0],
556 [[3 a1 x b y
557 3 a2 x b y
558 6 a b1 y
559 6 a b2 y
560 8 a1 x b1 y
561 8 a1 x b2 y
562 8 a2 x b1 y
563 8 a2 x b2 y
564 ]])
565
566 AT_CHECK([$JOIN -v1 a b], [0],
567 [[1 a
568 5 a
569 9 a1
570 9 a2
571 9 a3
572 ]])
573
574 AT_CHECK([$JOIN -v2 a b], [0],
575 [[2 b
576 2 b
577 4 b
578 7 b
579 ]])
580
581 AT_CHECK([$JOIN -v1 -v2 a b], [0],
582 [[1 a
583 2 b
584 2 b
585 4 b
586 5 a
587 7 b
588 9 a1
589 9 a2
590 9 a3
591 ]])
592
593 AT_CHECK([$JOIN -a1 a b], [0],
594 [[1 a
595 3 a1 x b y
596 3 a2 x b y
597 5 a
598 6 a b1 y
599 6 a b2 y
600 8 a1 x b1 y
601 8 a1 x b2 y
602 8 a2 x b1 y
603 8 a2 x b2 y
604 9 a1
605 9 a2
606 9 a3
607 ]])
608
609 AT_CHECK([$JOIN -a2 a b], [0],
610 [[2 b
611 2 b
612 3 a1 x b y
613 3 a2 x b y
614 4 b
615 6 a b1 y
616 6 a b2 y
617 7 b
618 8 a1 x b1 y
619 8 a1 x b2 y
620 8 a2 x b1 y
621 8 a2 x b2 y
622 ]])
623
624 AT_CHECK([$JOIN -a1 -a2 a b], [0],
625 [[1 a
626 2 b
627 2 b
628 3 a1 x b y
629 3 a2 x b y
630 4 b
631 5 a
632 6 a b1 y
633 6 a b2 y
634 7 b
635 8 a1 x b1 y
636 8 a1 x b2 y
637 8 a2 x b1 y
638 8 a2 x b2 y
639 9 a1
640 9 a2
641 9 a3
642 ]])
643
644 AT_CHECK([$JOIN b a], [0],
645 [[3 b y a1 x
646 3 b y a2 x
647 6 b1 y a
648 6 b2 y a
649 8 b1 y a1 x
650 8 b1 y a2 x
651 8 b2 y a1 x
652 8 b2 y a2 x
653 ]])
654
655 AT_CHECK([$JOIN -v1 b a], [0],
656 [[2 b
657 2 b
658 4 b
659 7 b
660 ]])
661
662 AT_CHECK([$JOIN -v2 b a], [0],
663 [[1 a
664 5 a
665 9 a1
666 9 a2
667 9 a3
668 ]])
669
670 AT_CHECK([$JOIN -v1 -v2 b a], [0],
671 [[1 a
672 2 b
673 2 b
674 4 b
675 5 a
676 7 b
677 9 a1
678 9 a2
679 9 a3
680 ]])
681
682 AT_CHECK([$JOIN -a1 b a], [0],
683 [[2 b
684 2 b
685 3 b y a1 x
686 3 b y a2 x
687 4 b
688 6 b1 y a
689 6 b2 y a
690 7 b
691 8 b1 y a1 x
692 8 b1 y a2 x
693 8 b2 y a1 x
694 8 b2 y a2 x
695 ]])
696
697 AT_CHECK([$JOIN -a2 b a], [0],
698 [[1 a
699 3 b y a1 x
700 3 b y a2 x
701 5 a
702 6 b1 y a
703 6 b2 y a
704 8 b1 y a1 x
705 8 b1 y a2 x
706 8 b2 y a1 x
707 8 b2 y a2 x
708 9 a1
709 9 a2
710 9 a3
711 ]])
712
713 AT_CHECK([$JOIN -a1 -a2 b a], [0],
714 [[1 a
715 2 b
716 2 b
717 3 b y a1 x
718 3 b y a2 x
719 4 b
720 5 a
721 6 b1 y a
722 6 b2 y a
723 7 b
724 8 b1 y a1 x
725 8 b1 y a2 x
726 8 b2 y a1 x
727 8 b2 y a2 x
728 9 a1
729 9 a2
730 9 a3
731 ]])
732
733 AT_CHECK([echo wat | $JOIN -v1 - /dev/null], [0],
734 [[wat
735 ]])
736
737 AT_CLEANUP
738
739 m4_divert_push([PREPARE_TESTS])dnl
740 test_fix_ltdl () {
741   $PERL -e 'my $x = 42; exit $x;'; test $? = 42 || exit 77
742   $PERL -f "$srcdir/scripts/fix-ltdl.pl" "$@"
743 }
744 test_fix_gnulib () {
745   $PERL -e 'my $x = 42; exit $x;'; test $? = 42 || exit 77
746   $PERL -f "$srcdir/scripts/fix-gnulib.pl" "$@"
747 }
748 test_gnulib_mk () {
749   echo;
750   for arg
751   do
752     sed -n -f - "$srcdir/tests/data/gnulib.mk" <<EOF
753 /^## begin gnulib module $arg/,/^## end   gnulib module $arg/p
754 EOF
755   done
756 }
757 m4_divert_pop([PREPARE_TESTS])
758
759 AT_SETUP([fix-gnulib.pl SED_HEADER variables])
760
761 test_gnulib_mk gen-header >test.mk.in
762 AT_CHECK([grep SED_HEADER test.mk.in >expout || exit 99])
763 AT_CHECK([test_fix_gnulib -i test.mk.in -o test.mk || exit
764 grep SED_HEADER test.mk], [0], [expout])
765
766 AT_CLEANUP
767
768 AT_SETUP([fix-gnulib.pl %reldir% substitution])
769
770 test_gnulib_mk sys_types >test.mk.in
771 AT_CHECK([grep '%reldir%' test.mk.in >/dev/null || exit 99])
772
773 sed -n -f - test.mk.in >expout <<'EOF'
774 ${G;p;b}
775 /^## begin gnulib/,/^## end   gnulib/!b
776 /^#/{p;b}
777 s|(srcdir)|(top_srcdir)|
778 s|%reldir%|lib|
779 s|BUILT_SOURCES|gnulib_core_headers|
780 s|sys[[/_]]|lib/&|g
781 /^MOSTLYCLEANFILES/{h;b}
782 p
783 EOF
784
785 AT_CHECK([test_fix_gnulib -i test.mk.in -o test.mk || exit
786 sed -n -e '/^## begin gnulib/,/^## end   gnulib/p' \
787        -e '/CLEANFILES/p' test.mk],
788 [0], [expout])
789
790 AT_CLEANUP
791
792 AT_SETUP([fix-gnulib.pl warning removal])
793
794 AT_DATA([test.mk.in], [[
795 ## test begin
796 noinst_LTLIBRARIES += libgnu.la
797 libgnu_la_CFLAGS = $(AM_CFLAGS) $(GL_CFLAG_GNULIB_WARNINGS)
798 noinst_LIBRARIES += libgnu.a
799 libgnu_a_CFLAGS = $(AM_CFLAGS) $(GL_CFLAG_GNULIB_WARNINGS)
800 ## test end
801 ]])
802 AT_CHECK([test_fix_gnulib -i test.mk.in -o test.mk || exit
803 sed -n '/^## test begin/,/^## test end/p' test.mk], [0], [## test begin
804 EXTRA_LTLIBRARIES += libgnu.la
805 EXTRA_LIBRARIES += libgnu.a
806 ## test end
807 ])
808
809 AT_CLEANUP
810
811 AT_SETUP([fix-gnulib.pl header directory creation])
812
813 AT_DATA([extract.sed],
814 [[/AM_V_GEN/b ok
815 /gl_V_at/b ok
816 s/:.*/:/
817 h
818 b
819 :ok
820 s/'//g
821 x
822 G
823 p
824 n
825 s/[)].*/)/
826 p
827 ]])
828
829 test_gnulib_mk alloca-opt sys_types stddef >test.mk.in
830 AT_CHECK([test_fix_gnulib -i test.mk.in -o test.mk || exit
831 sed -n -f extract.sed test.mk], [0],
832 [[lib/alloca.h:
833         $(AM_V_GEN)$(MKDIR_P) lib
834         $(AM_V_at)
835 lib/sys/types.h:
836         $(AM_V_GEN)$(MKDIR_P) lib/sys
837         $(AM_V_at)
838 lib/stddef.h:
839         $(AM_V_GEN)$(MKDIR_P) lib
840         $(AM_V_at)
841 ]])
842
843 AT_CLEANUP
844
845 dnl TEST_FIND_AUTOMAKE_VER([to-check], [test-action])
846 dnl
847 dnl For each whitespace-separated version token in to-check, check if we can
848 dnl run the programs automake-VER and aclocal-VER.  The special token 'default'
849 dnl also checks the unversioned automake and aclocal (or, if set in the
850 dnl environment, $AUTOMAKE and $ACLOCAL).
851 dnl
852 dnl Then test-action is expanded such that shell variables $ac and $am refer to
853 dnl the aclocal and automake programs, and $amver is the actual version
854 dnl reported by --version.  The action should do nothing if the version is
855 dnl acceptable, or "continue" if the version is unacceptable.
856 dnl
857 dnl If an acceptable version is found, the AUTOMAKE and ACLOCAL environment
858 dnl variables are set accordingly.  Otherwise, the test group is skipped.
859 m4_define([TEST_FIND_AUTOMAKE],
860 [have_am=false
861 for am in $1; do
862   AS_CASE([$am],
863     [default], [ac=${ACLOCAL-aclocal} am=${AUTOMAKE-automake}],
864     [ac=aclocal-$am; am=automake-$am])
865   amver=`$am --version | sed -n '1s/.* //p'`
866   acver=`$ac --version | sed -n '1s/.* //p'`
867   set x $amver $acver; shift; test x"$[]#" = x"2" || continue
868   test x"$amver" = x"$acver" || continue
869   $2
870   have_am=:; break
871 done
872 AT_CHECK([$have_am || exit 77])
873 AUTOMAKE=$am; export AUTOMAKE
874 ACLOCAL=$ac; export ACLOCAL
875 AT_CHECK([$ACLOCAL --version && $AUTOMAKE --version], [0], [stdout])
876 ])
877
878 m4_define([TEST_LTDL_LIBOBJ_MANGLING],
879 [TEST_CONFIGURE_AC([[AM_INIT_AUTOMAKE([foreign subdir-objects])
880 AC_PROG_CC
881 LT_INIT
882 AC_SUBST([ltdl_LTLIBOBJS], [libltdl/test.lo])
883 AC_CONFIG_FILES([Makefile])
884 ]])
885
886 mkdir libltdl
887 AT_DATA([ltdl.mk.in], [[
888 AM_CPPFLAGS += -DSTRING=\"helloworld\"
889
890 noinst_LTLIBRARIES = libltdl/libltdl.la
891 libltdl_libltdl_la_SOURCES = libltdl/ltdl.c
892 libltdl_libltdl_la_LIBADD = $(ltdl_LTLIBOBJS)
893 libltdl_libltdl_la_DEPENDENCIES = $(ltdl_LTLIBOBJS)
894
895 EXTRA_DIST += libltdl/test.c
896 ]])
897 AT_DATA([Makefile.am], [[AM_CPPFLAGS =
898 include $(top_srcdir)/ltdl.mk
899 AM_LIBTOOLFLAGS = --quiet
900 bin_PROGRAMS = test
901 test_SOURCES =
902 test_LDADD = libltdl/libltdl.la
903 all-local: ; @printf '%s\n' $(AM_CPPFLAGS)
904 ]])
905 AT_DATA([libltdl/test.c], [[#include <stdio.h>
906 int foo(void) { printf("%s\n", STRING); return 0; }
907 ]])
908 AT_DATA([libltdl/ltdl.c], [[int foo(void); int main(void) { return foo(); }
909 ]])
910
911 AT_CHECK([test_fix_ltdl -i ltdl.mk.in -o ltdl.mk])
912 libtoolize; TEST_AUTORECONF
913 TEST_CONFIGURE([--disable-shared])
914 AT_CHECK([make -s && ./test], [0], [
915 helloworld
916 ])])
917
918 AT_SETUP([fix-ltdl.pl LIBOBJ mangling (<automake-1.16)])
919
920 TEST_FIND_AUTOMAKE([default 1.10 1.11 1.12 1.13 1.14 1.15],
921   [AS_VERSION_COMPARE(["$amver"], [1.16], [], [continue], [continue])])
922 TEST_LTDL_LIBOBJ_MANGLING
923
924 AT_CLEANUP
925
926 AT_SETUP([fix-ltdl.pl LIBOBJ mangling (>=automake-1.16)])
927
928 TEST_FIND_AUTOMAKE([default 1.16 1.17 1.18 1.19],
929   [AS_VERSION_COMPARE(["$amver"], [1.16], [continue])])
930 TEST_LTDL_LIBOBJ_MANGLING
931
932 AT_CLEANUP