-
Notifications
You must be signed in to change notification settings - Fork 2
/
not-autoshell.m4
957 lines (891 loc) · 30.9 KB
/
not-autoshell.m4
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
dnl **************************************************************************
dnl _ _ _ ___ _ _ _
dnl | \ | | | | / _ \ | | | | | |
dnl | \| | ___ | |_ / /_\ \_ _| |_ ___ | |_ ___ ___ | |___
dnl | . ` |/ _ \| __| | _ | | | | __/ _ \| __/ _ \ / _ \| / __|
dnl | |\ | (_) | |_ | | | | |_| | || (_) | || (_) | (_) | \__ \
dnl \_| \_/\___/ \__| \_| |_/\__,_|\__\___/ \__\___/ \___/|_|___/
dnl
dnl A collection of useful m4 macros for GNU Autotools
dnl
dnl -- Released under GNU GPL3 --
dnl
dnl https://github.com/madmurphy/not-autotools
dnl **************************************************************************
dnl **************************************************************************
dnl S H E L L - A G N O S T I C M 4 A B S T R A C T I O N S
dnl **************************************************************************
dnl NS_SETVARS(var1[, val1][, var2[, val2][, ... varN[, valN]]])
dnl **************************************************************************
dnl
dnl M4 sugar to set the value of many shell variables altogether
dnl
dnl Same as `var1=val1 var2=val2 ... varN=valN`.
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.0.1
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_SETVARS],
[m4_if([$#], [0], [],
[AS_VAR_SET([$1], [$2])[]m4_if([$#], [1], [], [$#], [2], [],
[m4_newline()NS_SETVARS(m4_shift2($@))])])])
dnl NS_GETVAR(var)
dnl **************************************************************************
dnl
dnl M4 sugar to get the value of a shell variable
dnl
dnl Same as `$var`.
dnl
dnl Example:
dnl
dnl NS_SETVARS([MY_MESSAGE], ['This is a test'])
dnl AC_MSG_NOTICE([My message --> NS_GETVAR([MY_MESSAGE])])
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.1.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_GETVAR],
[AS_LITERAL_WORD_IF([$1], [${$1}], [$(eval echo "\${$1}")])])
dnl NS_GETOUT(command)
dnl **************************************************************************
dnl
dnl M4 sugar to get the output of a command
dnl
dnl Same as `$(command)`. This macro works exactly like `m4_esyscmd()`, but
dnl instead of executing a command during the `autoreconf` process, it
dnl executes it during the `configure` process, when all M4 macros have been
dnl already expanded. The returned value cannot therefore be stored in another
dnl macro, but must be stored in a shell variable.
dnl
dnl Example:
dnl
dnl AC_MSG_NOTICE([Today is NS_GETOUT([date])])
dnl AC_MSG_NOTICE([NS_GETOUT([echo 'This is a test'])])
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_GETOUT], [@S|@@{:@$1@:}@])
dnl NS_UNSET(var1[, var2[, var3[, ... varN]]])
dnl **************************************************************************
dnl
dnl Like `AS_UNSET()`, but allows to unset many variables altogether
dnl
dnl For example:
dnl
dnl NS_SETVARS([FIRST_VAR], ['first value'],
dnl [SECOND_VAR], ['second value'],
dnl [THIRD_VAR], ['third value'])
dnl
dnl NS_UNSET([FIRST_VAR], [SECOND_VAR], [THIRD_VAR])
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.0.1
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_UNSET],
[m4_if([$#], [0], [],
[AS_UNSET(m4_normalize([$1]))])[]m4_if([$#], [1], [],
[m4_newline()[]NS_UNSET(m4_shift($@))])])
dnl NS_MOVEVAR(destination, source)
dnl **************************************************************************
dnl
dnl Copies the value of `source` into the shell variable `destination`, then
dnl unsets `source` if this is set
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.0.1
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_MOVEVAR],
[AS_VAR_COPY([$1], [$2])[]m4_newline()[]AS_UNSET([$2])])
dnl NS_REPLACEVAR(destination, source)
dnl **************************************************************************
dnl
dnl If `source` is set, copies the value of `source` into the shell variable
dnl `destination` then unsets `source`; if `source` is not set but
dnl `destination` is set, unsets `destination`
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.1.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_REPLACEVAR],
[AS_VAR_SET_IF([$2],
[AS_VAR_COPY([$1], [$2])[]m4_newline()[]AS_UNSET([$2])],
[AS_UNSET([$1])])])
dnl NS_IF(test1, run1[, test2, run2[, testN, runN]][, run-if-false])
dnl **************************************************************************
dnl
dnl Shell `if` / `else`
dnl
dnl This macro is a clone of `AS_IF()` written with the main purpose of being
dnl safely used by the `NS_PP_IF()` macro families. It has been designed as M4
dnl sugar to be used internally by the **Not Autotools** project, but can be
dnl safely invoked by the final user. Usage is identical to `AS_IF()`.
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_IF],
[m4_if([$#], [0], [],
[$#], [1], [],
[$#], [2], [if [$1]
then :
$2
fi],
[$#], [3],
[if [$1]
then :
$2[]m4_ifnblank([$3], [
else :
$3])
fi],
[if [$1]
then :
$2
el[]NS_IF(m4_shift2($@))])])
dnl NS_PP_IF(macro, test1, run1[, test2, run2[, testN, runN]][, run-if-false])
dnl **************************************************************************
dnl
dnl Shell `if` / `else`, preprocessing each `runN` argument with `macro`
dnl
dnl Example:
dnl
dnl AS_VAR_SET([TESTNUM], [31])
dnl
dnl NS_PP_IF([AC_MSG_NOTICE],
dnl [test "${TESTNUM}" -eq 44],
dnl [Number is 44],
dnl [test "${TESTNUM}" -eq 31],
dnl [Number is 31],
dnl [Invalid number])
dnl
dnl Prints:
dnl
dnl configure: Number is 31
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: shell code
dnl Requires: `NS_IF()`
dnl Version: 1.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_PP_IF],
[NS_IF(m4_shift(m4_for([__argn__], [3], m4_eval([(($# + 1) >> 1) << 1]),
[2], [, m4_argn(m4_decr(__argn__), $@), $1(m4_argn(__argn__,
$@))])[])[]m4_if(m4_eval([($# >> 1) << 1]), [$#],
[, $1(m4_argn($#, $@))]))])
dnl NS_STDOUT([text])
dnl **************************************************************************
dnl
dnl A version of `AS_ECHO()` guaranteed to output immediatelly to the Standard
dnl Output
dnl
dnl As in `AS_ECHO()` the `text` argument is passed verbatim, without shell
dnl quoting. For a version that treats the `text` argument in the same way as
dnl `AC_MSG_NOTICE()` does, please see `NS_STDOUT_UNQUOTED()`.
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_STDOUT],
[echo $1])
dnl NS_STDOUT_UNQUOTED([text])
dnl **************************************************************************
dnl
dnl A version of `AS_ECHO()` guaranteed to output immediatelly to the Standard
dnl Output, with backquote expansion protection
dnl
dnl This is a quote-safe version of `NS_STDOUT()`. The `text` argument does
dnl not need shell quotes, which will be escaped if found.
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_STDOUT_UNQUOTED],
[echo "_AS_QUOTE([$1])"])
dnl NS_STRING_IF(test1, str1[, test2, str2[, testN, strN]][, string-if-false])
dnl **************************************************************************
dnl
dnl A ternary-operator-like macro for shell strings
dnl
dnl Example:
dnl
dnl AS_VAR_SET([TESTNUM], ['31'])
dnl
dnl AS_VAR_SET([NUMSTATUS],
dnl NS_STRING_IF([test "${TESTNUM}" -eq 44],
dnl ['valid'],
dnl [test "${TESTNUM}" -eq 31],
dnl ['mostly valid'],
dnl ["invalid (${TESTNUM})"]))
dnl
dnl AC_MSG_NOTICE([Status is "${NUMSTATUS}"])
dnl
dnl Prints:
dnl
dnl configure: Status is "mostly valid"
dnl
dnl The `strN` arguments are passed verbatim, without shell quoting. For a
dnl version that treats the `strN` arguments in the same way as
dnl `AC_MSG_NOTICE()` does, please see `NS_STRING_IF_UNQUOTED()`.
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: shell code
dnl Requires: `NS_PP_IF()` and `NS_STDOUT()`
dnl Version: 1.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_STRING_IF],
["@S|@@{:@{ NS_PP_IF([NS_STDOUT], $@) }@:}@"])
dnl NS_STRING_IF_UNQUOTED(test1, str1[, testN, strN][, string-if-false])
dnl **************************************************************************
dnl
dnl A ternary-operator-like macro for shell strings, with backquote expansion
dnl protection
dnl
dnl This is a quote-safe version of `NS_STRING_IF()`. The `strN` arguments do
dnl not need shell quotes, which will be escaped if found.
dnl
dnl Example:
dnl
dnl AS_VAR_SET([NUMSTATUS],
dnl NS_STRING_IF_UNQUOTED([test "${TESTNUM}" -eq 44],
dnl [valid],
dnl [test "${TESTNUM}" -eq 31],
dnl [mostly valid],
dnl [invalid (${TESTNUM})]))
dnl
dnl AC_MSG_NOTICE([Status is "${NUMSTATUS}"])
dnl
dnl Prints:
dnl
dnl configure: Status is "mostly valid"
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: shell code
dnl Requires: `NS_PP_IF()` and `NS_STDOUT_UNQUOTED()`
dnl Version: 1.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_STRING_IF_UNQUOTED],
["@S|@@{:@{ NS_PP_IF([NS_STDOUT_UNQUOTED], $@) }@:}@"])
dnl NS_FOR(initialization, statement)
dnl **************************************************************************
dnl
dnl M4 sugar to create a "for" shell loop
dnl
dnl For example:
dnl
dnl # Iterate over all `configure` arguments and check if `--docdir` has
dnl # been given
dnl NS_FOR([_this_arg_],
dnl [AS_CASE([${_this_arg_}], [--docdir=*], [
dnl AS_VAR_SET([is_auto_docdir], [no])
dnl NS_BREAK
dnl ])])
dnl
dnl AS_IF([test "x${is_auto_docdir}" != xno],
dnl [AC_MSG_NOTICE([Using default value for <docdir>])],
dnl [AC_MSG_NOTICE([Using user-given value for <docdir>])])
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_FOR],
[{ for $1; do[]m4_newline()$2[]m4_newline()done }])
dnl NS_WHILE(initialization, statement)
dnl **************************************************************************
dnl
dnl M4 sugar to create a "while" shell loop
dnl
dnl See `NS_FOR()` for an example -- the syntax is identical.
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_WHILE],
[{ while $1; do[]m4_newline()$2[]m4_newline()done }])
dnl NS_UNTIL(initialization, statement)
dnl **************************************************************************
dnl
dnl M4 sugar to create an "until" shell loop
dnl
dnl See `NS_FOR()` for an example -- the syntax is identical.
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_UNTIL],
[{ until $1; do[]m4_newline()$2[]m4_newline()done }])
dnl NS_BREAK()
dnl **************************************************************************
dnl
dnl M4 sugar that expands to a shell "break" command, to be used within loops
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.0.0
dnl Author: madmurphy
dnl
AC_DEFUN([NS_BREAK],
[m4_newline()break;m4_newline()])
dnl NS_CONTINUE()
dnl **************************************************************************
dnl
dnl M4 sugar that expands to a shell "continue" command, to be used within
dnl loops
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.0.0
dnl Author: madmurphy
dnl
AC_DEFUN([NS_CONTINUE],
[m4_newline()continue;m4_newline()])
dnl NS_TEST_EQ(left1, right1[, left2, right2[, ... leftN, rightN]])
dnl **************************************************************************
dnl
dnl Checks if all equality tests have succeeded and triggers `true` or `false`
dnl accordingly
dnl
dnl For example,
dnl
dnl AS_VAR_SET([first], [yes])
dnl AS_VAR_SET([second], [no])
dnl
dnl AS_IF([NS_TEST_EQ(
dnl [${first}], [yes],
dnl [${second}], [no])],
dnl [AC_MSG_NOTICE([Test passed])],
dnl [AC_MSG_NOTICE([Test not passed])])
dnl
dnl will print
dnl
dnl Test passed
dnl
dnl To understand how the macro works, the following code
dnl
dnl NS_TEST_EQ([one], [two], [three], [four])
dnl
dnl expands to
dnl
dnl test "?one?three" = "?two?four"
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.0.1
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_TEST_EQ],
[m4_if([$#], [0], [:], [$#], [1], [:], [$#], [2],
[test "_AS_QUOTE([[?$1]])" != "_AS_QUOTE([[?$2]])"],
[NS_TEST_EQ([$1?$3], [$2?$4]m4_if([$#], [3], [], [$#], [4], [],
[, m4_shift3(m4_shift($@))]))])])
dnl NS_TEST_NE(left1, right1[, left2, right2[, ... leftN, rightN]])
dnl **************************************************************************
dnl
dnl Checks if at least one equality test has failed and triggers `true` or
dnl `false` accordingly
dnl
dnl For example,
dnl
dnl AS_VAR_SET([first], [yes])
dnl AS_VAR_SET([second], [no])
dnl
dnl AS_IF([NS_TEST_NE(
dnl [${first}], [yes],
dnl [${second}], [no])],
dnl [AC_MSG_NOTICE([Test passed])],
dnl [AC_MSG_NOTICE([Test not passed])])
dnl
dnl will print
dnl
dnl Test not passed
dnl
dnl All arguments do not need shell quotes, which will be escaped if found.
dnl
dnl To understand how the macro works, the following code
dnl
dnl NS_TEST_NE([one], [two], [three], [four])
dnl
dnl expands to
dnl
dnl test "?one?three" != "?two?four"
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.0.1
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_TEST_NE],
[m4_if([$#], [0], [:], [$#], [1], [:], [$#], [2],
[test "_AS_QUOTE([[?$1]])" != "_AS_QUOTE([[?$2]])"],
[NS_TEST_NE([$1?$3], [$2?$4]m4_if([$#], [3], [], [$#], [4], [],
[, m4_shift3(m4_shift($@))]))])])
dnl NS_TEST_AEQ(string1, string2[, string3[, ... stringN]])
dnl **************************************************************************
dnl
dnl Check if all arguments expand to the same string and triggers `true` or
dnl `false` accordingly
dnl
dnl For example,
dnl
dnl AC_HEADER_STDBOOL
dnl
dnl AC_CHECK_HEADERS([stddef.h stdint.h stdio.h stdlib.h])
dnl
dnl AS_IF([NS_TEST_AEQ([yes],
dnl [${ac_cv_header_stdio_h}], [${ac_cv_header_stddef_h}],
dnl [${ac_cv_header_stdbool_h}], [${ac_cv_header_stdint_h}],
dnl [${ac_cv_header_stdlib_h}])],
dnl [AC_MSG_NOTICE([Test passed])],
dnl [AC_MSG_ERROR([Test not passed])])
dnl
dnl will likely print
dnl
dnl Test passed
dnl
dnl All arguments do not need shell quotes, which will be escaped if found.
dnl
dnl To understand how the macro works, the following code
dnl
dnl NS_TEST_AEQ([one], [two], [three], [four])
dnl
dnl expands to
dnl
dnl test "?two?three?four" != "?one?one?one"
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.0.2
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_TEST_AEQ],
[m4_if([$#], [0], [:], [$#], [1], [:],
[test "_AS_QUOTE(m4_dquote([?]m4_joinall([?], m4_shift($@))))" = "_AS_QUOTE(m4_dquote(m4_for([], [2], [$#], [1], [[?$1]])))"])])
dnl NS_TEST_NAE(string1, string2[, string3[, ... stringN]])
dnl **************************************************************************
dnl
dnl Check if all arguments do **not** expand to the same string and triggers
dnl `true` or `false` accordingly
dnl
dnl For example,
dnl
dnl AC_HEADER_STDBOOL
dnl
dnl AC_CHECK_HEADERS([stddef.h stdint.h stdio.h stdlib.h])
dnl
dnl AS_IF([NS_TEST_NAE([yes],
dnl [${ac_cv_header_stdio_h}], [${ac_cv_header_stddef_h}],
dnl [${ac_cv_header_stdbool_h}], [${ac_cv_header_stdint_h}],
dnl [${ac_cv_header_stdlib_h}])],
dnl [AC_MSG_ERROR([Test not passed])],
dnl [AC_MSG_NOTICE([Test passed])])
dnl
dnl will likely print
dnl
dnl Test passed
dnl
dnl All arguments do not need shell quotes, which will be escaped if found.
dnl
dnl To understand how the macro works, the following code
dnl
dnl NS_TEST_NAE([one], [two], [three], [four])
dnl
dnl expands to
dnl
dnl test "?two?three?four" != "?one?one?one"
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.0.2
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_TEST_NAE],
[m4_if([$#], [0], [:], [$#], [1], [:],
[test "_AS_QUOTE(m4_dquote([?]m4_joinall([?], m4_shift($@))))" != "_AS_QUOTE(m4_dquote(m4_for([], [2], [$#], [1], [[?$1]])))"])])
dnl NS_TEXT_WRAP(text[, max-width=79])
dnl **************************************************************************
dnl
dnl M4 sugar to wrap a text into a fixed-width column
dnl
dnl This macro is similar to the Unix `fmt` command, but it is implemented
dnl using only `sed`. The `text` argument is passed verbatim, without shell
dnl quoting. For a version that treats the `text` argument in the same way as
dnl `AC_MSG_NOTICE()` does, please see `NS_TEXT_WRAP_UNQUOTED()`.
dnl
dnl For example, the following code:
dnl
dnl AS_VAR_SET([INCIPIT],
dnl ['Lorem ipsum dolor sit amet, consectetur adipiscing elit.'])
dnl
dnl NS_TEXT_WRAP(["${INCIPIT}"' Phasellus sit amet enim ac tellus aliquam
dnl lacinia. Nullam iaculis imperdiet lorem, ac consectetur nisi vulputate
dnl et. Proin a eros at orci pharetra fringilla non accumsan nulla. Fusce
dnl sem dolor, facilisis ac vestibulum a, lacinia sed arcu.'], [40])
dnl
dnl will generate the following shell output:
dnl
dnl Lorem ipsum dolor sit amet, consectetur
dnl adipiscing elit. Phasellus sit amet enim
dnl ac tellus aliquam lacinia. Nullam
dnl iaculis imperdiet lorem, ac consectetur
dnl nisi vulputate et. Proin a eros at orci
dnl pharetra fringilla non accumsan nulla.
dnl Fusce sem dolor, facilisis ac vestibulum
dnl a, lacinia sed arcu.
dnl
dnl The shell code produced by this macro is safely contained within curly
dnl brackets, so that its output can be easily captured or piped, as in the
dnl following example,
dnl
dnl AS_VAR_SET([FOO],
dnl ["$(NS_TEXT_WRAP(['Hello world!'], [6]))"])
dnl
dnl AS_ECHO("${FOO}")
dnl
dnl which will print the following text:
dnl
dnl Hello
dnl world!
dnl
dnl If `text` does not contain any shell expansions you should use
dnl `AS_ECHO(['m4_text_wrap(m4_quote(m4_bpatsubst([TEXT GOES HERE], ['], ['\\''])),,, [MAX-WIDTH GOES HERE])'])`
dnl instead of `NS_TEXT_WRAP()`, so that the `configure` script receives a
dnl literal instead of a `sed` substitution to perform each time it is run.
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.0.1
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_TEXT_WRAP], [{
AC_REQUIRE([AC_PROG_SED])
_newtxt_=$1
while :; do
_oldtxt_="${_newtxt_}"
_newtxt_="$(echo -n "${_oldtxt_}" | ${SED} '
s/^..\{'m4_default_nblank_quoted([$2], ['79'])'\}/&\x00/;
s/^\(\S\+\)\x00\(\S*\)\s\|\(^\|\s\)\(\S*\)\x00/\1\2\x00\4/;
s/^\x00//;
s/\x00/\n/;
')"
test "x${_newtxt_}" != "x${_oldtxt_}" || break
done
echo "${_newtxt_}"
}])
dnl NS_TEXT_WRAP_UNQUOTED(text[, max-width=79])
dnl **************************************************************************
dnl
dnl M4 sugar to wrap a text into a fixed-width column, with backquote
dnl expansion protection
dnl
dnl This is a quote-safe version of `NS_TEXT_WRAP()`. The `text` argument does
dnl not need shell quotes, which will be escaped if found.
dnl
dnl For example, the following code:
dnl
dnl AS_VAR_SET([INCIPIT],
dnl ['Lorem ipsum dolor sit amet, consectetur adipiscing elit.'])
dnl
dnl NS_TEXT_WRAP_UNQUOTED([${INCIPIT} Phasellus sit amet enim ac tellus
dnl aliquam lacinia. Nullam iaculis imperdiet lorem, ac consectetur nisi
dnl vulputate et. Proin a eros at orci pharetra fringilla non accumsan
dnl nulla. Fusce sem dolor, facilisis ac vestibulum a, lacinia sed arcu.],
dnl [40])
dnl
dnl will generate the following shell output:
dnl
dnl Lorem ipsum dolor sit amet, consectetur
dnl adipiscing elit. Phasellus sit amet enim
dnl ac tellus aliquam lacinia. Nullam
dnl iaculis imperdiet lorem,ac consectetur
dnl nisi vulputate et. Proin a eros at orci
dnl pharetra fringilla non accumsan nulla.
dnl Fusce sem dolor,facilisis ac vestibulum
dnl a,lacinia sed arcu.
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: shell code
dnl Requires: `NS_TEXT_WRAP()`
dnl Version: 1.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_TEXT_WRAP_UNQUOTED],
[m4_if([$#], [0],
[NS_TEXT_WRAP],
[NS_TEXT_WRAP(["]m4_dquote(_AS_QUOTE([[$1]]))["]m4_if([$#], [1], [], [, $2]))])])
dnl NS_TEXT_WRAP_CENTER(text[, max-width=60[, screen-width=79]])
dnl **************************************************************************
dnl
dnl M4 sugar to wrap a text into a centered fixed-width column
dnl
dnl This macro calls `NS_TEXT_WRAP()` and then centers each line. The `text`
dnl argument is passed verbatim, without shell quoting.
dnl
dnl For example, the following code:
dnl
dnl AS_VAR_SET([INCIPIT],
dnl ['Lorem ipsum dolor sit amet, consectetur adipiscing elit.'])
dnl
dnl NS_TEXT_WRAP_CENTER(["${INCIPIT}"' Phasellus sit amet enim ac tellus
dnl aliquam lacinia. Nullam iaculis imperdiet lorem, ac consectetur nisi
dnl vulputate et. Proin a eros at orci pharetra fringilla non accumsan
dnl nulla. Fusce sem dolor, facilisis ac vestibulum a, lacinia sed arcu.'],
dnl [40], [70])
dnl
dnl will generate the following shell output:
dnl
dnl Lorem ipsum dolor sit amet, consectetur
dnl adipiscing elit. Phasellus sit amet enim
dnl ac tellus aliquam lacinia. Nullam
dnl iaculis imperdiet lorem, ac consectetur
dnl nisi vulputate et. Proin a eros at orci
dnl pharetra fringilla non accumsan nulla.
dnl Fusce sem dolor, facilisis ac vestibulum
dnl a, lacinia sed arcu.
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: shell code
dnl Requires: `NS_TEXT_WRAP()`
dnl Version: 1.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_TEXT_WRAP_CENTER],
[{ NS_TEXT_WRAP([$1], m4_ifblank([$2], [['60']], [[$2]])) | while read _line_; do test "${@%:@_line_}" -ge m4_ifblank([$3], ['79'], [$3]) && echo "${_line_}" || echo "$(printf "%$(expr '(' m4_ifblank([$3], ['79'], [$3]) '-' "${@%:@_line_}" ')' '/' 2)s")${_line_}"
done; }])
dnl NS_LITERAL_HEREDOC(content[, end-keyword])
dnl **************************************************************************
dnl
dnl M4 sugar to launch `cat << 'END_HEREDOC' ...`
dnl
dnl Example
dnl
dnl NS_LITERAL_HEREDOC([
dnl Welcome to the build system of Foo package.
dnl
dnl If you need help, please type ./configure --help
dnl ])
dnl
dnl By default, the end keyword chosen is `NS_END_HEREDOC`. You can use a
dnl different keyword by using the optional `end-keyword` argument.
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_LITERAL_HEREDOC],
[{ cat << 'm4_default_nblank_quoted([$2], [NS_END_HEREDOC])'m4_newline()$1[]m4_newline()m4_default_nblank_quoted([$2], [NS_END_HEREDOC])[]m4_newline() }])
dnl NS_HEREDOC(content[, end-keyword])
dnl **************************************************************************
dnl
dnl M4 sugar to launch `cat << END_HEREDOC ...`
dnl
dnl Example
dnl
dnl NS_HEREDOC([
dnl Welcome to the build system of Foo package.
dnl
dnl If you need help, please type ${0} --help
dnl ])
dnl
dnl By default, the end keyword chosen is `NS_END_HEREDOC`. You can use a
dnl different keyword by using the optional `end-keyword` argument.
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_HEREDOC],
[{ cat << m4_default_nblank_quoted([$2], [NS_END_HEREDOC])[]m4_newline()$1[]m4_newline()m4_default_nblank_quoted([$2], [NS_END_HEREDOC])[]m4_newline() }])
dnl NS_CATCH(shell-code[, stdout-var-name[, stderr-var-name]])
dnl **************************************************************************
dnl
dnl Execute custom shell code and save `stdout` and `stderr` into shell
dnl variables
dnl
dnl Both `stdout-var-name` and `stderr-var-name` can be left empty, and in
dnl that case the respective file descriptor will be normally flushed.
dnl Alternatively, they can be set to a hyphen (`-`), and in that case the
dnl respective file descriptor will be redirected to `/dev/null`.
dnl
dnl A few examples:
dnl
dnl # Save both `stdout` and `stderr` into two variables
dnl NS_CATCH([
dnl echo 'This is stderr' 1>&2
dnl echo 'This is stdout'
dnl ], [MY_STDOUT], [MY_STDERR])
dnl
dnl # Save `stdout` into a variable and silence `stderr`
dnl NS_CATCH([
dnl echo 'This is stderr' 1>&2
dnl echo 'This is stdout'
dnl ], [MY_STDOUT], [-])
dnl
dnl # Save `stdout` into a variable and print `stderr` normally
dnl NS_CATCH([
dnl echo 'This is stderr' 1>&2
dnl echo 'This is stdout'
dnl ], [MY_STDOUT])
dnl
dnl # Save `stderr` into a variable and silence `stdout`
dnl NS_CATCH([
dnl echo 'This is stderr' 1>&2
dnl echo 'This is stdout'
dnl ], [-], [MY_STDERR])
dnl
dnl # Save `stderr` into a variable and print `stdout` normally
dnl NS_CATCH([
dnl echo 'This is stderr' 1>&2
dnl echo 'This is stdout'
dnl ], [], [MY_STDERR])
dnl
dnl # Silence both `stdout` and `stderr`
dnl NS_CATCH([
dnl echo 'This is stderr' 1>&2
dnl echo 'This is stdout'
dnl ], [-], [-])
dnl
dnl # Silence `stderr`, print only `stdout`
dnl NS_CATCH([
dnl echo 'This is stderr' 1>&2
dnl echo 'This is stdout'
dnl ], [], [-])
dnl
dnl # Silence `stdout`, print only `stderr`
dnl NS_CATCH([
dnl echo 'This is stderr' 1>&2
dnl echo 'This is stdout'
dnl ], [-])
dnl
dnl # Print both `stdout` and `stderr` normally
dnl NS_CATCH([
dnl echo 'This is stderr' 1>&2
dnl echo 'This is stdout'
dnl ])
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl NOTE: `NS_CATCH()` incorporates an answer of mine on stackoverflow
dnl (https://stackoverflow.com/a/59592881, "10. The POSIX-compliant
dnl version #2").
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_CATCH],
[m4_if([$2$3], [],
[{m4_newline()[]$1[]m4_newline()}],
[$2$3], [--],
[{m4_newline(){m4_newline()[]$1[]m4_newline()} 1> /dev/null 2>&1[]m4_newline()}],
[$2], [],
[m4_if([$3], [-],
[{m4_newline(){m4_newline()[]$1[]m4_newline()} 2> /dev/null[]m4_newline()}],
[{m4_newline()[]AS_VAR_SET([$3], ["$({]m4_newline()[$1]m4_newline()[} 3>&2 2>&1 1>&3 3>&-)"])[]m4_newline()} 2>&1])],
[$2], [-],
[m4_if([$3], [],
[{m4_newline(){m4_newline()[]$1[]m4_newline()} 1> /dev/null[]m4_newline()}],
[{m4_newline()[]AS_VAR_SET([$3], ["$({]m4_newline()[$1]m4_newline()[} 3>&2 2>&1 1>&3 3>&-)"])[]m4_newline()} 2> /dev/null])],
[$3], [],
[AS_VAR_SET([$2], ["$({]m4_newline()[$1]m4_newline()[})"])],
[$3], [-],
[AS_VAR_SET([$2], ["$({]m4_newline()[$1]m4_newline()[} 2> /dev/null)"])],
[# See https://stackoverflow.com/a/59592881
__sep__=$'\cZ'
{
IFS=$'\n'"${__sep__}" read -r -d "${__sep__}" "$2";
IFS=$'\n'"${__sep__}" read -r -d "${__sep__}" "$3";
(IFS=$'\n'"${__sep__}" read -r -d "${__sep__}" __errno__; exit ${__errno__});
} <<__NA_EOF__
$((printf "${__sep__}%s${__sep__}%d${__sep__}" "$(((({ {m4_newline()[]$1[]m4_newline()}m4_newline()[]echo "${?}" 1>&3-; } | cut -z -d"${__sep__}" -f1 | tr -d '\0' 1>&4-) 4>&2- 2>&1- | cut -z -d"${__sep__}" -f1 | tr -d '\0' 1>&4-) 3>&1- | exit "$(cat)") 4>&1-)" "${?}" 1>&2) 2>&1)
__NA_EOF__
AS_UNSET([__sep__])
])])
dnl **************************************************************************
dnl NOTE: The `NS_` prefix (which stands for "Not autoShell") is used with
dnl the purpose of avoiding collisions with the default Autotools
dnl prefixes `AC_`, `AM_`, `AS_`, `AX_`, `LT_`.
dnl **************************************************************************
dnl EOF