summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bin/eolian/main.c74
1 files changed, 70 insertions, 4 deletions
diff --git a/src/bin/eolian/main.c b/src/bin/eolian/main.c
index db8ea371dd..95d81a7e04 100644
--- a/src/bin/eolian/main.c
+++ b/src/bin/eolian/main.c
@@ -14,12 +14,13 @@ enum
14 GEN_H_LEGACY = 1 << 1, 14 GEN_H_LEGACY = 1 << 1,
15 GEN_H_STUB = 1 << 2, 15 GEN_H_STUB = 1 << 2,
16 GEN_C = 1 << 3, 16 GEN_C = 1 << 3,
17 GEN_C_IMPL = 1 << 4 17 GEN_C_IMPL = 1 << 4,
18 GEN_D = 1 << 5
18}; 19};
19 20
20static const char *_dexts[5] = 21static const char *_dexts[6] =
21{ 22{
22 ".h", ".legacy.h", ".stub.h", ".c", ".c" 23 ".h", ".legacy.h", ".stub.h", ".c", ".c", ".d"
23}; 24};
24 25
25static int 26static int
@@ -50,6 +51,7 @@ _print_usage(const char *progn, FILE *outf)
50 " s: Stub C header file (.eo.stub.h/.eot.stub.h)\n" 51 " s: Stub C header file (.eo.stub.h/.eot.stub.h)\n"
51 " c: C source file (.eo.c)\n" 52 " c: C source file (.eo.c)\n"
52 " i: Implementation file (.c, merged with existing)\n" 53 " i: Implementation file (.c, merged with existing)\n"
54 " d: Make-style dependencies (.d)\n"
53 "\n" 55 "\n"
54 "By default, the 'hc' set is used ('h' for .eot files).\n\n" 56 "By default, the 'hc' set is used ('h' for .eot files).\n\n"
55 "The system-wide Eolian directory is scanned for eo files\n" 57 "The system-wide Eolian directory is scanned for eo files\n"
@@ -98,6 +100,9 @@ _try_set_out(char t, char **outs, const char *val, int *what)
98 pos = _get_bit_pos(GEN_C_IMPL); 100 pos = _get_bit_pos(GEN_C_IMPL);
99 *what |= GEN_C_IMPL; 101 *what |= GEN_C_IMPL;
100 break; 102 break;
103 case 'd':
104 pos = _get_bit_pos(GEN_D);
105 *what |= GEN_D;
101 } 106 }
102 if (pos < 0) 107 if (pos < 0)
103 return EINA_FALSE; 108 return EINA_FALSE;
@@ -420,12 +425,68 @@ _write_impl(const Eolian_State *eos, const char *ofname, const char *ifname)
420 return ret; 425 return ret;
421} 426}
422 427
428static void
429_append_dep_line(Eina_Strbuf *buf, Eina_Strbuf *dbuf, char **outs, int gen_what, int what)
430{
431 if (!(gen_what & what))
432 return;
433 eina_strbuf_append(buf, outs[_get_bit_pos(what)]);
434 eina_strbuf_append_buffer(buf, dbuf);
435}
436
437static Eina_Bool
438_write_deps(const Eolian_State *eos, const char *ofname, const char *ifname,
439 char **outs, int gen_what)
440{
441 INF("generating deps: %s", ofname);
442
443 Eina_Bool ret = EINA_TRUE;
444 Eina_Strbuf *buf = eina_strbuf_new();
445 Eina_Strbuf *dbuf = eina_strbuf_new();
446
447 const Eolian_Unit *un = eolian_state_unit_by_file_get(eos, ifname);
448 if (!un)
449 {
450 ret = EINA_FALSE;
451 goto result;
452 }
453
454 eina_strbuf_append(dbuf, ": ");
455 /* every generated file depends on its .eo/.eot file */
456 eina_strbuf_append(dbuf, eolian_unit_file_path_get(un));
457
458 const Eolian_Unit *dun;
459 Eina_Iterator *deps = eolian_unit_children_get(un);
460 EINA_ITERATOR_FOREACH(deps, dun)
461 {
462 const char *dpath = eolian_unit_file_path_get(dun);
463 if (!dpath)
464 continue;
465 eina_strbuf_append_char(dbuf, ' ');
466 eina_strbuf_append(dbuf, dpath);
467 }
468 eina_iterator_free(deps);
469 eina_strbuf_append_char(dbuf, '\n');
470
471 _append_dep_line(buf, dbuf, outs, gen_what, GEN_H);
472 _append_dep_line(buf, dbuf, outs, gen_what, GEN_H_LEGACY);
473 _append_dep_line(buf, dbuf, outs, gen_what, GEN_H_STUB);
474 _append_dep_line(buf, dbuf, outs, gen_what, GEN_C);
475 _append_dep_line(buf, dbuf, outs, gen_what, GEN_C_IMPL);
476
477 ret = _write_file(ofname, buf);
478result:
479 eina_strbuf_free(dbuf);
480 eina_strbuf_free(buf);
481 return ret;
482}
483
423int 484int
424main(int argc, char **argv) 485main(int argc, char **argv)
425{ 486{
426 int pret = 1; 487 int pret = 1;
427 488
428 char *outs[5] = { NULL, NULL, NULL, NULL, NULL }; 489 char *outs[6] = { NULL, NULL, NULL, NULL, NULL, NULL };
429 char *basen = NULL; 490 char *basen = NULL;
430 Eina_List *includes = NULL; 491 Eina_List *includes = NULL;
431 492
@@ -478,6 +539,9 @@ main(int argc, char **argv)
478 case 'i': 539 case 'i':
479 gen_what |= GEN_C_IMPL; 540 gen_what |= GEN_C_IMPL;
480 break; 541 break;
542 case 'd':
543 gen_what |= GEN_D;
544 break;
481 default: 545 default:
482 fprintf(stderr, "unknown type: '%c'\n", *wstr); 546 fprintf(stderr, "unknown type: '%c'\n", *wstr);
483 goto end; 547 goto end;
@@ -575,6 +639,8 @@ main(int argc, char **argv)
575 succ = _write_source(eos, outs[_get_bit_pos(GEN_C)], eobn, !strcmp(ext, ".eot")); 639 succ = _write_source(eos, outs[_get_bit_pos(GEN_C)], eobn, !strcmp(ext, ".eot"));
576 if (succ && (gen_what & GEN_C_IMPL)) 640 if (succ && (gen_what & GEN_C_IMPL))
577 succ = _write_impl(eos, outs[_get_bit_pos(GEN_C_IMPL)], eobn); 641 succ = _write_impl(eos, outs[_get_bit_pos(GEN_C_IMPL)], eobn);
642 if (succ && (gen_what & GEN_D))
643 succ = _write_deps(eos, outs[_get_bit_pos(GEN_D)], eobn, outs, gen_what);
578 644
579 if (!succ) 645 if (!succ)
580 goto end; 646 goto end;