• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2
3import os
4
5# Given a list of source files from the V8 gyp file, create a string that
6# can be put into the LOCAL_SRC_FILES makefile variable. One per line, followed
7# by a '\' and with the 'src' directory prepended.
8def _makefileSources(src_list):
9  result = ""
10  for i in xrange(0, len(src_list)):
11    result += '\tsrc/' + src_list[i]
12    if i != len(src_list) - 1:
13      result += ' \\'
14    result += '\n'
15  return result
16
17# Return a string that contains the common header variable setup used in
18# (most of) the V8 makefiles.
19def _makefileCommonHeader(module_name):
20  result = ""
21  result += '### GENERATED, do not edit\n'
22  result += '### for changes, see genmakefiles.py\n'
23  result += 'LOCAL_PATH := $(call my-dir)\n'
24  result += 'include $(CLEAR_VARS)\n'
25  result += 'include $(LOCAL_PATH)/Android.v8common.mk\n'
26  result += 'LOCAL_MODULE := ' + module_name + '\n'
27  return result
28
29# Write a makefile in the simpler format used by v8_libplatform and
30# v8_libsampler
31def _writeMakefile(filename, module_name, sources):
32  if not sources:
33    raise ValueError('No sources for ' + filename)
34
35  with open(filename, 'w') as out:
36    out.write(_makefileCommonHeader(module_name))
37    out.write('LOCAL_MODULE_CLASS := STATIC_LIBRARIES\n')
38
39    out.write('LOCAL_SRC_FILES := \\\n')
40
41    out.write(_makefileSources(sources))
42
43    out.write('LOCAL_C_INCLUDES := \\\n')
44    out.write('\t$(LOCAL_PATH)/src \\\n')
45    out.write('\t$(LOCAL_PATH)/include\n')
46
47    out.write('include $(BUILD_STATIC_LIBRARY)\n')
48
49def _writeMkpeepholeMakefile(target):
50  if not target:
51    raise ValueError('Must specify mkpeephole target properties')
52
53  with open('Android.mkpeephole.mk', 'w') as out:
54    out.write(_makefileCommonHeader('v8mkpeephole'))
55    out.write('LOCAL_SRC_FILES := \\\n')
56    sources = [x for x in target['sources'] if x.endswith('.cc')]
57    sources.sort()
58
59    out.write(_makefileSources(sources))
60
61    out.write('LOCAL_STATIC_LIBRARIES += libv8base liblog\n')
62    out.write('LOCAL_LDLIBS_linux += -lrt\n')
63    out.write('include $(BUILD_HOST_EXECUTABLE)\n')
64
65    out.write('include $(CLEAR_VARS)\n')
66    out.write('include $(LOCAL_PATH)/Android.v8common.mk\n')
67    out.write('LOCAL_MODULE := v8peephole\n')
68    out.write('LOCAL_MODULE_CLASS := STATIC_LIBRARIES\n')
69    out.write('generated_sources := $(call local-generated-sources-dir)\n')
70    out.write('PEEPHOLE_TOOL := $(HOST_OUT_EXECUTABLES)/v8mkpeephole\n')
71    out.write('PEEPHOLE_FILE := ' \
72        '$(generated_sources)/bytecode-peephole-table.cc\n')
73    out.write('$(PEEPHOLE_FILE): PRIVATE_CUSTOM_TOOL = ' \
74        '$(PEEPHOLE_TOOL) $(PEEPHOLE_FILE)\n')
75    out.write('$(PEEPHOLE_FILE): $(PEEPHOLE_TOOL)\n')
76    out.write('\t$(transform-generated-source)\n')
77    out.write('LOCAL_GENERATED_SOURCES += $(PEEPHOLE_FILE)\n')
78    out.write('include $(BUILD_STATIC_LIBRARY)\n')
79
80def _writeV8SrcMakefile(target):
81  if not target:
82    raise ValueError('Must specify v8_base target properties')
83
84  with open('Android.v8.mk', 'w') as out:
85    out.write(_makefileCommonHeader('libv8src'))
86    out.write('LOCAL_MODULE_CLASS := STATIC_LIBRARIES\n')
87
88    out.write('LOCAL_SRC_FILES := \\\n')
89
90    sources = [x for x in target['sources'] if x.endswith('.cc')]
91    sources.sort()
92
93    out.write(_makefileSources(sources))
94
95    arm_src = None
96    arm64_src = None
97    x86_src = None
98    x86_64_src = None
99    mips_src = None
100    mips64_src = None
101    for condition in target['conditions']:
102      if condition[0] == 'v8_target_arch=="arm"':
103        arm_src = [x for x in condition[1]['sources'] if x.endswith('.cc')]
104      elif condition[0] == 'v8_target_arch=="arm64"':
105        arm64_src = [x for x in condition[1]['sources'] if x.endswith('.cc')]
106      elif condition[0] == 'v8_target_arch=="ia32"':
107        x86_src = [x for x in condition[1]['sources'] if x.endswith('.cc')]
108      elif condition[0] \
109          == 'v8_target_arch=="mips" or v8_target_arch=="mipsel"':
110        mips_src = [x for x in condition[1]['sources'] if x.endswith('.cc')]
111      elif condition[0] \
112          == 'v8_target_arch=="mips64" or v8_target_arch=="mips64el"':
113        mips64_src = [x for x in condition[1]['sources'] if x.endswith('.cc')]
114      elif condition[0] == 'v8_target_arch=="x64"':
115        x86_64_src = [x for x in condition[1]['sources'] if x.endswith('.cc')]
116
117    arm_src.sort()
118    arm64_src.sort()
119    x86_src.sort()
120    x86_64_src.sort()
121    mips_src.sort()
122    mips64_src.sort()
123
124    out.write('LOCAL_SRC_FILES_arm += \\\n')
125    out.write(_makefileSources(arm_src))
126    out.write('LOCAL_SRC_FILES_arm64 += \\\n')
127    out.write(_makefileSources(arm64_src))
128    out.write('LOCAL_SRC_FILES_mips += \\\n')
129    out.write(_makefileSources(mips_src))
130    out.write('LOCAL_SRC_FILES_mips64 += \\\n')
131    out.write(_makefileSources(mips64_src))
132    out.write('LOCAL_SRC_FILES_x86 += \\\n')
133    out.write(_makefileSources(x86_src))
134    out.write('LOCAL_SRC_FILES_x86_64 += \\\n')
135    out.write(_makefileSources(x86_64_src))
136
137    out.write('# Enable DEBUG option.\n')
138    out.write('ifeq ($(DEBUG_V8),true)\n')
139    out.write('LOCAL_SRC_FILES += \\\n')
140    out.write('\tsrc/objects-debug.cc \\\n')
141    out.write('\tsrc/ast/prettyprinter.cc \\\n')
142    out.write('\tsrc/regexp/regexp-macro-assembler-tracer.cc\n')
143    out.write('endif\n')
144    out.write('LOCAL_C_INCLUDES := \\\n')
145    out.write('\t$(LOCAL_PATH)/src \\\n')
146    out.write('\texternal/icu/icu4c/source/common \\\n')
147    out.write('\texternal/icu/icu4c/source/i18n\n')
148    out.write('include $(BUILD_STATIC_LIBRARY)\n')
149
150def _writeGeneratedFilesMakfile(target):
151  if not target:
152    raise ValueError('Must specify j2sc target properties')
153
154  with open('Android.v8gen.mk', 'w') as out:
155    out.write(_makefileCommonHeader('libv8gen'))
156    out.write('LOCAL_MODULE_CLASS := STATIC_LIBRARIES\n')
157
158    sources = target['variables']['library_files']
159    out.write('V8_LOCAL_JS_LIBRARY_FILES := \\\n')
160    out.write(_makefileSources(sources))
161
162    sources = target['variables']['experimental_library_files']
163    out.write('V8_LOCAL_JS_EXPERIMENTAL_LIBRARY_FILES := \\\n')
164    out.write(_makefileSources(sources))
165
166    out.write('LOCAL_SRC_FILES += src/snapshot/snapshot-empty.cc\n')
167
168    out.write('LOCAL_JS_LIBRARY_FILES := ' \
169        '$(addprefix $(LOCAL_PATH)/, $(V8_LOCAL_JS_LIBRARY_FILES))\n')
170    out.write('LOCAL_JS_EXPERIMENTAL_LIBRARY_FILES := ' \
171        '$(addprefix $(LOCAL_PATH)/, ' \
172        '$(V8_LOCAL_JS_EXPERIMENTAL_LIBRARY_FILES))\n')
173    out.write('generated_sources := $(call local-generated-sources-dir)\n')
174    out.write('')
175
176    # Copy js2c.py to generated sources directory and invoke there to avoid
177    # generating jsmin.pyc in the source directory
178    out.write('JS2C_PY := ' \
179        '$(generated_sources)/js2c.py $(generated_sources)/jsmin.py\n')
180    out.write('$(JS2C_PY): ' \
181        '$(generated_sources)/%.py : $(LOCAL_PATH)/tools/%.py | $(ACP)\n')
182    out.write('\t@echo "Copying $@"\n')
183    out.write('\t$(copy-file-to-target)\n')
184
185    # Generate libraries.cc
186    out.write('GEN1 := $(generated_sources)/libraries.cc\n')
187    out.write('$(GEN1): SCRIPT := $(generated_sources)/js2c.py\n')
188    out.write('$(GEN1): $(LOCAL_JS_LIBRARY_FILES) $(JS2C_PY)\n')
189    out.write('\t@echo "Generating libraries.cc"\n')
190    out.write('\t@mkdir -p $(dir $@)\n')
191    out.write('\tpython $(SCRIPT) $@ CORE $(LOCAL_JS_LIBRARY_FILES)\n')
192    out.write('V8_GENERATED_LIBRARIES := $(generated_sources)/libraries.cc\n')
193
194    # Generate experimental-libraries.cc
195    out.write('GEN2 := $(generated_sources)/experimental-libraries.cc\n')
196    out.write('$(GEN2): SCRIPT := $(generated_sources)/js2c.py\n')
197    out.write('$(GEN2): $(LOCAL_JS_EXPERIMENTAL_LIBRARY_FILES) $(JS2C_PY)\n')
198    out.write('\t@echo "Generating experimental-libraries.cc"\n')
199    out.write('\t@mkdir -p $(dir $@)\n')
200    out.write('\tpython $(SCRIPT) $@ EXPERIMENTAL ' \
201        '$(LOCAL_JS_EXPERIMENTAL_LIBRARY_FILES)\n')
202    out.write('V8_GENERATED_LIBRARIES ' \
203        '+= $(generated_sources)/experimental-libraries.cc\n')
204
205    # Generate extra-libraries.cc
206    out.write('GEN3 := $(generated_sources)/extra-libraries.cc\n')
207    out.write('$(GEN3): SCRIPT := $(generated_sources)/js2c.py\n')
208    out.write('$(GEN3): $(JS2C_PY)\n')
209    out.write('\t@echo "Generating extra-libraries.cc"\n')
210    out.write('\t@mkdir -p $(dir $@)\n')
211    out.write('\tpython $(SCRIPT) $@ EXTRAS\n')
212    out.write('V8_GENERATED_LIBRARIES ' \
213        '+= $(generated_sources)/extra-libraries.cc\n')
214
215    # Generate experimental-extra-libraries.cc
216    out.write('GEN4 := $(generated_sources)/experimental-extra-libraries.cc\n')
217    out.write('$(GEN4): SCRIPT := $(generated_sources)/js2c.py\n')
218    out.write('$(GEN4): $(JS2C_PY)\n')
219    out.write('\t@echo "Generating experimental-extra-libraries.cc"\n')
220    out.write('\t@mkdir -p $(dir $@)\n')
221    out.write('\tpython $(SCRIPT) $@ EXPERIMENTAL_EXTRAS\n')
222    out.write('V8_GENERATED_LIBRARIES ' \
223        '+= $(generated_sources)/experimental-extra-libraries.cc\n')
224
225    out.write('LOCAL_GENERATED_SOURCES += $(V8_GENERATED_LIBRARIES)\n')
226
227    out.write('include $(BUILD_STATIC_LIBRARY)\n')
228
229def _writeLibBaseMakefile(target):
230  if not target:
231    raise ValueError('Must specify v8_libbase target properties')
232
233  with open('Android.base.mk', 'w') as out:
234    out.write(_makefileCommonHeader('libv8base'))
235    out.write('LOCAL_MODULE_CLASS := STATIC_LIBRARIES\n')
236
237    out.write('LOCAL_SRC_FILES := \\\n')
238
239    sources = [x for x in target['sources'] if x.endswith('.cc')]
240    sources += ['base/platform/platform-posix.cc']
241    sources.sort()
242
243    out.write(_makefileSources(sources))
244    out.write('LOCAL_SRC_FILES += \\\n')
245    out.write('\tsrc/base/debug/stack_trace_android.cc \\\n')
246    out.write('\tsrc/base/platform/platform-linux.cc\n')
247
248    out.write('LOCAL_C_INCLUDES := $(LOCAL_PATH)/src\n')
249    out.write('include $(BUILD_STATIC_LIBRARY)\n\n')
250
251    out.write('include $(CLEAR_VARS)\n')
252
253    out.write('include $(LOCAL_PATH)/Android.v8common.mk\n')
254
255    # Set up the target identity
256    out.write('LOCAL_MODULE := libv8base\n')
257    out.write('LOCAL_MODULE_CLASS := STATIC_LIBRARIES\n')
258
259    out.write('LOCAL_SRC_FILES := \\\n')
260    out.write(_makefileSources(sources))
261
262    # Host may be linux or darwin.
263    out.write('ifeq ($(HOST_OS),linux)\n')
264    out.write('LOCAL_SRC_FILES += \\\n')
265    out.write('\tsrc/base/debug/stack_trace_posix.cc \\\n')
266    out.write('\tsrc/base/platform/platform-linux.cc\n')
267    out.write('endif\n')
268    out.write('ifeq ($(HOST_OS),darwin)\n')
269    out.write('LOCAL_SRC_FILES += \\\n')
270    out.write('\tsrc/base/debug/stack_trace_posix.cc \\\n')
271    out.write('\tsrc/base/platform/platform-macos.cc\n')
272    out.write('endif\n')
273
274    out.write('LOCAL_C_INCLUDES := $(LOCAL_PATH)/src\n')
275    out.write('include $(BUILD_HOST_STATIC_LIBRARY)\n')
276
277def GenerateMakefiles():
278  # Slurp in the content of the V8 gyp file.
279  with open(os.path.join(os.getcwd(), './src/v8.gyp'), 'r') as f:
280    gyp = eval(f.read())
281
282  # Find the targets that we're interested in and write out the makefiles.
283  for target in gyp['targets']:
284    name = target['target_name']
285    sources = None
286    if target.get('sources'):
287      sources = [x for x in target['sources'] if x.endswith('.cc')]
288      sources.sort()
289
290    if name == 'v8_libplatform':
291      _writeMakefile('Android.platform.mk', 'libv8platform', sources)
292    elif name == 'v8_libsampler':
293      _writeMakefile('Android.sampler.mk', 'libv8sampler', sources)
294    elif name == 'v8_base':
295      _writeV8SrcMakefile(target)
296    elif name == 'mkpeephole':
297      _writeMkpeepholeMakefile(target)
298    elif name == 'js2c':
299      _writeGeneratedFilesMakfile(target)
300    elif name == 'v8_libbase':
301      _writeLibBaseMakefile(target)
302
303