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
|
#include <string.h>
#include <stdio.h>
#include <dirent.h>
#include <sys/stat.h>
static int
one (const struct dirent *unused)
{
return 1;
}
void
dir_list (char before[1024], char after[1024])
{
struct dirent **eps;
int n;
char gemname[1024] = "";
char gemname_path[4096] = "";
char complete_line[4096] = "";
struct stat attribut;
n = scandir("./g", &eps, one, alphasort);
if (n >= 0) {
int cnt;
for (cnt = 0; cnt < n; ++cnt) {
strcpy(gemname, eps[cnt]->d_name);
strcpy(gemname_path, "./g/");
strcat(gemname_path, gemname);
if (strcmp(gemname, ".") == 0)
continue;
if (strcmp(gemname, "..") == 0)
continue;
stat(gemname_path, &attribut);
if (S_ISDIR(attribut.st_mode) == 0)
continue;
strcat(complete_line, before);
strcat(complete_line, gemname);
strcat(complete_line, after);
strcat(complete_line, "\n");
}
puts(complete_line);
}
else
perror ("Couldn't open the directory");
}
void
make_gem_makefile()
{
puts("ifeq ($(OS),Windows_NT)");
puts("MAKE_FLAGS = --no-print-directory CC=$(CC) LL=$(LL) ALL_CFLAGS='$(ALL_CFLAGS)'");
puts("else");
puts("MAKE_FLAGS = --no-print-directory CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)'");
puts("endif");
puts("");
puts(".PHONY : all");
puts("all :");
dir_list("\t@$(MAKE) -C ", " $(MAKE_FLAGS)");
puts(".PHONY : clean");
puts("clean :");
dir_list("\t@$(MAKE) clean -C ", " $(MAKE_FLAGS)");
}
void
make_init_gems()
{
puts("/*");
puts(" * This file contains a list of all");
puts(" * initializing methods which are");
puts(" * necessary to bootstrap all gems.");
puts(" *");
puts(" * IMPORTANT:");
puts(" * This file was generated!");
puts(" * All manual changes will get lost.");
puts(" */");
puts("");
puts("#include \"mruby.h\"");
puts("");
dir_list("void mrb_", "_gem_init(mrb_state*);");
puts("void");
puts("mrb_init_mrbgems(mrb_state *mrb)");
puts("{");
dir_list(" mrb_", "_gem_init(mrb);");
puts("}");
}
int
main (int argc, char *argv[])
{
if (argc == 2) {
if (strcmp(argv[1], "makefile") == 0)
make_gem_makefile();
else if (strcmp(argv[1], "init_gems") == 0)
make_init_gems();
else
return 1;
}
else {
puts("Argument missing! Options: 'makefile'");
return 1;
}
return 0;
}
|