-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathutilities.gsl
922 lines (797 loc) · 31.1 KB
/
utilities.gsl
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
.template 0
###############################################################################
# Copyright (c) 2014-2025 libbitcoin developers (see COPYING).
#
# GSL libbitcoin utilities in the 'global' scope.
#
# This is a code generator built using the iMatix GSL code generation
# language. See https://github.com/imatix/gsl for details.
###############################################################################
# Functions
###############################################################################
#------------------------------------------------------------------------------
# Node utilities.
#------------------------------------------------------------------------------
function global.match_name(element, name)
define my.element = match_name.element
require(my.element, "element", "name")
return my.element.name = my.name
endfunction
function global.is_optional_element(element)
define my.element = is_optional_element.element
return defined(my.element.option)
endfunction
function global.is_private_element(element)
define my.element = is_private_element.element
return is_true(my.element.private)
endfunction
#------------------------------------------------------------------------------
# Collection utilities.
#------------------------------------------------------------------------------
function global.set_cursor_begin(element)
define my.element = set_cursor_begin.element
for my.element as _element
new cursor as _cursor
move _cursor to _element
return _cursor
endnew
endfor
return set_cursor_end(my.element)
endfunction
# We insert before a dummy element (cursor) at the end of the element.
# This provides a simple workaround for lack of reverse iteration in GSL,
# allowing order preservation and insertion at the end of the list.
# Fortunately extending a list while iterating it does not alter the iteration.
function global.set_cursor_end(element)
define my.element = set_cursor_end.element
new cursor as _cursor
move _cursor to my.element
return _cursor
endnew
endfunction
function global.clear_cursor(cursor)
define my.cursor = clear_cursor.cursor
delete my.cursor
endfunction
#------------------------------------------------------------------------------
# I/O utilities.
#------------------------------------------------------------------------------
# Open and validate a directory.
function global.create_directory(folder)
define my.result = directory.create(my.folder)
if (my.result = 0)
return
endif
abort "Directory creation failure: $(error_text)"
endfunction
# Open and validate a directory.
function global.open_directory(folder)
define my.directory = directory.open(my.folder, error_text)?
if (defined(my.directory))
return my.directory
endif
abort "Directory open failure: $(error_text)"
endfunction
# Test a directory and return the normalized path.
function global.normalize_directory(folder)
define my.directory = open_directory(my.folder)
return my.directory.path
endfunction
function global.append_path(base, subdir)
if (!is_empty(my.base))
if (!ends_with(my.base, "/") & !ends_with(my.base, "\\"))
return "$(my.base)/$(my.subdir)"
else
return "$(my.base)$(my.subdir)"
endif
endif
return "$(my.subdir)"
endfunction
function global.make_windows_path(path)
return string.replace(my.path, "/|\\")
endfunction
function global.make_prefix(path)
return string.replace(my.path, "/|_")
endfunction
#------------------------------------------------------------------------------
# Library utilities.
#------------------------------------------------------------------------------
function global.join_flags_name(container)
define my.container = join_flags_name.container
define my.result = ""
for my.container.flag as _flag where defined(_flag.name) & !is_empty(_flag.name)
my.result = join(my.result, "-$(_flag.name)", " ")
endfor
return my.result
endfunction
function global.join_flags_value(container)
define my.container = join_flags_value.container
define my.result = ""
for my.container.flag as _flag where defined(_flag.value) & !is_empty(_flag.value)
my.result = join(my.result, "$(_flag.value)", " ")
endfor
return my.result
endfunction
function global.canonical_path_name(repository)
define my.repository = canonical_path_name.repository
return defined(my.repository.path) ?? my.repository.path ?\
my.repository.name
endfunction
# Get the product with the given library name.
function global.find_library_product(name, make, repository)
define my.make = find_library_product.make
define my.repository = find_library_product.repository
define my.product_name = "lib$(my.name)"
return my.make->product(is_library(product) &\
target_name(product, my.repository) = my.product_name)
endfunction
# Accepts [lib]bitcoin[-include] and returns include.
function global.bitcoin_to_include(library)
define my.prefix = "bitcoin"
define my.libprefix = "lib$(my.prefix)"
if (my.library = my.prefix) | (my.library = my.libprefix)
return my.prefix
endif
my.prefix += "-"
if (starts_with(my.library, my.prefix))
return difference(my.library, string.length(my.prefix))
endif
my.libprefix += "-"
if (starts_with(my.library, my.libprefix))
return difference(my.library, string.length(my.libprefix))
endif
abort "The name is not a bitcoin library: $(my.library)"
endfunction
# Accepts include and returns bitcoin[-include].
function global.include_to_bitcoin(include)
define my.prefix = "bitcoin"
if (my.include = my.prefix)
return my.include
endif
return "$(my.prefix)-$(my.include)"
endfunction
#------------------------------------------------------------------------------
# Dependency utilities.
#------------------------------------------------------------------------------
# Get the dependency with the given name.
function global.find_dependency_by_name(name, configure)
define my.configure = find_dependency_by_name.configure
return my.configure->dependency(match_name(dependency, my.name))
endfunction
function global.is_function_dependency(dependency)
define my.dependency = is_function_dependency.dependency
return defined(my.dependency.function)
endfunction
function global.is_package_dependency(dependency)
define my.dependency = is_package_dependency.dependency
return defined(my.dependency.version) &\
!is_boost_dependency(my.dependency) &\
!is_boost_lib_dependency(my.dependency) &\
!is_python_dependency(my.dependency)
endfunction
function global.is_boost_dependency(dependency)
define my.dependency = is_boost_dependency.dependency
return match_name(my.dependency, "boost")
endfunction
function global.is_boost_lib_dependency(dependency)
define my.dependency = is_boost_lib_dependency.dependency
require(my.dependency, "dependency", "name")
return starts_with(my.dependency.name, "boost_")
endfunction
function global.is_mbedtls_dependency(dependency)
define my.dependency = is_mbedtls_dependency.dependency
return match_name(my.dependency, "mbedtls")
endfunction
function global.is_java_dependency(dependency)
define my.dependency = is_java_dependency.dependency
return match_name(my.dependency, "java")
endfunction
function global.is_python_dependency(dependency)
define my.dependency = is_python_dependency.dependency
return match_name(my.dependency, "python")
endfunction
function global.is_pthread_dependency(dependency)
define my.dependency = is_pthread_dependency.dependency
return match_name(my.dependency, "pthread")
endfunction
function global.is_iconv_dependency(dependency)
define my.dependency = is_iconv_dependency.dependency
return match_name(my.dependency, "iconv")
endfunction
function global.is_bitcoin_dependency(dependency)
define my.dependency = is_bitcoin_dependency.dependency
require(my.dependency, "dependency", "name")
return starts_with(my.dependency.name, "bitcoin")
endfunction
function global.has_m4(dependency)
define my.dependency = has_m4.dependency
return !defined(my.dependency.m4) |\
(defined(my.dependency.m4) & !(my.dependency.m4 = "none"))
endfunction
# Test for a flag context.
function global.match_flag_context(flag, context)
define my.flag = match_flag_context.flag?
return (my.flag.context ? "") = my.context
endfunction
# Test flag context value.
function global.is_ccc_flag(flag)
define my.flag = is_ccc_flag.flag?
return match_flag_context(my.flag, "c")
endfunction
function global.is_cxx_flag(flag)
define my.flag = is_cxx_flag.flag?
return match_flag_context(my.flag, "c++")
endfunction
function global.is_cpp_flag(flag)
define my.flag = is_cpp_flag.flag?
return match_flag_context(my.flag, "") |\
match_flag_context(my.flag, "preprocessor")
endfunction
function global.is_link_flag(flag)
define my.flag = is_link_flag.flag?
return match_flag_context(my.flag, "link")
endfunction
# Return CPPFLAGS|CFLAGS|CXXFLAGS|LDFLAGS
function get_flags_variable(flag)
define my.flag = get_flags_variable.flag
if (is_cpp_flag(my.flag))
return "CPPFLAGS"
elsif (is_ccc_flag(my.flag))
return "CFLAGS"
elsif (is_cxx_flag(my.flag))
return "CXXFLAGS"
elsif (is_link_flag(my.flag))
return "LDFLAGS"
endif
define my.context = my.flag.context ? ""
abort "Invalid flag context: '$(my.context)'."
endfunction
#------------------------------------------------------------------------------
# Option utilities.
#------------------------------------------------------------------------------
function global.get_option_symbol_generic(option, seperator, cstyle)
define my.option = get_option_symbol_generic.option
if (defined(my.option))
require(my.option, "option", "type")
require(my.option, "option", "name")
define my.prefix = ""
define my.name = "$(my.option.name:lower)"
define my.type = "$(my.option.type:lower)"
if (is_true(my.cstyle))
my.name = "$(my.option.name:c)"
my.type = "$(my.option.type:c)"
endif
if (!is_true(my.option.unprefixed))
my.prefix = "$(my.type)$(my.seperator)"
endif
return "$(my.prefix)$(my.name)"
endif
endfunction
function global.get_option_symbol(option)
define my.option = get_option_symbol.option
return get_option_symbol_generic(my.option, "_", "true")
endfunction
function global.find_option_symbol_generic(element, configure, seperator, cstyle)
define my.element = find_option_symbol_generic.element
define my.configure = find_option_symbol_generic.configure
if (is_optional_element(my.element))
define my.opt = my.configure->option(option.name = my.element.option)?
if (defined(my.opt))
return get_option_symbol_generic(my.opt, my.seperator, my.cstyle)
endif
abort "Symbol not defined for option: $(my.element.option)"
endif
endfunction
function global.find_option_symbol(element, configure)
define my.element = find_option_symbol.element
define my.configure = find_option_symbol.configure
return find_option_symbol_generic(my.element, my.configure, "_", "true")
endfunction
#------------------------------------------------------------------------------
# Matrix utilities.
#------------------------------------------------------------------------------
function global.is_coverage_job(job)
define my.job = is_coverage_job.job
return defined(my.job) & my.job.system = "linux" & my.job.compiler = "gcc" &\
my.job.link = "static" & is_true(my.job.coverage)
endfunction
function global.count_matrix_coverage_job(matrix)
define my.matrix = count_matrix_coverage_job.matrix?
if (defined(my.matrix))
return count(my.matrix->job(system = "linux" & compiler = "gcc" &\
link = "static" & is_true(coverage)))
endif
endfunction
#------------------------------------------------------------------------------
# Job utilities.
#------------------------------------------------------------------------------
# Get the value part of a standard form (e.g. "--prefix=value") job option.
function global.job_option(job, option)
define my.job = job_option.job
define my.assigner = "--$(my.option)="
define my.option = my.job->option(starts_with(option.value, my.assigner))?
if defined(my.option)
return difference(my.option.value, string.length(my.assigner))
endif
endfunction
#------------------------------------------------------------------------------
# Build utilities.
#------------------------------------------------------------------------------
function global.cumulative_dependencies(list, repositories, repository)
define my.list = cumulative_dependencies.list
define my.repositories = cumulative_dependencies.repositories
define my.repository = cumulative_dependencies.repository
for my.repository->configure.dependency as _dependency
for my.repositories.repository as _repository
if (!(_repository.name = my.repository.name) &\
(_repository->package.library = _dependency.name))
new configure as _deps
cumulative_dependencies(_deps, my.repositories, _repository)
for _deps.dependency as _subdep
if (count(my.list.dependency,\
(count.name = _subdep.name)) = 0)
copy _subdep to my.list
endif
endfor
endnew
endif
endfor
if (defined(my.list->dependency(name = _dependency.name)))
delete my.list->dependency(name = _dependency.name)
endif
copy _dependency to my.list
endfor
endfunction
function global.cumulative_install(list, repositories, repository)
define my.list = cumulative_install.list
define my.repositories = cumulative_install.repositories
define my.repository = cumulative_install.repository
for my.repository->install.build as _build
for my.repositories.repository as _repository
if (!(_repository.name = my.repository.name) &\
(_repository->package.library = _build.name))
new install as _dep_steps
cumulative_install(_dep_steps, my.repositories, _repository)
for _dep_steps.build as _step
if (count(my.list.build, (count.name = _step.name)) = 0)
copy _step to my.list
endif
endfor
endnew
endif
endfor
if (defined(my.list->build(name = _build.name)))
delete my.list->build(name = _build.name)
endif
copy _build to my.list
endfor
endfunction
function global.have_build(install, name)
define my.install = have_build.install
return defined(my.install->build(starts_with(build.name, my.name)))
endfunction
function global.is_icu_build(build)
define my.build = is_icu_build.build
return starts_with(my.build.name, "icu")
endfunction
function global.is_zmq_build(build)
define my.build = is_zmq_build.build
return starts_with(my.build.name, "zmq")
endfunction
function global.is_mbedtls_build(build)
define my.build = is_mbedtls_build.build
return starts_with(my.build.name, "mbedtls")
endfunction
function global.is_boost_build(build)
define my.build = is_boost_build.build
return my.build.name = "boost"
endfunction
function global.is_github_build(build)
define my.build = is_github_build.build
return !is_empty(my.build.github)
endfunction
#------------------------------------------------------------------------------
# Product utilities.
#------------------------------------------------------------------------------
function global.match_prefix(product, prefix)
define my.product = match_prefix.product
require(my.product, "product", "prefix")
return my.product.prefix = my.prefix
endfunction
# Test prefix for primary type (this is a simplified mapping).
function global.is_data(product)
define my.product = is_data.product
return match_prefix(my.product, "bash_completion") |\
match_prefix(my.product, "doc") |\
match_prefix(my.product, "pkgconfig") |\
match_prefix(my.product, "jarexec") |\
match_prefix(my.product, "sysconf")
endfunction
function global.is_headers(product)
define my.product = is_headers.product
return match_prefix(my.product, "include")
endfunction
function global.is_info(product)
define my.product = is_info.product
return match_prefix(my.product, "info")
endfunction
function global.is_java(product)
define my.product = is_java.product
return match_prefix(my.product, "javaexec")
endfunction
function global.is_jar(product)
define my.product = is_jar.product
# jar uses DATA but we wire it up as a product.
return match_prefix(my.product, "jarexec")
endfunction
function global.is_library(product)
define my.product = is_library.product
return match_prefix(my.product, "lib") |\
match_prefix(my.product, "pkgpyexec")
endfunction
function global.is_manual(product)
define my.product = is_manual.product
return match_prefix(my.product, "man")
endfunction
function global.is_program(product)
define my.product = is_program.product
return match_prefix(my.product, "bin")
endfunction
function global.is_python(product)
define my.product = is_python.product
return match_prefix(my.product, "pkgpython")
endfunction
function global.is_script(product)
define my.product = is_script.product
return match_prefix(my.product, "sbin")
endfunction
function global.is_bitcoin_headers(product)
define my.product = is_bitcoin_headers.product
return is_headers(my.product) & ((my.product.container ? "") = "bitcoin")
endfunction
# Is the product allowed to be active only once?
function global.is_singleton(product)
define my.product = is_singleton.product
return is_java(my.product) | is_jar(my.product)
endfunction
# Does the product assign to the CLEANFILES variable.
function global.is_clean_files(product)
define my.product = is_clean_files.product
return is_java(my.product) | is_jar(my.product)
endfunction
# Is the product built from c/c++?
function global.is_cpp(product)
define my.product = is_cpp.product
return is_program(my.product) | is_library(my.product)
endfunction
# Is the product executable?
function global.is_executable(product)
define my.product = is_executable.product
return is_program(my.product) | is_script(my.product)
endfunction
# Is the product compiled?
function global.is_compiled(product)
define my.product = is_compiled.product
return is_cpp(my.product) | is_java(my.product)
endfunction
# Is the non-compiled product explicitly set to distribute?
function global.is_distribute(product)
define my.product = is_distribute.product
return defined(my.product.distribute) & is_true(my.product.distribute)
endfunction
# Is the non-compiled product explicitly set to not distribute?
function global.is_no_distribute(product)
define my.product = is_no_distribute.product
return defined(my.product.distribute) & !is_true(my.product.distribute)
endfunction
# Is the product explicitly set to not install?
function global.is_no_install(product)
define my.product = is_no_install.product
return defined(my.product.install) & !is_true(my.product.install)
endfunction
# Is the product a test executable?
function global.is_test(product)
define my.product = is_test.product
if (!is_true(my.product.test) | is_executable(my.product))
return is_true(my.product.test)
endif
abort "Tests must be executable: '$(my.product.prefix)'"
endfunction
# Is the product a check target.
function global.is_not_covered(product)
define my.product = is_not_covered.product
return (is_test(my.product) | is_no_install(my.product)) &\
is_cpp(my.product)
endfunction
# Is the product a check target.
function global.is_check(product)
define my.product = is_check.product
return is_true(my.product.check) | is_test(my.product)
endfunction
# Is the product a custom target.
function global.is_custom_target(product)
define my.product = is_custom_target.product
return is_optional_element(my.product) & !is_test(my.product)
endfunction
# Is the path extension that of a c/c++ interface implementation file.
function global.is_cpp_implementation_file(path)
return ends_with(my.path, ".ipp")
endfunction
# Is the path extension that of a c/c++ header file.
function global.is_cpp_header_file(path, use_implementation)
return ends_with(my.path, ".hpp") | ends_with(my.path, ".h") |\
((my.use_implementation ? 0) & is_cpp_implementation_file(my.path))
endfunction
# Is the path extension that of a c/c++ source file.
function global.is_cpp_source_file(path)
return ends_with(my.path, ".cpp") | ends_with(my.path, ".c")
endfunction
# Does the file extension conform to the required prefix pattern?
function global.is_product_file(product, path, use_implementation)
define my.product = is_product_file.product
require(my.product, "product", "prefix")
# doc expects no type and bash_completion and manual have no extension.
if (is_data(my.product))
if (match_prefix(my.product, "bash_completion"))
return ends_with(my.path, "")
elsif (match_prefix(my.product, "doc"))
return ends_with(my.path, "")
elsif (match_prefix(my.product, "pkgconfig"))
return ends_with(my.path, ".pc")
elsif (match_prefix(my.product, "sysconf"))
return ends_with(my.path, ".cfg")
endif
elsif (is_cpp(my.product))
return is_cpp_source_file(my.path) |\
is_cpp_header_file(my.path, my.use_implementation)
elsif (is_headers(my.product))
return is_cpp_header_file(my.path, my.use_implementation)
elsif (is_info(my.product))
return ends_with(my.path, ".texi")
elsif (is_java(my.product))
return ends_with(my.path, ".java")
elsif (is_manual(my.product))
return ends_with(my.path, "")
elsif (is_python(my.product))
return ends_with(my.path, ".py")
elsif (is_script(my.product))
return ends_with(my.path, ".sh")
endif
abort "Unknown product type for prefix: '$(my.product.prefix)'"
endfunction
# Get the relative files in the directory.
function global.get_product_files(files, folder, trim, product,\
use_implementation)
define my.files = get_product_files.files
define my.product = get_product_files.product
define my.directory = open_directory(my.folder)
for my.directory.file as _file by _file.name\
where is_product_file(my.product, _file.name, my.use_implementation)
define my.path = "$(_file.path)$(_file.name)"
define my.relative = difference(my.path, my.trim)
table_add(my.files, my.relative, "")
endfor
endfunction
# Get the relative files in the directory hierarchy.
function global.get_all_product_files(files, folder, trim, product)
define my.files = get_all_product_files.files
define my.product = get_all_product_files.product
get_product_files(my.files, my.folder, my.trim, my.product, 1)
define my.directory = open_directory(my.folder)
for my.directory.directory as _directory by _directory.name
define my.subfolder = "$(_directory.path)$(_directory.name)"
get_all_product_files(my.files, my.subfolder, my.trim, my.product)
endfor
endfunction
function global.get_files(files, directory, relative_path, tag, recurse,\
ignore_hidden_dirs, ignore_hidden_files)
define my.files = get_files.files
define my.directory = get_files.directory
if (!defined(my.recurse))
abort("get_files: specify 'recurse' parameter")
endif
if (!defined(my.ignore_hidden_dirs))
abort("get_files: specify 'ignore_hidden_dirs' parameter")
endif
if (!defined(my.ignore_hidden_files))
abort("get_files: specify 'ignore_hidden_files' parameter")
endif
for my.directory.file as _file by _file.name
if (!(is_true(my.ignore_hidden_files) & starts_with(_file.name, ".")))
new my.files.file as _element
_element.name = _file.name
_element.full_path = _file.path
_element.relative_path = my.relative_path
_element.relative_name = append_path(my.relative_path, _file.name)
_element.tag = my.tag
endnew
endif
endfor
if (is_true(my.recurse))
for my.directory.directory as _directory by _directory.name
define my.subdir_path = append_path(my.directory.path,\
_directory.name)
define my.subdir = open_directory(my.subdir_path)
define my.sub_relative_path = append_path(my.relative_path,\
_directory.name)
define my.sub_tag = append_path(my.tag, _directory.name)
if (!(is_true(my.ignore_hidden_dirs) &\
starts_with(_directory.name, ".")))
get_files(my.files, my.subdir, my.sub_relative_path,\
my.sub_tag, my.recurse, my.ignore_hidden_dirs,\
my.ignore_hidden_files)
endif
endfor
endif
endfunction
function global.has_uuid(product)
define my.product = has_uuid.product
return defined(my.product.uuid) & !is_empty(my.product.uuid)
endfunction
function global.target_name(product, repository)
define my.product = target_name.product
define my.repository = target_name.repository
require(my.repository, "repository", "name")
if (defined(my.product.target_name))
return "$(my.product.target_name)"
elsif (defined(my.product.option))
return "$(my.repository.name)-$(my.product.option)"
else
return "$(my.repository.name)"
endif
endfunction
function global.project_name(product, repository)
define my.product = project_name.product
define my.repository = project_name.repository
if (defined(my.product.project_name))
return "$(my.product.project_name)"
else
return target_name(my.product, my.repository)
endif
endfunction
#------------------------------------------------------------------------------
# Package utilities.
#------------------------------------------------------------------------------
function global.get_package_name(package)
define my.package = get_package_name.package
require(my.package, "package", "library")
return "lib$(my.package.library)"
endfunction
#------------------------------------------------------------------------------
# Debugging utilities.
#------------------------------------------------------------------------------
function global.notify(filename)
echo "Generating $(my.filename)..."
endfunction
function global.require(node, context, attribute)
if (!defined(require.node))
abort "Required node undefined for $(my.context).$(my.attribute)."
endif
define my.node = require.node
if (!defined(my.node.$(my.attribute)))
abort "Required attribute missing: $(my.context).$(my.attribute)"
endif
endfunction
function global.trace1(text)
trace(my.text, 1)
endfunction
function global.trace2(text)
trace(my.text, 2)
endfunction
function global.trace3(text)
trace(my.text, 3)
endfunction
function global.trace(text, context)
if ((global.trace ? 0) = my.context ? 1)
echo defined(my.text) ?? "---> $(my.text)" ? "undefined trace"
endif
endfunction
function global.shebang(interpreter)
write_line("#!/bin/$(my.interpreter)")
endfunction
function global.batch_no_echo()
write_line("@echo off")
endfunction
# Write one include.
function global.write_include(path)
write_line("#include <$(my.path)>")
endfunction
#------------------------------------------------------------------------------
# Version utilities.
#------------------------------------------------------------------------------
function split_version(version, version_string)
define my.version = split_version.version
define my.position = string.locate(my.version_string, ".")
define my.version.major = left(my.version_string, my.position)
define my.remainder = string.substr(my.version_string, my.position + 1)
define my.position = string.locate(my.remainder, ".")
define my.version.minor = left(my.remainder, my.position)
define my.version.patch = string.substr(my.remainder, my.position + 1)
endfunction
#------------------------------------------------------------------------------
# CMake utilities.
#------------------------------------------------------------------------------
function calculate_presets(result, repository, presets)
define my.result = calculate_presets.result
define my.repository = calculate_presets.repository
define my.presets = calculate_presets.presets
for my.repository->presets.configuration as _configuration
if (count(my.presets.configuration, count.name = _configuration.name) = 1)
copy my.presets->configuration(name = _configuration.name) to my.result
else
abort "Preset $(_configuration.name) absent from registry."
endif
endfor
endfunction
###############################################################################
# Macros
###############################################################################
.endtemplate
.template 1
.
.# Write a line to the template.
.macro global.write_line(text)
$(my.text ? "")
.endmacro
.
.# Write a single indented line to the template.
.macro global.write_line1(text)
$(my.text ? "")
.endmacro
.
.# Write a double indented line to the template.
.macro global.write_line2(text)
$(my.text ? "")
.endmacro
.
.macro global.heading1(text)
# $(my.text)
#==============================================================================
.endmacro
.
.macro global.heading2(text)
# $(my.text)
#------------------------------------------------------------------------------
.endmacro
.
.macro global.heading3(text)
# $(my.text)
.endmacro
.
.macro global.copyleft(name)
###############################################################################
# Copyright (c) 2014-2025 $(my.name) developers (see COPYING).
#
# GENERATED SOURCE CODE, DO NOT EDIT EXCEPT EXPERIMENTALLY
#
###############################################################################
.endmacro
.
.macro global.c_copyleft(name)
///////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2014-2025 $(my.name) developers (see COPYING).
//
// GENERATED SOURCE CODE, DO NOT EDIT EXCEPT EXPERIMENTALLY
//
///////////////////////////////////////////////////////////////////////////////
.endmacro
.
.macro global.bat_copyleft(name)
REM ###########################################################################
REM # Copyright (c) 2014-2025 $(my.name) developers (see COPYING).
REM #
REM # GENERATED SOURCE CODE, DO NOT EDIT EXCEPT EXPERIMENTALLY
REM #
REM ###########################################################################
.endmacro
.
.macro global.xml_copyleft(name)
<!--
| Copyright (c) 2014-2025 $(my.name) developers (see COPYING).
|
| GENERATED SOURCE CODE, DO NOT EDIT EXCEPT EXPERIMENTALLY
|
-->
.endmacro
.
.endtemplate