1 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 # GNU Makefile based on shared rules provided by the Native Client SDK.
6 # See README.Makefiles for more details.
8 [[def ExpandDict(key, value_in, pre_list=[], post_list=[]):]]
9 [[ value = value_in or [] ]]
10 [[ pre = pre_list or [] ]]
11 [[ post = post_list or [] ]]
12 [[ if type(value) is not dict:]]
14 [[ out.extend(value)]]
17 {{key}} = {{' '.join(out)}}
21 [[ for subkey in value:]]
23 [[ out.extend(value[subkey])]]
25 {{key}}_{{subkey}} = {{' '.join(out)}}
27 {{key}} = $({{key}}_$(TOOLCHAIN))
30 VALID_TOOLCHAINS := {{' '.join(tools)}}
32 NACL_SDK_ROOT ?= $(abspath $(CURDIR)/{{rel_sdk}})
33 include $(NACL_SDK_ROOT)/tools/common.mk
35 [[if desc.get('SOCKET_PERMISSIONS'):]]
36 CHROME_ARGS += --allow-nacl-socket-api=localhost
39 TARGET = {{targets[0]['NAME']}}
40 [[ExpandDict('DEPS', targets[0].get('DEPS', []))]]
41 [[ExpandDict('LIBS', targets[0].get('LIBS', []), pre_list=['$(DEPS)'])]]
43 [[for target in targets:]]
44 [[ source_list = (s for s in sorted(target['SOURCES']) if not s.endswith('.h'))]]
45 [[ source_list = ' \\\n '.join(source_list)]]
46 [[ sources = target['NAME'] + '_SOURCES']]
47 [[ cflags = target['NAME'] + '_CFLAGS']]
48 [[ flags = target.get('CFLAGS', [])]]
49 [[ flags.extend(target.get('CXXFLAGS', []))]]
50 [[ if len(targets) == 1:]]
51 [[ sources = 'SOURCES']]
52 [[ cflags = 'CFLAGS']]
54 [[ ExpandDict(cflags, flags)]]
55 [[ if 'CFLAGS_GCC' in target:]]
56 ifneq ($(TOOLCHAIN),pnacl)
57 {{cflags}} += {{' '.join(target['CFLAGS_GCC'])}}
60 {{sources}} = {{source_list}}
62 # Build rules generated by macros from common.mk:
64 [[if targets[0].get('DEPS'):]]
65 $(foreach dep,$(DEPS),$(eval $(call DEPEND_RULE,$(dep))))
66 [[if len(targets) > 1:]]
67 [[ for target in targets:]]
68 [[ name = target['NAME'] ]]
69 $(foreach src,$({{name}}_SOURCES),$(eval $(call COMPILE_RULE,$(src),$({{name}}_CFLAGS))))
71 $(foreach src,$(SOURCES),$(eval $(call COMPILE_RULE,$(src),$(CFLAGS))))
74 [[for target in targets:]]
75 [[ sources = target['NAME'] + '_SOURCES']]
76 [[ name = target['NAME'] ]]
77 [[ if len(targets) == 1:]]
78 [[ sources = 'SOURCES']]
79 [[ name = '$(TARGET)']]
80 [[ if target['TYPE'] == 'so':]]
81 $(eval $(call SO_RULE,{{name}},$({{sources}})))
82 [[ elif target['TYPE'] == 'so-standalone':]]
83 $(eval $(call SO_RULE,{{name}},$({{sources}}),,,1))
85 ifeq ($(CONFIG),Release)
86 $(eval $(call LINK_RULE,{{name}}_unstripped,$({{sources}}),$(LIBS),$(DEPS)))
87 $(eval $(call STRIP_RULE,{{name}},{{name}}_unstripped))
89 $(eval $(call LINK_RULE,{{name}},$({{sources}}),$(LIBS),$(DEPS)))
93 $(eval $(call NMF_RULE,$(TARGET),)){{post}}