-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnot-m4sugar.m4
1534 lines (1455 loc) · 47.6 KB
/
not-m4sugar.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
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
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 M 4 S U G A R E X T E N S I O N S
dnl **************************************************************************
dnl n4_lambda(macro_body)
dnl **************************************************************************
dnl
dnl Creates an anonymous macro on the fly, able to be passed as a callback
dnl argument
dnl
dnl For example,
dnl
dnl n4_lambda([Hi there! Here it's $1!])([Rose])
dnl
dnl will expand to
dnl
dnl Hi there! Here it's Rose!
dnl
dnl Or, for instance, in the following code a lambda macro instead of a named
dnl one is passed to `m4_map()`:
dnl
dnl AC_DEFUN([MISSING_PROGRAMS], [[find], [xargs], [sed]])
dnl AC_MSG_ERROR([install first m4_map([n4_lambda(["$1", ])], [MISSING_PROGRAMS])then proceed.])
dnl
dnl The code above will print:
dnl
dnl install first "find", "xargs", "sed", then proceed.
dnl
dnl By using the `n4_anon` keyword, a lambda macro can invoke itself
dnl repeatedly (recursion). For example,
dnl
dnl AC_MSG_NOTICE([n4_lambda([m4_if(m4_eval([$2 > 0]), [1], [$1[]n4_anon([$1], m4_decr([$2]))])])([Repeat me!], 4)])
dnl
dnl will print
dnl
dnl Repeat me!Repeat me!Repeat me!Repeat me!
dnl
dnl Alternatively you can use the `$0` shortcut, which expands to `n4_anon`:
dnl
dnl AC_MSG_NOTICE([n4_lambda([m4_if(m4_eval([$2 > 0]), [1], [$1[]$0([$1], m4_decr([$2]))])])([Repeat me!], 4)])
dnl
dnl The `n4_anon` keyword is available only from within the lambda macro body,
dnl works in a stack-like fashion and is fully reentrant. Do not attempt to
dnl redefine it yourself.
dnl
dnl Lambda macros can be nested within each other:
dnl
dnl n4_lambda([Hi there! n4_lambda([This is a nested lambda macro!])])
dnl
dnl However, as with any other type of macro, reading the arguments of a
dnl nested lambda macro might be difficult. Consider for example the following
dnl code snippet:
dnl
dnl n4_lambda([Hi there! Here it's $1! n4_lambda([And here it's $1!])([Charlie])])([Rose])
dnl
dnl It will print:
dnl
dnl Hi there! Here it's Rose! And here it's Rose!
dnl
dnl This is because `$1` gets replaced with `Rose` before the nested macro's
dnl arguments can expand. The only way to prevent this is by delaying the
dnl composition of `$` and `1`, so that the expansion of the argument happens
dnl at a later time. Hence,
dnl
dnl n4_lambda([Hi there! Here it's $1! n4_lambda([And here it's ][$][1][!])([Charlie])])([Rose])
dnl
dnl will finally print:
dnl
dnl Hi there! Here it's Rose! And here it's Charlie!
dnl
dnl This applies also to other argument notations, such as `$#`, `$*` and
dnl `#@`.
dnl
dnl There is no particular limit in the level of nesting reachable, except
dnl good coding practices. As an extreme example, consider the following
dnl snippet, consisting of three lambda macros nested within each other, whose
dnl innermost one is also recursive (the atypical M4 indentation is only for
dnl clarity):
dnl
dnl # Let's use `L()` as a shortcut for `n4_lambda()`...
dnl m4_define([L], m4_defn([n4_lambda]))
dnl
dnl L([
dnl This is $1 L([
dnl This is ][$][1][ L([
dnl {][$][1][}m4_if(m4_eval(][$][#][[ > 1]), [1],
dnl [n4_anon(m4_shift(]]m4_dquote([$][@])[[))])
dnl ])([internal-1], [internal-2], [internal-3], [internal-4])
dnl ])([central])
dnl ])([external])
dnl
dnl The example above will print something like this (plus some trailing
dnl spaces due to the atypical indentation):
dnl
dnl This is external
dnl This is central
dnl {internal-1}
dnl {internal-2}
dnl {internal-3}
dnl {internal-4}
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: literal
dnl Requires: nothing
dnl Version: 1.0.0
dnl Author: madmurphy
dnl Further reading: https://www.gnu.org/software/m4/manual/html_node/Composition.html
dnl
dnl **************************************************************************
m4_define([n4_lambda],
[m4_pushdef([n4_anon], [$1])[]m4_pushdef([n4_anon], [m4_popdef([n4_anon])[]$1[]m4_popdef([n4_anon])])[]n4_anon])
dnl n4_with(val, expression)
dnl **************************************************************************
dnl
dnl Expands every occurrence of `n4_this` in `expression` with `val`
dnl
dnl For example:
dnl
dnl n4_with(m4_eval(10 ** 3),
dnl [n4_this... n4_this...])
dnl
dnl => 1000... 1000...
dnl
dnl The `n4_this` keyword is fully reentrant and allows nested invocations of
dnl `n4_with()`
dnl
dnl n4_with(m4_eval(10 ** 3),
dnl [n4_this... n4_with(m4_eval(9 ** 3), [n4_this... n4_this])... n4_this...])
dnl
dnl => 1000... 729... 729... 1000...
dnl
dnl This macro is useful for expensive operations that would need otherwise to
dnl be invoked repeatedly.
dnl
dnl The keyword `n4_this` optionally supports the usage of temporary
dnl arguments:
dnl
dnl n4_with([text $1], [n4_this([a])... n4_this([b])...])
dnl => text a... text b...
dnl
dnl The following examples illustrate the different behavior of `n4_with()`
dnl depending on the presence of quotes or not in the first argument.
dnl
dnl No quoting:
dnl
dnl m4_define([counter], [0])
dnl
dnl n4_with(counter m4_define([counter], m4_incr(counter)),
dnl [n4_this n4_this n4_this n4_this n4_this n4_this...])
dnl
dnl => 0 0 0 0 0 0 ...
dnl
dnl Quoting:
dnl
dnl m4_define([counter], [0])
dnl
dnl n4_with([counter m4_define([counter], m4_incr(counter))],
dnl [n4_this n4_this n4_this n4_this n4_this n4_this...])
dnl
dnl => 0 1 2 3 4 5 ...
dnl
dnl If you need to store more than one value at a time, use `n4_let()` or
dnl `n4_qlet()` instead of `n4_with()`
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: literal
dnl Requires: nothing
dnl Version: 2.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
m4_define([n4_with],
[m4_pushdef([n4_this], [$1])$2[]m4_popdef([n4_this])])
dnl n4_let(macro-name1, val1[, ... macro-nameN, valN], expression)
dnl **************************************************************************
dnl
dnl Exactly like `n4_with()`, but allows to use infinite aliases
dnl
dnl This macro in fact creates a complete M4 scoping mechanism. See the
dnl documentation of `n4_with()` for more information.
dnl
dnl For example,
dnl
dnl n4_let([AUTHOR], [madmurphy],
dnl [DATE], m4_esyscmd_s([date +%d/%m/%Y]),
dnl [This text has been created by AUTHOR on DATE.])
dnl
dnl will print:
dnl
dnl This text has been created by madmurphy on 25/09/2019.
dnl
dnl In the example above the system call `date` will be invoked only once,
dnl regardless of how many times the keyword `DATE` appears in `expression`.
dnl
dnl As with `n4_with()`, scope nesting is fully supported. For example,
dnl
dnl n4_let([AUTHOR], [madmurphy],
dnl [DATE], m4_esyscmd_s([date +%d/%m/%Y]),
dnl [This text has been created by AUTHOR on DATE.
dnl
dnl n4_let([AUTHOR], [charlie],
dnl [...Don't forget to write an email to the real author, AUTHOR!])
dnl
dnl The real author is AUTHOR.])
dnl
dnl will print:
dnl
dnl This text has been created by madmurphy on 25/09/2019.
dnl
dnl ...Don't forget to write an email to the real author, charlie!
dnl
dnl The real author is madmurphy.
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: literal
dnl Requires: nothing
dnl Version: 2.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
m4_define([n4_let],
[m4_if([$#], [0], [], [$#], [1], [$1],
[m4_pushdef([$1], [$2])[]n4_let(m4_shift2($@))[]m4_popdef([$1])])])
dnl n4_qlet([name-val-pair1][, ... [name-val-pairN]], expression)
dnl **************************************************************************
dnl
dnl Exactly like `n4_let()`, but requires each name-value pair to be
dnl surrounded by quotes (this macro is only for clarity)
dnl
dnl For example,
dnl
dnl n4_qlet([[AUTHOR], [madmurphy]],
dnl [[DATE], m4_esyscmd_s([date +%d/%m/%Y])],
dnl [This text has been created by AUTHOR on DATE.])
dnl
dnl will print:
dnl
dnl This text has been created by madmurphy on 25/09/2019.
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: literal
dnl Requires: `n4_let()`
dnl Version: 2.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
m4_define([n4_qlet],
[n4_let(m4_reverse(m4_shift(m4_reverse($*))), m4_argn([$#], $@))])
dnl n4_has(list, check1, if-found1[, ... checkN, if-foundN[, if-not-found]])
dnl **************************************************************************
dnl
dnl Check if a list contains one or more elements
dnl
dnl Example:
dnl
dnl m4_define([MY_LIST],
dnl [[AUTUMN], [WINTER], [SUMMER]])
dnl
dnl n4_has(m4_dquote(MY_LIST),
dnl [SPRING],
dnl [SPRING found],
dnl [SUMMER],
dnl [SUMMER found],
dnl [Neither SPRING nor SUMMER can be found])
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: literal
dnl Requires: Nothing
dnl Version: 1.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
m4_define([n4_has],
[m4_if([$#], [0], [], [$#], [1], [], [$#], [2], [],
[m4_if(m4_argn(1, $1), [$2], [$3], [$#], [3], [], [$#], [4],
[m4_if(m4_count($1), [1],
[$4],
[n4_has(m4_dquote(m4_shift($1)), m4_shift($@))])],
[m4_if(m4_count($1), [1],
[n4_has([$1], m4_shift3($@))],
[n4_has(m4_dquote(m4_shift($1)), [$2], [$3],
[n4_has([$1], m4_shift3($@))])])])])])
dnl n4_has_any(list, check-list1, if-found1[, ... check-listN, if-foundN[,
dnl if-not-found]])
dnl **************************************************************************
dnl
dnl Check if a list contains one or more elements grouped in further lists
dnl
dnl This macro is very similar to `n4_has()`, but allows to group more than
dnl one element under the same conditional.
dnl
dnl For example,
dnl
dnl m4_define([MY_LIST],
dnl [[August], [September], [October]])
dnl
dnl n4_has_any(m4_dquote(MY_LIST),
dnl [[February]],
dnl [The shortest month in your list has 28 days],
dnl [[April], [June], [September], [November2]],
dnl [The shortest month in your list has 30 days],
dnl [[January], [March], [May], [July], [August], [October], [December]],
dnl [The shortest month in your list has 31 days],
dnl [Are you sure you wrote the month names correctly?])
dnl
dnl expands to
dnl
dnl The shortest month in your list has 30 days
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: literal
dnl Requires: Nothing
dnl Version: 1.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
m4_define([n4_has_any],
[m4_if([$#], [0], [], [$#], [1], [], [$#], [2], [],
[m4_if(m4_argn(1, $1), m4_argn(1, $2), [$3], [$#], [3], [], [$#], [4],
[m4_if(m4_count($1), [1],
[$4],
[m4_if(m4_count($2), [1],
[n4_has_any(m4_dquote(m4_shift($1)), m4_shift($@))],
[n4_has_any(m4_dquote(m4_shift($1)), [$2], [$3],
[n4_has_any([$1], m4_dquote(m4_shift($2)), m4_shift2($@))])])])],
[m4_if(m4_count($1), [1],
[m4_if(m4_count($2), [1],
[n4_has_any([$1], m4_shift3($@))],
[n4_has_any([$1], m4_dquote(m4_shift($2)), [$3],
[n4_has_any([$1], m4_shift3($@))])])],
[n4_has_any(m4_dquote(m4_shift($1)), [$2], [$3],
m4_if(m4_count($2), [1],
[[n4_has_any([$1], m4_shift3($@))]],
[[n4_has_any([$1], m4_dquote(m4_shift($2)), m4_shift2($@))]]))])])])])
dnl n4_case_in(text, list1, if-found1[, ... listN, if-foundN], [if-not-found])
dnl **************************************************************************
dnl
dnl Searches for the first occurrence of `text` in each comma-separated list
dnl `listN`
dnl
dnl For example,
dnl
dnl n4_case_in(NR_GET_ENV_VAR([USER]),
dnl [[rose], [madmurphy], [charlie]],
dnl [Official release],
dnl [Unofficial release])
dnl
dnl will print "Official release" if the user who generated the `configure`
dnl script was in the list above, or it will print "Unofficial release"
dnl otherwise (for the `NR_GET_ENV_VAR()` macro, see `not-autoreconf.m4`).
dnl
dnl This macro works exactly like `m4_case()`, but instead of looking for the
dnl equality of a target string with one or more other strings, it checks
dnl whether a target string is present in one or more given lists.
dnl
dnl Here is a more articulated example:
dnl
dnl n4_case_in(NR_GET_ENV_VAR([USER]),
dnl [[rose], [madmurphy], [lili], [frank]],
dnl [Official release],
dnl [[rick], [karl], [matilde]],
dnl [Semi-official release],
dnl [[jack], [charlie]],
dnl [Offensive release],
dnl [Unofficial release])
dnl
dnl `n4_case_in()` has been designed to behave like `m4_case()` when a simple
dnl string is passed instead of a list.
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: literal
dnl Requires: Nothing
dnl Version: 1.0.1
dnl Author: madmurphy
dnl Further reading: https://www.gnu.org/software/autoconf/manual/autoconf-2.71/html_node/Conditional-constructs.html#index-m4_005fcase-1
dnl
dnl **************************************************************************
m4_define([n4_case_in],
[m4_if([$#], [0], [], [$#], [1], [], [$#], [2], [],
[m4_if(m4_argn([1], $2), [$1],
[$3],
[m4_if(m4_count($2), [1],
[m4_if([$#], [3], [], [$#], [4],
[$4],
[n4_case_in([$1], m4_shift3($@))])],
[n4_case_in([$1],
m4_dquote(m4_shift($2)),
m4_shift2($@))])])])])
dnl n4_list_index(target, list[, [add-to-return-value][, if-not-found]])
dnl **************************************************************************
dnl
dnl Searches for the first occurrence of `target` in the comma-separated list
dnl `list` and returns its position, or `-1` if `target` has not been found
dnl
dnl For example,
dnl
dnl n4_list_index([bar],
dnl [[foo], [bar], [hello]])
dnl
dnl expands to `1`.
dnl
dnl If the `add-to-return-value` argument is expressed (this accepts only
dnl numbers, both positive and negative), it will be added to the returned
dnl index -- if `target` has not been found and the `if-not-found` argument is
dnl omitted, it will be added to `-1`.
dnl
dnl If the `if-not-found` argument is expressed, it will be returned every
dnl time `target` is not found. This argument accepts both numerical and
dnl non-numerical values.
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: literal
dnl Requires: Nothing
dnl Version: 2.0.1
dnl Author: madmurphy
dnl
dnl **************************************************************************
m4_define([n4_list_index],
[m4_if([$#], [0], [-1],
[$#], [1], [-1],
[m4_if(m4_argn([1], $2), [$1],
[m4_default_nblank_quoted([$3], [0])],
[m4_if(m4_count($2), [1],
[m4_default_nblank_quoted([$4],
[m4_ifblank([$3],
[-1],
[m4_decr([$3])])])],
[n4_list_index([$1],
m4_dquote(m4_shift($2)),
m4_ifblank([$3],
[1],
[m4_incr([$3])]),
m4_default_nblank_quoted([$4],
[m4_ifblank([$3],
[-1],
[m4_decr([$3])])]))])])])])
dnl n4_arg_index(target, arg1[, arg2[, arg3[, ... argN]]])
dnl **************************************************************************
dnl
dnl Searches for the first occurrence of `target` in the arguments passed and
dnl returns its position, or `-1` if `target` has not been found
dnl
dnl For example,
dnl
dnl n4_arg_index([bar],
dnl [foo], [bar], [hello])
dnl
dnl expands to `1`.
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: literal
dnl Requires: `n4_list_index()`
dnl Version: 1.0.1
dnl Author: madmurphy
dnl
dnl **************************************************************************
m4_define([n4_arg_index],
[n4_list_index([$1], m4_dquote(m4_shift($@)))])
dnl n4_rshift(arg1[, arg2[, arg3[, ... argN]]])
dnl **************************************************************************
dnl
dnl Reversed shift -- like `m4_reverse(m4_shift(m4_reverse(arg1, ... argN)))`,
dnl but more efficient
dnl
dnl For example,
dnl
dnl n4_rshift([one], [two], [three], [four], [five])
dnl
dnl expands to
dnl
dnl one, two, three, four
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: literal
dnl Requires: nothing
dnl Version: 1.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
m4_define([n4_rshift],
[m4_if([$#], [0], [], [$#], [1], [], [$#], [2], [[$1]],
[[$1], n4_rshift(m4_shift($@))])])
dnl n4_rshift2(arg1[, arg2[, arg3[, ... argN]]])
dnl **************************************************************************
dnl
dnl Like `n4_rshift()`, but trimming two arguments instead of one
dnl
dnl For example,
dnl
dnl n4_rshift2([one], [two], [three], [four], [five])
dnl
dnl expands to
dnl
dnl one, two, three
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: literal
dnl Requires: nothing
dnl Version: 1.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
m4_define([n4_rshift2],
[m4_if([$#], [0], [], [$#], [1], [], [$#], [2], [], [$#], [3], [[$1]],
[[$1], n4_rshift2(m4_shift($@))])])
dnl n4_rshift3(arg1[, arg2[, arg3[, ... argN]]])
dnl **************************************************************************
dnl
dnl Like `n4_rshift()`, but trimming three arguments instead of one
dnl
dnl For example,
dnl
dnl n4_rshift3([one], [two], [three], [four], [five])
dnl
dnl expands to
dnl
dnl one, two
dnl
dnl For wider shifts please use `m4_shiftn()` + `m4_reverse()` -- i.e.
dnl `m4_reverse(m4_shiftn(num, m4_reverse(arg1, arg2, arg3, ... argN)))`.
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: literal
dnl Requires: nothing
dnl Version: 1.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
m4_define([n4_rshift3],
[m4_if([$#], [0], [], [$#], [1], [], [$#], [2], [], [$#], [3], [], [$#], [4], [[$1]],
[[$1], n4_rshift3(m4_shift($@))])])
dnl n4_set_counter(counter-name[, initial-value = 0[, default-increase = 1]])
dnl **************************************************************************
dnl
dnl Creates self-updating counters
dnl
dnl The counters created optionally support an `increase` argument for
dnl overriding their default increase.
dnl
dnl Example #1:
dnl
dnl n4_set_counter([my_counter])
dnl
dnl my_counter
dnl my_counter
dnl my_counter(7)
dnl my_counter
dnl my_counter(-121)
dnl my_counter
dnl
dnl expands to
dnl
dnl 0
dnl 1
dnl 2
dnl 9
dnl 10
dnl -111
dnl
dnl Example #2:
dnl
dnl n4_set_counter([my_counter], [1000])
dnl
dnl my_counter
dnl my_counter
dnl
dnl expands to
dnl
dnl 1000
dnl 1001
dnl
dnl Example #3:
dnl
dnl n4_set_counter([my_counter], , [-10])
dnl
dnl my_counter
dnl my_counter
dnl my_counter
dnl my_counter(0)
dnl my_counter(0)
dnl my_counter(0)
dnl
dnl expands to
dnl
dnl 0
dnl -10
dnl -20
dnl -30
dnl -30
dnl -30
dnl
dnl Negative numbers are allowed everywhere. If `counter-name` is an already
dnl existing counter or a generic macro it will be overwritten. Use
dnl `m4_undefine()` when you want to unset a counter.
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: literal (void)
dnl Requires: Nothing
dnl Version: 1.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
m4_define([n4_set_counter],
[m4_if([$#], [0], [],
[m4_define([$1],
m4_if([$#], [1],
[[0[]m4_ifblank(]m4_dquote([$][1])[,
[n4_set_counter([$1], 1)],
[n4_set_counter([$1], ]]m4_dquote(m4_dquote([$][1]))[[)])]],
[m4_default_nblank_quoted([$2], [0])[[]m4_ifblank(]m4_dquote([$][1])[,
]m4_if([$#], [2],
[[[n4_set_counter([$1], ]]m4_incr([$2])[[)]]],
[$3], [0], [],
[[[n4_set_counter([$1], ]]m4_eval([$2 + $3])[[, [$3])]]])[,
[m4_if(]]m4_dquote(m4_dquote([$][1]))[[, [0], [],
[n4_set_counter([$1],
m4_eval(]]]m4_dquote(m4_dquote(m4_dquote(m4_default_nblank_quoted([$2], [0]))))[[[[ + ]]]]m4_dquote(m4_dquote(m4_dquote([$][1])))[[[)]]]m4_if([$#], [2], [], [[[[, [$3]]]]])[[[)])])]]))])])
dnl n4_joinalln(separator-list, tree1[, tree2[, ... tree2]])
dnl **************************************************************************
dnl
dnl Like `m4_joinall()`, but walks through multi-dimensional lists of any
dnl dimensions
dnl
dnl The first separator will be used for the top level, the second separator
dnl will be used for the first nesting, and so on.
dnl
dnl For example,
dnl
dnl n4_joinalln([m4_newline, [ = ]],
dnl
dnl [[foo], [bar]],
dnl [[hello], [world]])
dnl
dnl expands to
dnl
dnl foo = bar
dnl hello = world
dnl
dnl Or, for example,
dnl
dnl n4_joinalln([[ => ], [ = ], [ + ]],
dnl
dnl [[[a], [b]],
dnl [[c], [d]]],
dnl [[[e]],
dnl [[f], [g], [h], [i]]])
dnl
dnl expands to
dnl
dnl a + b = c + d => e = f + g + h + i
dnl
dnl If the length of `separator-list` exceeds the maximum nesting present, the
dnl separators in excess will be ignored. If instead any of the lists
dnl possesses a deeper nesting than the number of separators passed, the
dnl innermost nested lists will be returned verbatim.
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: literal
dnl Requires: nothing
dnl Version: 1.0.1
dnl Author: madmurphy
dnl
dnl **************************************************************************
m4_define([n4_joinalln],
[m4_if(m4_count($1), [1],
[m4_joinall($1, m4_shift($@))],
[m4_map_args_sep([n4_joinalln(m4_dquote(m4_shift($1)), m4_unquote(],
[))],
[]m4_dquote(m4_argn([1], $1))[], m4_shift($@))])])
dnl n4_mem([macro-name1[, macro-name2[, ... macro-nameN]]], value)
dnl **************************************************************************
dnl
dnl Expands to `value` after this has been stored into one or more macros
dnl
dnl For example,
dnl
dnl AC_MSG_NOTICE(n4_mem([one], [two], [Hello world]))
dnl AC_MSG_NOTICE(one)
dnl AC_MSG_NOTICE(two)
dnl
dnl will print:
dnl
dnl Hello world
dnl Hello world
dnl Hello world
dnl
dnl Or, showing a more concrete scenario,
dnl
dnl AC_INIT([libfoo],
dnl m4_joinall([.],
dnl n4_mem([PROJECT_MAJVER], [1]),
dnl n4_mem([PROJECT_MINVER], [4]),
dnl n4_mem([PROJECT_REVVER], [2])))
dnl
dnl will call `AC_INIT()` for libfoo 1.4.2 while storing the three macros
dnl `PROJECT_MAJVER`, `PROJECT_MINVER` and `PROJECT_REVVER` for later uses.
dnl
dnl To delete the stored macros you must use `m4_undefine()`.
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: literal
dnl Requires: nothing
dnl Version: 1.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
m4_define([n4_mem],
[m4_if([$#], [0], [],
[$#], [1], [$1],
[m4_define([$1], [$2])n4_mem(m4_shift($@))])])
dnl n4_nquote(n, arg1[, arg2[, arg3[, ... arg4]]]])
dnl **************************************************************************
dnl
dnl Adds/removes `n` layers of quotes
dnl
dnl This macro supports both positive and negative numbers for the `n`
dnl argument. Using positive numbers will correspond to invoking repeatedly
dnl `m4_quote()` or `m4_dquote()`; using negative numbers will correspond to
dnl invoking repeatedly `m4_unquote()`.
dnl
dnl In particular, writing
dnl
dnl n4_nquote(1, [one], [two], [three])
dnl
dnl corresponds to writing,
dnl
dnl m4_quote([one], [two], [three])
dnl
dnl writing
dnl
dnl n4_nquote(2, [one], [two], [three])
dnl
dnl corresponds to writing,
dnl
dnl m4_dquote([one], [two], [three])
dnl
dnl writing
dnl
dnl n4_nquote(0, [one], [two], [three])
dnl
dnl corresponds to writing,
dnl
dnl [one], [two], [three]
dnl
dnl writing
dnl
dnl n4_nquote(-1, [one], [two], [three])
dnl
dnl corresponds to writing,
dnl
dnl m4_unquote([one], [two], [three])
dnl
dnl and so on.
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: literal
dnl Requires: Nothing
dnl Version: 1.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
m4_define([n4_nquote],
[m4_if([$1], [-1],
[m4_unquote(m4_shift($@))],
[$1], [0],
[m4_shift($@)],
[$1], [1],
[m4_quote(m4_shift($@))],
[$1], [2],
[m4_dquote(m4_shift($@))],
[m4_if(m4_eval([$1 < 0]), [1],
[m4_unquote(n4_nquote(m4_incr([$1]), m4_shift($@)))],
[m4_dquote(n4_nquote(m4_decr([$1]), m4_shift($@)))])])])
dnl n4_bind(original-macro, new-macro, arg1[, arg2[, arg3[, ... argN]]])
dnl **************************************************************************
dnl
dnl Creates a new macro that invokes `original-macro` with `arg1`, `arg2` ...
dnl `argN` as initial arguments
dnl
dnl This macro is the m4 version of ECMAScript `Function.prototype.bind()`.
dnl
dnl For example,
dnl
dnl m4_define([MY_UNBOUND_MACRO], [
dnl First argument is: `$1`
dnl Second argument is: `$2`
dnl Third argument is: `$3`
dnl Fourth argument is: `$4`])
dnl
dnl n4_bind([MY_UNBOUND_MACRO],
dnl [MY_BOUND_MACRO], [foo], [bar])
dnl
dnl MY_UNBOUND_MACRO([hello], [world])
dnl MY_BOUND_MACRO([hello], [world])
dnl
dnl expands to
dnl
dnl First argument is: `hello`
dnl Second argument is: `world`
dnl Third argument is: ``
dnl Fourth argument is: ``
dnl
dnl First argument is: `foo`
dnl Second argument is: `bar`
dnl Third argument is: `hello`
dnl Fourth argument is: `world`
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: literal (void)
dnl Requires: nothing
dnl Version: 1.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
m4_define([n4_bind],
[m4_define([$2],
[$1(]m4_dquote(m4_shift2($@))[m4_if(]m4_dquote([$][#])[, [0], [], ]m4_dquote([, $][@])[))])])
dnl n4_expanded_once(placeholder, macro[, arg1[, arg2[, ... argN ]]])
dnl **************************************************************************
dnl
dnl Calls `macro[(arg1[, arg2[, ... argN ]])]` and stores the result into a
dnl novel `placeholder` macro containing a literal
dnl
dnl For example,
dnl
dnl n4_expanded_once([MY_AM_VERSION], [NR_PROG_VERSION], [automake])
dnl n4_expanded_once([MY_AC_VERSION], [NR_PROG_VERSION], [autoconf])
dnl n4_expanded_once([MY_LT_VERSION], [NR_PROG_VERSION], [libtool])
dnl n4_expanded_once([MY_ACLOCAL_VERSION], [NR_PROG_VERSION], [aclocal])
dnl
dnl AC_MSG_NOTICE([automake version: MY_AM_VERSION])
dnl AC_MSG_NOTICE([autoconf version: MY_AC_VERSION])
dnl AC_MSG_NOTICE([libtool version: MY_LT_VERSION])
dnl AC_MSG_NOTICE([aclocal version: MY_ACLOCAL_VERSION])
dnl
dnl will generate the following output:
dnl
dnl configure: automake version: 1.16.1
dnl configure: autoconf version: 2.69
dnl configure: libtool version: 2.4.6.42-b88ce
dnl configure: aclocal version: 1.16.1
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: literal (void)
dnl Requires: nothing
dnl Version: 1.0.1
dnl Author: madmurphy
dnl
dnl **************************************************************************
m4_define([n4_expanded_once],
[m4_if([$#], [0], [], [$#], [1], [],
[m4_define([$1],
m4_dquote(m4_if([$#], [2],
[$2],
[$2(m4_shift2($@))])))])])
dnl n4_expand_once(placeholder, macro[, arg1[, arg2[, ... argN ]]])
dnl **************************************************************************
dnl
dnl Creates a new macro named `placeholder` that when invoked redefines itself
dnl once and for all as the expansion of `macro[(arg1[, arg2[, ... argN ]])]`
dnl
dnl This macro is very similar to `n4_expanded_once()`, except that it waits
dnl before expanding `macro` until `placeholder` is actually invoked. This
dnl allows expensive operations (such as system calls) to be skipped if not
dnl used.
dnl
dnl For example,
dnl
dnl n4_expand_once([MY_AM_VERSION], [NR_PROG_VERSION], [automake])
dnl n4_expand_once([MY_AC_VERSION], [NR_PROG_VERSION], [autoconf])
dnl n4_expand_once([MY_LT_VERSION], [NR_PROG_VERSION], [libtool])
dnl n4_expand_once([MY_ACLOCAL_VERSION], [NR_PROG_VERSION], [aclocal])
dnl
dnl m4_if(something, [1], [
dnl AC_MSG_NOTICE([automake version: MY_AM_VERSION])
dnl AC_MSG_NOTICE([autoconf version: MY_AC_VERSION])
dnl AC_MSG_NOTICE([libtool version: MY_LT_VERSION])
dnl AC_MSG_NOTICE([aclocal version: MY_ACLOCAL_VERSION])
dnl ])
dnl
dnl will generate the following output if the expansion of `something` equals
dnl `1`,
dnl
dnl configure: automake version: 1.16.1
dnl configure: autoconf version: 2.69
dnl configure: libtool version: 2.4.6.42-b88ce
dnl configure: aclocal version: 1.16.1
dnl
dnl otherwise no system call will be made -- for the `NR_PROG_VERSION()` macro
dnl please see `not-autoreconf.m4`.
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: literal (void)
dnl Requires: nothing
dnl Version: 1.0.1
dnl Author: madmurphy
dnl
dnl **************************************************************************
m4_define([n4_expand_once],
[m4_if([$#], [0], [], [$#], [1], [],
[m4_define([$1],
[m4_define([$1],
m4_dquote(m4_if([$#], [2],
[$2],
[$2(m4_shift2($@))])))$1])])])
dnl n4_void(string1[, string2[, ... stringN]])
dnl **************************************************************************
dnl
dnl Suppresses the output
dnl
dnl The strings passed as arguments will be discarded, but their macro
dnl invocations will still be performed.
dnl
dnl For example,
dnl
dnl n4_void([Bla bla bla... m4_define([foo], [bar])... Bla bla bla])::foo
dnl
dnl expands to
dnl
dnl ::bar
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: literal (void)