-
Notifications
You must be signed in to change notification settings - Fork 0
/
chibi.cpp
1724 lines (1416 loc) · 42.7 KB
/
chibi.cpp
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
#include "chibi-internal.h"
#include "filesystem.h"
#include "stringhelpers.h"
#include <algorithm> // std::remove_if, std::replace
#include <assert.h>
#include <limits.h> // PATH_MAX
#include <stdarg.h>
#include <string>
#include <string.h>
#include <vector>
// for MacOS users : "brew install ccache"
using namespace chibi;
using namespace chibi_filesystem;
namespace chibi
{
bool write_cmake_file(const ChibiInfo & chibi_info, const char * platform, const char * output_filename);
bool write_gradle_files(const ChibiInfo & chibi_info, const char * output_path);
}
// todo : create library targets which are an alias for an existing system library, such as libusb, libsdl2, etc -> will allow to normalize library names, and to use either the system version or compile from source version interchangable
// todo : add option to specify plist file for apps
// set_plist_file <filename>
// todo : add option to specify permissions (camera, microphone input),
// add_permission camera
// add_permission microphone
#ifdef _MSC_VER
#include <direct.h>
#include <stdint.h>
#include <Windows.h>
#ifndef PATH_MAX
#define PATH_MAX _MAX_PATH
#endif
typedef SSIZE_T ssize_t;
static ssize_t my_getline(char ** _line, size_t * _line_size, FILE * file)
{
char *& line = *_line;
size_t & line_size = *_line_size;
if (line == nullptr)
{
line_size = 4096;
line = (char*)malloc(line_size);
}
for (;;)
{
auto pos = ftell(file);
const char * r = fgets(line, (int)line_size, file);
if (r == nullptr)
break;
const size_t length = strlen(line);
if (length + 1 == line_size)
{
free(line);
line_size *= 2;
line = (char*)malloc(line_size);
// for some reason, fseek fails to seek to the location from before the read, as determined by ftell above
// ths _should_ work, but is broken on Windows. so instead I bumped the initial line size above as a work
// around, and processing of files with lines larger than the initial size (which will re-alloc and re-read)
// are likely to fail for now ..
int seek_result = fseek(file, pos, SEEK_SET);
if (seek_result != 0)
return -1;
}
else
return length;
}
return -1;
}
#else
#include <unistd.h>
#define my_getline getline
#endif
#if defined(__GNUC__)
#define sprintf_s(s, ss, f, ...) snprintf(s, ss, f, __VA_ARGS__)
#define vsprintf_s(s, ss, f, a) vsnprintf(s, ss, f, a)
#define strcpy_s(d, ds, s) strcpy(d, s)
#define sscanf_s sscanf
#endif
static thread_local ssize_t s_current_line_length = 0;
static bool file_exist(const char * path)
{
FILE * f = fopen(path, "rb");
if (f == nullptr)
return false;
else
{
fclose(f);
f = nullptr;
return true;
}
}
static std::vector<std::string> s_currentFile; // fixme : make safe for concurrent use of library version of chibi
struct ChibiFileScope
{
ChibiFileScope(const char * filename)
{
s_currentFile.push_back(filename);
}
~ChibiFileScope()
{
s_currentFile.pop_back();
}
};
static void report_error(const char * line, const char * format, ...)
{
char text[1024];
va_list ap;
va_start(ap, format);
vsprintf_s(text, sizeof(text), format, ap);
va_end(ap);
//
if (line != nullptr)
{
printf(">>");
for (int i = 0; i < s_current_line_length; )
{
while (is_whitespace(line[i]))
i++;
if (i < s_current_line_length)
{
printf(" %s", line + i);
while (line[i] != 0)
i++;
i++;
}
}
printf("\n");
}
//
printf("error: %s\n", text);
if (!s_currentFile.empty())
printf("in file: %s\n", s_currentFile.back().c_str());
}
static bool is_absolute_path(const char * path)
{
#if MACOS || LINUX
// detect absolute Unix-style path
return path[0] == '/';
#else
// detect absolute Windows path
for (int i = 0; path[i] != 0; ++i)
if (path[i] == ':')
return true;
return false;
#endif
}
// fixme : make all of these safe for concurrent use of library version of chibi
static ChibiLibrary * s_currentLibrary = nullptr;
static std::string s_platform;
static std::string s_platform_full;
static bool is_platform(const char * platform)
{
if (match_element(s_platform.c_str(), platform, '|'))
return true;
else if (s_platform_full.empty() == false && match_element(s_platform_full.c_str(), platform, '|'))
return true;
else
return false;
}
static bool is_platform_full(const char * platform)
{
auto & platform_full =
s_platform_full.empty()
? s_platform
: s_platform_full;
return match_element(platform_full.c_str(), platform, '|');
}
static void show_syntax_elem(const char * format, const char * description)
{
printf("%s\n\t%s\n", format, description);
}
void show_chibi_syntax()
{
printf("chibi syntax (chibi-root):\n");
show_syntax_elem("add <path>", "adds a chibi file to the workspace");
show_syntax_elem("add_root <path>", "adds a chibi-root file to the workspace");
show_syntax_elem("push_group <name>", "pushes a group name. libraries and apps will be grouped by this name. push_group must be followed by a matching pop_group");
show_syntax_elem("pop_group", "restored the group name");
printf("chibi syntax (global):\n");
show_syntax_elem("app <app_name>", "adds an app target with the given name");
show_syntax_elem("cmake_module_path <path>", "adds a cmake module path");
show_syntax_elem("library <library_name> [shared]", "adds a library target with the given name");
show_syntax_elem("with_platform <platform_name>[|<platform_name>..]", "with_platform may be specified in front of every line. when set, lines are filtered based on whether the current platform name matched the given platform name");
printf("\n");
printf("chibi syntax (within app or library context):\n");
show_syntax_elem("add_dist_files <file>..", "adds one or more files to to be bundled with the application, when the build type is set to distribution");
show_syntax_elem("add_files <file>.. [- [conglomerate <conglomerate_file>]]", "adds one or more files to compile. the list of files may optionally be terminated by '-', after which further options may be specified");
show_syntax_elem("compile_definition <name> <value> [expose]", "adds a compile definition. when <value> is set to *, the compile definition is merely defined, without a value. when <expose> is set, the compile_definition is visible to all targets that depends on the current target");
show_syntax_elem("depend_library <library_name> [local | global | find]", "adds a target dependency. <library_name> may refer to a chibi library target, or to a pre-built library or system library. when [local] is set, the file is interpreted as a pre-built library to be found at the given location, relative to the current chibi file. When [global] is set, the system-global library is used. When [find] is set, the library will be searched for on the system");
show_syntax_elem("depend_package <package_name>", "depends on a package, to be found using one of cmake's find_package scripts. <package_name> defines the name of the cmake package script");
show_syntax_elem("exclude_files <file>..", "exclude one or more files added before using add_files or scan_files");
show_syntax_elem("group <group_name>", "specify the group for files to be added subsequently using add_files or scan_files");
show_syntax_elem("header_path <path> [expose]", "specify a header search path. when [expose] is set, the search path will be propagated to all dependent targets");
show_syntax_elem("resource_path <path>", "specify the resource_path. CHIBI_RESOURCE_PATH will be set appropriately to the given path for debug and release builds. for the distribution build type, files located at resource_path will be bundled with the app and CHIBI_RESOURCE_PATH will be set to the relative search path within the bundle");
show_syntax_elem("license_file <path>", "specify license file(s) for a library");
show_syntax_elem("scan_files <extension_or_wildcard> [path <path>].. [traverse] [group <group_name>] [conglomerate <conglomerate_file>]", "adds files by scanning the given path or the path of the current chibi file. files will be filtered using the extension or wildcard pattern provided. [path] can be used to specify a specific folder to look inside. [traverse] may be set to recursively look for files down the directory hierarchy. when [group] is specified, files found through the scan operation will be grouped by this name in generated ide project files. when [conglomerate] is set, the files will be concatenated into this files, and the generated file will be added instead. [conglomerate] may be used to speed up compile times by compiling a set of files in one go");
show_syntax_elem("push_conglomerate <name>", "pushes a conglomerate file. files will automatically be added to the given conglomerate file. push_conglomerate must be followed by a matching pop_conglomerate");
show_syntax_elem("link_translation_unit_using_function_call <function_name>", "adds a function to be called at the app level to ensure the translation unit in a dependent (static) library doesn't get stripped away by the linker");
}
static bool process_chibi_root_file(ChibiInfo & chibi_info, const char * filename, const std::string & current_group, const bool skip_file_scan);
static bool process_chibi_file(ChibiInfo & chibi_info, const char * filename, const std::string & current_group, const bool skip_file_scan);
static bool process_chibi_root_file(ChibiInfo & chibi_info, const char * filename, const std::string & current_group, const bool skip_file_scan)
{
return process_chibi_file(chibi_info, filename, current_group, skip_file_scan);
}
static bool process_chibi_file(ChibiInfo & chibi_info, const char * filename, const std::string & current_group, const bool skip_file_scan)
{
ChibiFileScope chibi_scope(filename);
s_currentLibrary = nullptr;
std::vector<std::string> group_stack;
group_stack.push_back(current_group);
std::vector<std::string> conglomerate_stack;
char chibi_path[PATH_MAX];
if (!get_path_from_filename(filename, chibi_path, PATH_MAX))
{
report_error(nullptr, "failed to get path from chibi filename: %s", filename);
return false;
}
//
FileHandle f(filename, "rt");
if (f == nullptr)
{
report_error(nullptr, "failed to open %s", filename);
return false;
}
else
{
char * line = nullptr;
size_t lineSize = 0;
for (;;)
{
ssize_t r = my_getline(&line, &lineSize, f);
if (r < 0)
{
s_current_line_length = 0;
break;
}
else
{
//printf("%s\n", line);
s_current_line_length = r;
if (is_comment_or_whitespace(line))
continue;
char * linePtr = line;
if (eat_word(linePtr, "with_platform"))
{
const char * platform;
if (!eat_word_v2(linePtr, platform))
{
report_error(line, "with_platform without platform");
return false;
}
if (is_platform(platform) == false)
continue;
}
if (eat_word(linePtr, "with_platform_full"))
{
const char * platform;
if (!eat_word_v2(linePtr, platform))
{
report_error(line, "with_platform_full without platform");
return false;
}
if (is_platform_full(platform) == false)
continue;
}
//
if (eat_word(linePtr, "add"))
{
const char * location;
if (!eat_word_v2(linePtr, location))
{
report_error(line, "missing location");
return false;
}
else
{
char chibi_file[PATH_MAX];
if (!concat(chibi_file, sizeof(chibi_file), chibi_path, "/", location, "/chibi.txt"))
{
report_error(line, "failed to create absolute path");
return false;
}
const int length = s_current_line_length;
const bool success = process_chibi_file(chibi_info, chibi_file, group_stack.back(), skip_file_scan);
s_currentLibrary = nullptr;
s_current_line_length = length;
if (success == false)
{
report_error(line, "failed to process chibi file: %s", chibi_file);
return false;
}
}
}
else if (eat_word(linePtr, "push_group"))
{
const char * name;
if (!eat_word_v2(linePtr, name))
{
report_error(line, "missing group name");
return false;
}
group_stack.push_back(name);
}
else if (eat_word(linePtr, "pop_group"))
{
if (group_stack.size() == 1)
{
report_error(line, "no group left to pop");
return false;
}
group_stack.pop_back();
}
else if (eat_word(linePtr, "add_root"))
{
const char * location;
if (!eat_word_v2(linePtr, location))
{
report_error(line, "missing location");
return false;
}
else
{
char chibi_file[PATH_MAX];
if (!concat(chibi_file, sizeof(chibi_file), chibi_path, "/", location, "/chibi-root.txt"))
{
report_error(line, "failed to create absolute path");
return false;
}
const int length = s_current_line_length;
if (!process_chibi_root_file(chibi_info, chibi_file, group_stack.back(), skip_file_scan))
return false;
s_current_line_length = length;
}
}
else if (eat_word(linePtr, "library"))
{
s_currentLibrary = nullptr;
const char * name;
bool shared = false;
bool prebuilt = false;
bool objc_arc = false;
if (!eat_word_v2(linePtr, name))
{
report_error(line, "missing name");
return false;
}
for (;;)
{
const char * option;
if (eat_word_v2(linePtr, option) == false)
break;
if (!strcmp(option, "shared"))
shared = true;
else if (!strcmp(option, "prebuilt"))
prebuilt = true;
else if (!strcmp(option, "objc-arc"))
objc_arc = true;
else
{
report_error(line, "unknown option: %s", option);
return false;
}
}
if (chibi_info.library_exists(name))
{
report_error(line, "library already exists");
return false;
}
ChibiLibrary * library = new ChibiLibrary();
library->name = name;
library->path = chibi_path;
library->chibi_file = s_currentFile.back();
if (group_stack.back().empty() == false)
library->group_name = group_stack.back();
library->shared = shared;
library->prebuilt = prebuilt;
library->objc_arc = objc_arc;
chibi_info.libraries.push_back(library);
s_currentLibrary = library;
}
else if (eat_word(linePtr, "app"))
{
s_currentLibrary = nullptr;
const char * name;
if (!eat_word_v2(linePtr, name))
{
report_error(line, "missing name");
return false;
}
if (chibi_info.library_exists(name))
{
report_error(line, "app already exists");
return false;
}
ChibiLibrary * library = new ChibiLibrary();
library->name = name;
library->path = chibi_path;
library->chibi_file = s_currentFile.back();
if (group_stack.back().empty() == false)
library->group_name = group_stack.back();
library->isExecutable = true;
chibi_info.libraries.push_back(library);
s_currentLibrary = library;
}
else if (eat_word(linePtr, "cmake_module_path"))
{
const char * path;
if (!eat_word_v2(linePtr, path))
{
report_error(line, "cmake_module_path without path");
return false;
}
char full_path[PATH_MAX];
if (!concat(full_path, sizeof(full_path), chibi_path, "/", path))
{
report_error(line, "failed to create absolute path");
return false;
}
chibi_info.cmake_module_paths.push_back(full_path);
}
else if (eat_word(linePtr, "add_files"))
{
if (s_currentLibrary == nullptr)
{
report_error(line, "add_files without a target");
return false;
}
else
{
std::vector<ChibiLibraryFile> library_files;
const char * group = nullptr;
const char * conglomerate =
conglomerate_stack.empty()
? nullptr
: conglomerate_stack.back().c_str();
bool absolute = false;
bool done = false;
// parse file list
for (;;)
{
const char * filename;
if (!eat_word_v2(linePtr, filename))
{
done = true;
break;
}
if (!strcmp(filename, "-"))
break;
ChibiLibraryFile file;
file.filename = filename;
library_files.push_back(file);
}
// parse options
if (done == false)
{
for (;;)
{
const char * option;
if (!eat_word_v2(linePtr, option))
{
done = true;
break;
}
if (!strcmp(option, "group"))
{
if (!eat_word_v2(linePtr, group))
{
report_error(line, "missing group name");
return false;
}
}
else if (!strcmp(option, "conglomerate"))
{
if (!eat_word_v2(linePtr, conglomerate))
{
report_error(line, "missing conglomerate target");
return false;
}
}
else if (!strcmp(option, "absolute"))
{
absolute = true;
}
else
{
report_error(line, "unknown option: %s", option);
return false;
}
}
}
if (absolute == false)
{
for (auto & library_file : library_files)
{
char full_path[PATH_MAX];
if (!concat(full_path, sizeof(full_path), chibi_path, "/", library_file.filename.c_str()))
{
report_error(line, "failed to create absolute path");
return false;
}
library_file.filename = full_path;
}
}
if (group != nullptr)
{
for (auto & library_file : library_files)
library_file.group = group;
}
if (conglomerate != nullptr)
{
char full_path[PATH_MAX];
if (!concat(full_path, sizeof(full_path), chibi_path, "/", conglomerate))
{
report_error(line, "failed to create absolute path");
return false;
}
for (auto & library_file : library_files)
{
library_file.conglomerate_filename = full_path;
library_file.compile = false;
}
if (group != nullptr)
{
s_currentLibrary->conglomerate_groups[full_path] = group;
}
}
s_currentLibrary->files.insert(
s_currentLibrary->files.end(),
library_files.begin(),
library_files.end());
}
}
else if (eat_word(linePtr, "scan_files"))
{
if (s_currentLibrary == nullptr)
{
report_error(line, "scan_files without a target");
return false;
}
else
{
const char * extensions;
if (!eat_word_v2(linePtr, extensions))
{
report_error(line, "missing extension");
return false;
}
bool traverse = false;
const char * platform = nullptr;
const char * path = nullptr;
std::vector<std::string> excluded_paths;
const char * group = nullptr;
const char * conglomerate =
conglomerate_stack.empty()
? nullptr
: conglomerate_stack.back().c_str();
for (;;)
{
const char * option;
if (eat_word_v2(linePtr, option) == false)
break;
if (!strcmp(option, "traverse"))
traverse = true;
else if (!strcmp(option, "platform"))
{
if (!eat_word_v2(linePtr, platform))
report_error(line, "missing platform name");
}
else if (!strcmp(option, "path"))
{
if (!eat_word_v2(linePtr, path))
report_error(line, "missing path");
}
else if (!strcmp(option, "exclude_path"))
{
const char * excluded_path;
if (!eat_word_v2(linePtr, excluded_path))
{
report_error(line, "exclude_path without a path");
return false;
}
char full_path[PATH_MAX];
if (!concat(full_path, sizeof(full_path), chibi_path, "/", excluded_path))
{
report_error(line, "failed to create absolute path");
return false;
}
excluded_paths.push_back(full_path);
}
else if (!strcmp(option, "group"))
{
if (!eat_word_v2(linePtr, group))
{
report_error(line, "missing group name");
return false;
}
}
else if (!strcmp(option, "conglomerate"))
{
if (!eat_word_v2(linePtr, conglomerate))
{
report_error(line, "missing conglomerate target");
return false;
}
}
else
{
report_error(line, "unknown option: %s", option);
return false;
}
}
if (skip_file_scan)
continue;
// scan files
char search_path[PATH_MAX];
if (path == nullptr)
{
if (!concat(search_path, sizeof(search_path), chibi_path))
{
report_error(line, "failed to create absolute path");
return false;
}
}
else
{
if (!concat(search_path, sizeof(search_path), chibi_path, "/", path))
{
report_error(line, "failed to create absolute path");
return false;
}
}
auto filenames = listFiles(search_path, traverse);
const bool is_wildcard = strchr(extensions, '*') != nullptr;
auto end = std::remove_if(filenames.begin(), filenames.end(), [&](const std::string & filename) -> bool
{
if (is_wildcard)
{
if (match_wildcard(filename.c_str(), extensions, ';') == false)
return true;
}
else
{
const auto extension = get_path_extension(filename.c_str(), true);
if (match_element(extension.c_str(), extensions, '|') == false)
return true;
}
if (platform != nullptr && platform != s_platform)
return true;
for (auto & excluded_path : excluded_paths)
if (string_starts_with(filename, excluded_path))
return true;
return false;
});
filenames.erase(end, filenames.end());
std::vector<ChibiLibraryFile> library_files;
for (auto & filename : filenames)
{
ChibiLibraryFile file;
file.filename = filename;
if (group != nullptr)
file.group = group;
library_files.push_back(file);
}
if (conglomerate != nullptr)
{
char full_path[PATH_MAX];
if (!concat(full_path, sizeof(full_path), chibi_path, "/", conglomerate))
{
report_error(line, "failed to create absolute path");
return false;
}
for (auto & library_file : library_files)
{
library_file.conglomerate_filename = full_path;
library_file.compile = false;
}
if (group != nullptr)
{
s_currentLibrary->conglomerate_groups[full_path] = group;
}
}
s_currentLibrary->files.insert(
s_currentLibrary->files.end(),
library_files.begin(),
library_files.end());
}
}
else if (eat_word(linePtr, "exclude_files"))
{
if (s_currentLibrary == nullptr)
{
report_error(line, "exclude_files without a target");
return false;
}
else
{
for (;;)
{
const char * filename;
if (!eat_word_v2(linePtr, filename))
break;
char full_path[PATH_MAX];
if (!concat(full_path, sizeof(full_path), chibi_path, "/", filename))
{
report_error(line, "failed to create absolute path");
return false;
}
for (auto fileItr = s_currentLibrary->files.begin(); fileItr != s_currentLibrary->files.end(); )
{
auto & file = *fileItr;
if (file.filename == full_path)
fileItr = s_currentLibrary->files.erase(fileItr);
else
fileItr++;
}
}
}
}
else if (eat_word(linePtr, "depend_package"))
{
if (s_currentLibrary == nullptr)
{
report_error(line, "depend_package without a target");
return false;
}
else
{
const char * name;
ChibiPackageDependency::Type type = ChibiPackageDependency::kType_FindPackage;
if (!eat_word_v2(linePtr, name))
{
report_error(line, "missing name");
return false;
}
for (;;)
{
const char * option;
if (!eat_word_v2(linePtr, option))
break;
#if ENABLE_PKGCONFIG
if (!strcmp(option, "pkgconfig"))
type = ChibiPackageDependency::kType_PkgConfig;
else
#endif
{
report_error(line, "unknown option: %s", option);
return false;
}
}
ChibiPackageDependency package_dependency;
package_dependency.name = name;
package_dependency.variable_name = name;
package_dependency.type = type;
std::replace(package_dependency.variable_name.begin(), package_dependency.variable_name.end(), '-', '_');
std::replace(package_dependency.variable_name.begin(), package_dependency.variable_name.end(), '.', '_');
s_currentLibrary->package_dependencies.push_back(package_dependency);
}
}
else if (eat_word(linePtr, "depend_library"))
{
if (s_currentLibrary == nullptr)
{
report_error(line, "depend_library without a target");
return false;
}
else
{
const char * name;
ChibiLibraryDependency::Type type = ChibiLibraryDependency::kType_Generated;
bool embed_framework = false;
if (!eat_word_v2(linePtr, name))
{
report_error(line, "missing name");
return false;
}
for (;;)
{
const char * option;
if (!eat_word_v2(linePtr, option))
break;
if (!strcmp(option, "local"))
type = ChibiLibraryDependency::kType_Local;
else if (!strcmp(option, "find"))
type = ChibiLibraryDependency::kType_Find;
else if (!strcmp(option, "global"))
type = ChibiLibraryDependency::kType_Global;
else if (!strcmp(option, "embed_framework"))
embed_framework = true;
else
{
report_error(line, "unknown option: %s", option);
return false;
}
}
char full_path[PATH_MAX];
full_path[0] = 0;
if (type == ChibiLibraryDependency::kType_Local)
{
if (!concat(full_path, sizeof(full_path), chibi_path, "/", name))
{
report_error(line, "failed to create absolute path");
return false;
}
}
ChibiLibraryDependency library_dependency;
library_dependency.name = name;
library_dependency.path = full_path;
library_dependency.type = type;
library_dependency.embed_framework = embed_framework;
s_currentLibrary->library_dependencies.push_back(library_dependency);
}
}