-
Notifications
You must be signed in to change notification settings - Fork 0
/
mulle-match-to-c
executable file
·868 lines (701 loc) · 22.9 KB
/
mulle-match-to-c
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
#! /usr/bin/env mulle-bash
# shellcheck shell=bash
#
# Copyright (c) 2020 Nat! - Mulle kybernetiK
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# Neither the name of Mulle kybernetiK nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Create fresh HeadersAndSources.cmake from filesystem information
#
[ "${TRACE}" = 'YES' ] && set -x && : "$0" "$@"
MULLE_EXECUTABLE_VERSION=2.2.0
usage()
{
if [ ! -z "$1" ]
then
log_error "$1"
fi
cat <<EOF >&2
Usage:
${MULLE_USAGE_NAME} [options]
Generate exportable #import and include statements for public
project headers.
The resulting file can be easily included into an envelope header with:
#import "_${PROJECT_NAME:-\$PROJECT_NAME}-export.h"
#include "_${PROJECT_NAME:-\$PROJECT_NAME}-provide.h"
A test run that writes to stdout and does not create files can be
accomplished with:
${MULLE_USAGE_NAME} --stdout
If the output is not to your liking and tweaking the patternfiles seems
too tedious, try the environment variable options.
Options:
--c-headers-file <file> : c header file to create
--objc-headers-file <file> : objc headers file to create
--serial : process headers and sources serially
--stdout : output to stdout
Environment:
MULLE_MATCH_TO_C_C_HEADERS : C headers
MULLE_MATCH_TO_C_C_HEADERS_FILE : C headers file to create
MULLE_MATCH_TO_C_IGNORE_HEADERS : headers to ignore
MULLE_MATCH_TO_C_OBJC_HEADER_REGEX : pattern to match ObjC headers ([A-Z])
MULLE_MATCH_TO_C_OBJC_HEADERS : Objective-C headers
MULLE_MATCH_TO_C_OBJC_HEADERS_FILE : ObjC headers file to create
MULLE_MATCH_TO_C_PATTERNFILETYPE : header patternfile type (header)
MULLE_MATCH_TO_C_PROJECT_HEADERS : project headers list, separated by ':'
MULLE_MATCH_TO_C_UNDERSCORE_HEADERS : ignore underscore prefixed headers (NO)
EOF
exit 1
}
#
# filename is the basename
#
r_match_type_for_filename()
{
log_entry "r_match_type_for_filename" "$@"
local filename="$1"
local projectname="$2"
local assoc
IFS=":"; shell_disable_glob
for assoc in ${MULLE_MATCH_TO_C_IGNORE_HEADERS}
do
if [ "${assoc}" = "${filename}" ]
then
IFS="${DEFAULT_IFS}"; shell_enable_glob
RVAL="ignore"
return
fi
done
for assoc in ${MULLE_MATCH_TO_C_PROJECT_HEADERS}
do
if [ "${assoc}" = "${filename}" ]
then
IFS="${DEFAULT_IFS}"; shell_enable_glob
RVAL="project"
return
fi
done
for assoc in ${MULLE_MATCH_TO_C_C_HEADERS}
do
if [ "${assoc}" = "${filename}" ]
then
IFS="${DEFAULT_IFS}"; shell_enable_glob
RVAL="c"
return
fi
done
for assoc in ${MULLE_MATCH_TO_C_OBJC_HEADERS}
do
if [ "${assoc}" = "${filename}" ]
then
IFS="${DEFAULT_IFS}"; shell_enable_glob
RVAL="objc"
return
fi
done
IFS="${DEFAULT_IFS}"; shell_enable_glob
case "${filename}" in
#
# underscore files should be included by other files if they are
# public and relevant
# by default we keep them, but you can remove them with
# MULLE_MATCH_TO_C_UNDERSCORE_HEADERS NO
#
_*|*[+-]_*)
if [ "${MULLE_MATCH_TO_C_UNDERSCORE_HEADERS}" != 'YES' ]
then
RVAL="ignore"
return
fi
;;
esac
pattern="${MULLE_MATCH_TO_C_OBJC_HEADER_REGEX:-[A-Z]}"
case "${filename}" in
# this is the file including us
"${projectname}".h)
RVAL="project"
;;
${pattern}*|_${pattern}*|__${pattern}*)
RVAL="${PROJECT_DIALECT}" # objc if set
;;
*)
RVAL="c"
;;
esac
}
r_statements_for_matching_headers()
{
log_entry "r_statements_for_matching_headers" "$@"
local categorized_files="$1"
local match_category="$2"
local match_type="$3"
local projectname="$4"
local line
local result
local category
local header
local filename
local type
.foreachline line in ${categorized_files}
.do
category="${line%%;*}"
header="${line##*;}"
log_debug "category: ${category}"
log_debug "header: ${header}"
case "${category}" in
${match_category})
;;
*)
.continue
;;
esac
# ignore reflected headers
case "${header}" in
*/reflect/*)
.continue
;;
esac
r_basename "${header}"
filename="${RVAL}"
r_match_type_for_filename "${filename}" "${projectname}"
case "${RVAL}" in
'project')
log_fluff "${filename} ignored as it's the envelope header"
.continue
;;
'ignore')
log_fluff "${filename} ignored"
.continue
;;
'objc')
if [ "${match_type}" != "objc" ]
then
log_fluff "${filename} looks like Objective-C, we are looking for C though"
.continue
fi
;;
'c')
if [ "${match_type}" != "c" ]
then
log_fluff "${filename} looks like C, we are looking for Objective-C though"
.continue
fi
;;
esac
if [ "${match_type}" = "c" ]
then
log_fluff "Add C #include \"${filename}\""
r_add_line "${result}" "#include \"${filename}\""
else
log_fluff "Add Objective-C #import \"${filename}\""
r_add_line "${result}" "#import \"${filename}\""
fi
result="${RVAL}"
.done
RVAL="${result}"
}
r_text_info_on()
{
log_entry "r_text_info_on" "$@"
local key="$1"
RVAL="/*
* This file will be regenerated by \`mulle-match-to-c\` via
* \`mulle-sde reflect\` and any edits will be lost.
* Suppress generation of this file with:
*
* mulle-sde environment set ${key} DISABLE
*
* To not let mulle-match-to-c generate any header files:
*
* mulle-sde environment set MULLE_MATCH_TO_C_RUN DISABLE
*/"
}
write_header_file()
{
log_entry "write_header_file" "$@"
local filename="$1"
local text_hdr="$2"
local projectname="$3"
local varname="$4"
local shield_identifier
r_basename "${filename}"
r_smart_file_downcase_identifier "${RVAL}"
shield_identifier="${RVAL}__"
r_text_info_on "${varname}"
r_add_line "${RVAL}" "#ifndef ${shield_identifier}"
r_add_line "${RVAL}" "#define ${shield_identifier}"
r_add_line "${RVAL}" $'\n'
r_add_line "${RVAL}" "${text_hdr}"
r_add_line "${RVAL}" $'\n'
r_add_line "${RVAL}" "#endif"
text_hdr="${RVAL}"
log_verbose "mulle-match-to-c writes ${C_RESET_BOLD}${filename}"
r_dirname "${filename}"
mkdir_if_missing "${RVAL}"
if [ -f "${filename}" ]
then
exekutor chmod a+w "${filename}" || _fatal "Can't unprotect \"${filename}\""
fi
if ! redirect_exekutor "${filename}" printf "%s\n" "${text_hdr}"
then
log_error "Failed to write \"${filename}\""
return 1
fi
exekutor chmod a-w "${filename}" || log_warning "Failed to protect \"${filename}\""
}
create_c_headers_file()
{
log_entry "create_c_headers_file" "$@"
local categorized_files="$1"
local projectname="$2"
local text_hdr
case "${MULLE_MATCH_TO_C_C_HEADERS_FILE}" in
DISABLE*)
log_verbose "C Header generation disabled by MULLE_MATCH_TO_C_C_HEADERS_FILE=DISABLE"
return
;;
NONE)
log_verbose "C Header file generation disabled by MULLE_MATCH_TO_C_C_HEADERS_FILE=DISABLE"
text_hdr="# C Header output disabled by MULLE_MATCH_TO_C_C_HEADERS_FILE=NONE"
MULLE_MATCH_TO_C_C_HEADERS_FILE=""
;;
*)
r_statements_for_matching_headers "${categorized_files}" \
"PUBLIC_HEADERS" \
"c" \
"${projectname}"
text_hdr="${RVAL}"
if [ -z "${text_hdr}" ]
then
text_hdr="// no headers"
fi
;;
esac
if [ ! -z "${MULLE_MATCH_TO_C_IGNORE_HEADERS}" ]
then
text_hdr="${text_hdr}
//
// MULLE_MATCH_TO_C_IGNORE_HEADERS=${MULLE_MATCH_TO_C_IGNORE_HEADERS}"
fi
if [ ! -z "${MULLE_MATCH_TO_C_C_HEADERS}" ]
then
text_hdr="${text_hdr}
//
// MULLE_MATCH_TO_C_C_HEADERS=${MULLE_MATCH_TO_C_C_HEADERS}"
fi
if [ "${MULLE_MATCH_TO_C_C_HEADERS_FILE}" = '-' ]
then
log_info "C Public Headers"
printf "%s\n" "${text_hdr}"
return 0
fi
MULLE_MATCH_TO_C_C_HEADERS_FILE="${MULLE_MATCH_TO_C_C_HEADERS_FILE:-${PROJECT_SOURCE_DIR:-src}/reflect/_${projectname}-provide.h}"
log_fluff "Create public C header files (${PWD})"
write_header_file "${MULLE_MATCH_TO_C_C_HEADERS_FILE}" \
"${text_hdr}" \
"${projectname}" \
'MULLE_MATCH_TO_C_C_HEADERS_FILE'
}
create_objc_headers_file()
{
log_entry "create_objc_headers_file" "$@"
local categorized_files="$1"
local projectname="$2"
local text_hdr
case "${MULLE_MATCH_TO_C_OBJC_HEADERS_FILE}" in
DISABLE*)
log_verbose "Objective-C Header file generation disabled by MULLE_MATCH_TO_C_OBJC_HEADERS_FILE=DISABLE"
return
;;
NONE)
log_verbose "Objective-C Header output disabled by MULLE_MATCH_TO_C_OBJC_HEADERS_FILE=NONE"
text_hdr="# Objective-C Header output disabled by MULLE_MATCH_TO_C_OBJC_HEADERS_FILE=NONE"
MULLE_MATCH_TO_C_OBJC_HEADERS_FILE=""
;;
*)
r_statements_for_matching_headers "${categorized_files}" \
"PUBLIC_HEADERS" \
"objc" \
"${projectname}"
text_hdr="${RVAL}"
if [ -z "${text_hdr}" ]
then
text_hdr="// no headers"
fi
;;
esac
if [ ! -z "${MULLE_MATCH_TO_C_IGNORE_HEADERS}" ]
then
text_hdr="${text_hdr}
//
// MULLE_MATCH_TO_C_IGNORE_HEADERS=${MULLE_MATCH_TO_C_IGNORE_HEADERS}"
fi
if [ ! -z "${MULLE_MATCH_TO_C_OBJC_HEADERS}" ]
then
text_hdr="${text_hdr}
//
// MULLE_MATCH_TO_C_OBJC_HEADERS=${MULLE_MATCH_TO_C_OBJC_HEADERS}"
fi
if [ "${MULLE_MATCH_TO_C_OBJC_HEADERS_FILE}" = '-' ]
then
log_info "Objective-C Public Headers"
printf "%s\n" "${text_hdr}"
return 0
fi
MULLE_MATCH_TO_C_OBJC_HEADERS_FILE="${MULLE_MATCH_TO_C_OBJC_HEADERS_FILE:-${PROJECT_SOURCE_DIR:-src}/reflect/_${projectname}-export.h}"
log_fluff "Create public Objective-C header files (${PWD})"
write_header_file "${MULLE_MATCH_TO_C_OBJC_HEADERS_FILE}" \
"${text_hdr}" \
"${projectname}" \
'MULLE_MATCH_TO_C_OBJC_HEADERS_FILE'
}
create_c_project_headers_file()
{
log_entry "create_c_project_headers_file" "$@"
local categorized_files="$1"
local projectname="$2"
local text_hdr
case "${MULLE_MATCH_TO_C_C_PROJECT_HEADERS_FILE}" in
DISABLE*)
log_verbose "C Header generation disabled by MULLE_MATCH_TO_C_C_PROJECT_HEADERS_FILE=DISABLE"
return
;;
NONE)
log_verbose "C Header file generation disabled by MULLE_MATCH_TO_C_C_PROJECT_HEADERS_FILE=DISABLE"
text_hdr="# C Header output disabled by MULLE_MATCH_TO_C_C_PROJECT_HEADERS_FILE=NONE"
MULLE_MATCH_TO_C_C_PROJECT_HEADERS_FILE=""
;;
*)
r_statements_for_matching_headers "${categorized_files}" \
"PUBLIC_HEADERS" \
"c" \
"${projectname}"
text_hdr="${RVAL}"
if [ -z "${text_hdr}" ]
then
text_hdr="// no headers"
fi
;;
esac
if [ ! -z "${MULLE_MATCH_TO_C_IGNORE_HEADERS}" ]
then
text_hdr="${text_hdr}
//
// MULLE_MATCH_TO_C_IGNORE_HEADERS=${MULLE_MATCH_TO_C_IGNORE_HEADERS}"
fi
if [ ! -z "${MULLE_MATCH_TO_C_C_HEADERS}" ]
then
text_hdr="${text_hdr}
//
// MULLE_MATCH_TO_C_C_HEADERS=${MULLE_MATCH_TO_C_C_HEADERS}"
fi
if [ "${MULLE_MATCH_TO_C_C_HEADERS_FILE}" = '-' ]
then
log_info "C Project Headers"
printf "%s\n" "${text_hdr}"
return 0
fi
MULLE_MATCH_TO_C_C_PROJECT_HEADERS_FILE="${MULLE_MATCH_TO_C_C_PROJECT_HEADERS_FILE:-${PROJECT_SOURCE_DIR:-src}/reflect/_${projectname}-include-project.h}"
log_fluff "Create project C header files (${PWD})"
write_header_file "${MULLE_MATCH_TO_C_C_PROJECT_HEADERS_FILE}" \
"${text_hdr}" \
"${projectname}" \
'MULLE_MATCH_TO_C_C_PROJECT_HEADERS_FILE'
}
create_objc_project_headers_file()
{
log_entry "create_objc_project_headers_file" "$@"
local categorized_files="$1"
local projectname="$2"
local text_hdr
case "${MULLE_MATCH_TO_C_OBJC_PROJECT_HEADERS_FILE}" in
DISABLE*)
log_verbose "Objective-C Header file generation disabled by MULLE_MATCH_TO_C_OBJC_PROJECT_HEADERS_FILE=DISABLE"
return
;;
NONE)
log_verbose "Objective-C Header output disabled by MULLE_MATCH_TO_C_OBJC_PROJECT_HEADERS_FILE=NONE"
text_hdr="# Objective-C Header output disabled by MULLE_MATCH_TO_C_OBJC_PROJECT_HEADERS_FILE=NONE"
MULLE_MATCH_TO_C_OBJC_PROJECT_HEADERS_FILE=""
;;
*)
r_statements_for_matching_headers "${categorized_files}" \
"PUBLIC_HEADERS" \
"objc" \
"${projectname}"
text_hdr="${RVAL}"
if [ -z "${text_hdr}" ]
then
text_hdr="// no headers"
fi
;;
esac
if [ ! -z "${MULLE_MATCH_TO_C_IGNORE_HEADERS}" ]
then
text_hdr="${text_hdr}
//
// MULLE_MATCH_TO_C_IGNORE_HEADERS=${MULLE_MATCH_TO_C_IGNORE_HEADERS}"
fi
if [ ! -z "${MULLE_MATCH_TO_C_OBJC_HEADERS}" ]
then
text_hdr="${text_hdr}
//
// MULLE_MATCH_TO_C_OBJC_HEADERS=${MULLE_MATCH_TO_C_OBJC_HEADERS}"
fi
if [ "${MULLE_MATCH_TO_C_OBJC_HEADERS_FILE}" = '-' ]
then
log_info "Objective-C Project Headers"
printf "%s\n" "${text_hdr}"
return 0
fi
MULLE_MATCH_TO_C_OBJC_PROJECT_HEADERS_FILE="${MULLE_MATCH_TO_C_OBJC_PROJECT_HEADERS_FILE:-${PROJECT_SOURCE_DIR:-src}/reflect/_${projectname}-import-project.h}"
log_fluff "Create project Objective-C header files (${PWD})"
write_header_file "${MULLE_MATCH_TO_C_OBJC_PROJECT_HEADERS_FILE}" \
"${text_hdr}" \
"${projectname}" \
'MULLE_MATCH_TO_C_OBJC_PROJECT_HEADERS_FILE'
}
main()
{
log_entry "main" "$@"
# technical flags
local MULLE_TRACE
local MULLE_FLAG_DONT_DEFER='NO'
local MULLE_FLAG_EXEKUTOR_DRY_RUN='NO'
local MULLE_FLAG_FOLLOW_SYMLINKS='YES'
local MULLE_FLAG_LOG_CACHE='NO'
local MULLE_FLAG_LOG_DEBUG='NO'
local MULLE_FLAG_LOG_EXEKUTOR='NO'
local MULLE_FLAG_LOG_FLUFF='NO'
local MULLE_FLAG_LOG_MERGE='NO'
local MULLE_FLAG_LOG_SCRIPTS='NO'
local MULLE_FLAG_LOG_SETTINGS='NO'
local MULLE_FLAG_LOG_VERBOSE='NO'
local MULLE_TRACE_PATHS_FLIP_X='NO'
local MULLE_TRACE_POSTPONE='NO'
local MULLE_TRACE_RESOLVER_FLIP_X='NO'
local MULLE_TRACE_SETTINGS_FLIP_X='NO'
local OPTION_PARALLEL='YES'
local OPTION_C_PUBLIC_HEADERS='DEFAULT'
local OPTION_OBJC_PUBLIC_HEADERS='DEFAULT'
local OPTION_C_PROJECT_HEADERS='DEFAULT'
local OPTION_OBJC_PROJECT_HEADERS='DEFAULT'
MULLE_MATCH_TO_C_PATTERNFILETYPE="${MULLE_MATCH_TO_C_PATTERNFILETYPE:-header}"
MULLE_MATCH_TO_C_UNDERSCORE_HEADERS="${MULLE_MATCH_TO_C_UNDERSCORE_HEADERS:-NO}"
while [ $# -ne 0 ]
do
if options_technical_flags "$1"
then
shift
continue
fi
case "$1" in
-h*|--help|help)
usage
;;
--parallel|--no-serial)
OPTION_PARALLEL='YES'
;;
--serial|--no-parallel)
OPTION_PARALLEL='NO'
;;
--c-headers)
OPTION_C_PUBLIC_HEADERS='YES'
;;
--no-c-headers)
OPTION_C_PUBLIC_HEADERS='NO'
;;
--c-project-headers)
OPTION_C_PROJECT_HEADERS='YES'
;;
--no-c-project-headers)
OPTION_C_PROJECT_HEADERS='NO'
;;
--objc-headers)
OPTION_OBJC_PUBLIC_HEADERS='YES'
;;
--no-objc-headers)
OPTION_OBJC_PUBLIC_HEADERS='NO'
;;
--objc-project-headers)
OPTION_OBJC_PROJECT_HEADERS='YES'
;;
--no-objc-project-headers)
OPTION_OBJC_PROJECT_HEADERS='NO'
;;
--underscore-headers)
MULLE_MATCH_TO_C_UNDERSCORE_HEADERS='YES'
;;
--no-underscore-headers)
MULLE_MATCH_TO_C_UNDERSCORE_HEADERS='NO'
;;
-H|--c-headers-file)
[ $# -eq 1 ] && usage "missing argument to $1"
shift
MULLE_MATCH_TO_C_C_HEADERS_FILE="$1"
;;
--c-project-headers-file)
[ $# -eq 1 ] && usage "missing argument to $1"
shift
MULLE_MATCH_TO_C_C_PROJECT_HEADERS_FILE="$1"
;;
--objc-headers-file)
[ $# -eq 1 ] && usage "missing argument to $1"
shift
MULLE_MATCH_TO_C_OBJC_HEADERS_FILE="$1"
;;
--objc-project-headers-file)
[ $# -eq 1 ] && usage "missing argument to $1"
shift
MULLE_MATCH_TO_C_OBJC_PROJECT_HEADERS_FILE="$1"
;;
--header-filter-type)
[ $# -eq 1 ] && usage "missing argument to $1"
shift
MULLE_MATCH_TO_C_PATTERNFILETYPE="$1"
;;
--stdout)
OPTION_PARALLEL='NO'
MULLE_MATCH_TO_C_C_HEADERS_FILE="-"
MULLE_MATCH_TO_C_OBJC_HEADERS_FILE="-"
MULLE_MATCH_TO_C_C_PROJECT_HEADERS_FILE="-"
MULLE_MATCH_TO_C_OBJC_PROJECT_HEADERS_FILE="-"
;;
--version)
printf "%s\n" "${MULLE_EXECUTABLE_VERSION}"
return 0
;;
-*)
usage "Unknown option \"$1\""
;;
*)
break
;;
esac
shift
done
options_setup_trace "${MULLE_TRACE}" && set -x
[ $# -ne 0 ] && usage "superflous arguments $*"
MULLE_MATCH="${MULLE_MATCH:-`command -v mulle-match`}"
[ -z "${MULLE_MATCH}" ] && fail "mulle-match not in PATH"
include "case"
if [ -z "${PROJECT_NAME}" ]
then
r_basename "${PWD}"
PROJECT_NAME="${RVAL}" # could be nicer
fi
if [ -z "${PROJECT_IDENTIFIER}" ]
then
r_identifier "${PROJECT_NAME}"
PROJECT_IDENTIFIER="${RVAL}"
fi
if [ -z "${PROJECT_DOWNCASE_IDENTIFIER}" ]
then
r_tweaked_de_camel_case "${PROJECT_IDENTIFIER}"
r_lowercase "${RVAL}"
PROJECT_DOWNCASE_IDENTIFIER="${RVAL}"
fi
PROJECT_SOURCE_DIR="${PROJECT_SOURCE_DIR:-.}"
# default to objc here
PROJECT_DIALECT="${PROJECT_DIALECT:-objc}"
if [ "${OPTION_C_PUBLIC_HEADERS}" = 'DEFAULT' ]
then
OPTION_C_PUBLIC_HEADERS='YES'
fi
# if nothing set use objc as default
if [ "${OPTION_OBJC_PUBLIC_HEADERS}" = 'DEFAULT' -a "${PROJECT_DIALECT}" = "objc" ]
then
OPTION_OBJC_PUBLIC_HEADERS='YES'
fi
# TODO: enable this "soonish"
#
# if [ "${OPTION_C_PROJECT_HEADERS}" = 'DEFAULT' ]
# then
# OPTION_C_PROJECT_HEADERS='YES'
# fi
#
# # if nothing set use objc as default
# if [ "${OPTION_OBJC_PROJECT_HEADERS}" = 'DEFAULT' -a "${PROJECT_DIALECT}" = "objc" ]
# then
# OPTION_OBJC_PROJECT_HEADERS='YES'
# fi
#
# With 1000 header and 1000 source files, a full update takes ~7s on
# my machine. It certainly would be interesting to make this properly
# incremental.
#
local categorized_headers
if ! categorized_headers="`rexekutor "${MULLE_MATCH}" \
${MULLE_TECHNICAL_FLAGS} \
find --format "%C;%f\\n" \
--qualifier "TYPE_MATCHES ${MULLE_MATCH_TO_C_PATTERNFILETYPE}"`"
then
return 1
fi
categorized_headers="`LC_ALL=C rexekutor sort -d -t';' -k 1,2 <<< "${categorized_headers}" `"
log_setting "categorized_headers=${categorized_headers}"
if [ "${OPTION_PARALLEL}" = 'YES' ]
then
if [ "${OPTION_C_PUBLIC_HEADERS}" = 'YES' ]
then
create_c_headers_file "${categorized_headers}" "${PROJECT_NAME}" &
fi
if [ "${OPTION_OBJC_PUBLIC_HEADERS}" = 'YES' ]
then
create_objc_headers_file "${categorized_headers}" "${PROJECT_NAME}" &
fi
if [ "${OPTION_C_PROJECT_HEADERS}" = 'YES' ]
then
create_c_project_headers_file "${categorized_headers}" "${PROJECT_NAME}" &
fi
if [ "${OPTION_OBJC_PROJECT_HEADERS}" = 'YES' ]
then
create_objc_project_headers_file "${categorized_headers}" "${PROJECT_NAME}" &
fi
log_fluff "waiting..."
wait
log_fluff 'done!'
else
if [ "${OPTION_C_PUBLIC_HEADERS}" = 'YES' ]
then
create_c_headers_file "${categorized_headers}" "${PROJECT_NAME}"
fi
if [ "${OPTION_OBJC_PUBLIC_HEADERS}" = 'YES' ]
then
create_objc_headers_file "${categorized_headers}" "${PROJECT_NAME}"
fi
if [ "${OPTION_C_PROJECT_HEADERS}" = 'YES' ]
then
create_c_project_headers_file "${categorized_headers}" "${PROJECT_NAME}"
fi
if [ "${OPTION_OBJC_PROJECT_HEADERS}" = 'YES' ]
then
create_objc_project_headers_file "${categorized_headers}" "${PROJECT_NAME}"
fi
fi
}
call_with_flags "main" "${MULLE_MATCH_TO_C_FLAGS}" "$@"