forked from lopesivan/androgenizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
emit.c
268 lines (236 loc) · 6.68 KB
/
emit.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
/*
Copyright (C) 2011 Collabora Ltd. <http://www.collabora.com/>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "common.h"
void emit_libraries(struct library *l, int count, enum build_type bt,
struct library *filt, int fcount)
{
int i, j, first;
/*libfilter pass. this is the king of the kludges, but I haven't
thought of a reasonable solution... yet?
*/
for (i = 0; i < count; i++)
for (j = 0; j < fcount; j++)
if (strcmp(l[i].name, filt[j].name) == 0)
l[i].ltype = filt[j].ltype;
if (bt == BUILD_NDK) {
first = 1;
for (i = 0; i < count; i++) {
if ((l[i].ltype == LIBRARY_NDK) ||
(l[i].ltype == LIBRARY_UNSUPPORTED)) {
if (first) {
first = 0;
printf("LOCAL_LDLIBS:=\\\n");
} else printf(" \\\n");
printf("\t-l%s", l[i].name);
}
}
if (!first)
printf("\n");
first = 1;
for (i = 0; i < count; i++) {
if (l[i].ltype == LIBRARY_EXTERNAL) {
if (first) {
first = 0;
printf("LOCAL_SHARED_LIBRARIES:=\\\n");
} else printf(" \\\n");
printf("\tlib%s", l[i].name);
}
}
if (!first)
printf("\n\n");
first = 1;
for (i = 0; i < count; i++) {
if (l[i].ltype == LIBRARY_STATIC) {
if (first) {
first = 0;
printf("LOCAL_STATIC_LIBRARIES:=\\\n");
} else printf(" \\\n");
printf("\tlib%s", l[i].name);
}
}
if (!first)
printf("\n\n");
first = 1;
for (i = 0; i < count; i++) {
if (l[i].ltype == LIBRARY_WHOLE_STATIC) {
if (first) {
first = 0;
printf("LOCAL_WHOLE_STATIC_LIBRARIES:=\\\n");
} else printf(" \\\n");
printf("\tlib%s", l[i].name);
}
}
if (!first) {
printf("\n\n");
}
} else { /* bt == BUILD_EXTERNAL */
first = 1;
for (i = 0; i < count; i++) {
if ((l[i].ltype != LIBRARY_FLAG) &&
(l[i].ltype != LIBRARY_STATIC) &&
(l[i].ltype != LIBRARY_WHOLE_STATIC)) {
if (first) {
first = 0;
printf("LOCAL_SHARED_LIBRARIES:=\\\n");
} else printf(" \\\n");
printf("\tlib%s", l[i].name);
}
}
if (!first)
printf("\n\n");
first = 1;
for (i = 0; i < count; i++) {
if ((l[i].ltype == LIBRARY_STATIC)) {
if (first) {
first = 0;
printf("LOCAL_STATIC_LIBRARIES:=\\\n");
} else printf(" \\\n");
printf("\tlib%s", l[i].name);
}
}
if (!first)
printf("\n\n");
first = 1;
for (i = 0; i < count; i++) {
if ((l[i].ltype == LIBRARY_WHOLE_STATIC)) {
if (first) {
first = 0;
printf("LOCAL_WHOLE_STATIC_LIBRARIES:=\\\n");
} else printf(" \\\n");
printf("\tlib%s", l[i].name);
}
}
if (!first)
printf("\n\n");
}
first = 1;
for (i = 0; i < count; i++) {
if (l[i].ltype == LIBRARY_FLAG) {
if (first) {
first = 0;
printf("LOCAL_LDFLAGS:=\\\n");
} else printf("\\\n");
printf("\t%s", l[i].name);
}
}
if (!first)
printf("\n\n");
}
static void emit_flag_array(const char *assignment, struct flag_array *arr)
{
int i;
if (!arr->flags || arr->nr_flags == 0)
return;
printf("%s", assignment);
for (i = 0; i < arr->nr_flags; i++)
printf(" \\\n\t%s", arr->flags[i].flag);
printf("\n\n");
}
int emit_file(struct project *p)
{
int i, j;
printf("# This file is generated by androgenizer for:\n");
printf("# [%s] NDK\n", (p->btype == BUILD_NDK) ? "x" : " ");
printf("# [%s] system\n\n", (p->btype == BUILD_EXTERNAL) ? "x" : " ");
printf("LOCAL_PATH:=$(call my-dir)\n");
if (p->stype == SCRIPT_TOP)
printf("%s_TOP := $(LOCAL_PATH)\n", p->name);
for (i = 0; i < p->modules; i++) {
struct module *m = &p->module[i];
printf("include $(CLEAR_VARS)\n\n");
printf("LOCAL_MODULE:=%s\n\n", m->name);
/* no tags == no build for the external dir... */
if (m->tags) {
printf("LOCAL_MODULE_TAGS:=");
if (m->tags & TAG_USER)
printf("user ");
if (m->tags & TAG_ENG)
printf("eng ");
if (m->tags & TAG_TESTS)
printf("tests ");
if (m->tags & TAG_OPTIONAL)
printf("optional ");
if (m->tags & TAG_DEBUG)
printf("debug ");
printf("\n\n");
}
if (m->sources) {
/* should do two passes? one for LOCAL_SRC_FILES, one for generated */
printf("LOCAL_SRC_FILES := \\\n");
for (j = 0; j < m->sources - 1; j++)
printf("\t%s \\\n", m->source[j].name);
printf("\t%s\n\n", m->source[j].name);
}
emit_libraries(m->library,
m->libraries,
p->btype,
m->libfilter,
m->libfilters);
/* Android passes LOCAL_CPPFLAGS to g++, LOCAL_CXXFLAGS don't exist,
* and LOCAL_CFLAGS goes to *BOTH* g++ and gcc.
* Really.
*/
emit_flag_array("LOCAL_CFLAGS :=", &m->c);
emit_flag_array("LOCAL_CPPFLAGS :=", &m->cxx);
/* We only have to add these to CFLAGS because android's going to give them
* to the c++ compiler anyway...
*/
emit_flag_array("LOCAL_CFLAGS +=", &m->cpp);
emit_flag_array("LOCAL_C_INCLUDES :=", &m->include);
printf("LOCAL_PRELINK_MODULE := false\n");
if (m->header_target) {
printf("LOCAL_COPY_HEADERS_TO := %s\n", m->header_target);
}
if (m->headers) {
printf("LOCAL_COPY_HEADERS := \\\n");
for (j = 0; j < m->headers - 1; j++)
printf("\t%s \\\n", m->header[j].name);
printf("\t%s\n\n", m->header[j].name);
}
if (m->passthrough) {
for (j = 0; j < m->passthroughs; j++)
printf("%s\n", m->passthrough[j].name);
printf("\n");
}
switch (p->module[i].mtype) {
case MODULE_SHARED_LIBRARY:
printf("include $(BUILD_SHARED_LIBRARY)\n");
break;
case MODULE_STATIC_LIBRARY:
printf("include $(BUILD_STATIC_LIBRARY)\n");
break;
case MODULE_EXECUTABLE:
printf("include $(BUILD_EXECUTABLE)\n");
break;
case MODULE_HOST_SHARED_LIBRARY:
printf("include $(BUILD_HOST_SHARED_LIBRARY)\n");
break;
case MODULE_HOST_STATIC_LIBRARY:
printf("include $(BUILD_HOST_STATIC_LIBRARY)\n");
break;
case MODULE_HOST_EXECUTABLE:
printf("include $(BUILD_HOST_EXECUTABLE)\n");
break;
default:
assert(!!!"OH NOES!!!");
}
}
for (i = 0; i < p->subdirs; i++)
printf("-include $(%s_TOP)/%s/Android.mk\n", p->name, p->subdir[i].name);
return 0;
}