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 [[if 'INCLUDES' in targets[0]:]]
34 EXTRA_INC_PATHS={{' '.join(targets[0]['INCLUDES'])}}
37 [[if multi_platform:]]
38 # Build with platform-specific subdirectories, to reduce the download size of
43 include $(NACL_SDK_ROOT)/tools/common.mk
45 [[if desc.get('SOCKET_PERMISSIONS'):]]
46 CHROME_ARGS += --allow-nacl-socket-api=localhost
49 TARGET = {{targets[0]['NAME']}}
50 [[if sel_ldr and targets[0].get('SEL_LDR_LIBS'):]]
52 [[ ExpandDict('DEPS', targets[0].get('SEL_LDR_DEPS', []))]]
53 [[ ExpandDict('LIBS', targets[0].get('SEL_LDR_LIBS', []))]]
55 [[ ExpandDict('DEPS', targets[0].get('DEPS', []))]]
56 [[ ExpandDict('LIBS', targets[0].get('LIBS', []))]]
59 [[ ExpandDict('DEPS', targets[0].get('DEPS', []))]]
60 [[ ExpandDict('LIBS', targets[0].get('LIBS', []))]]
63 [[for target in targets:]]
64 [[ source_list = (s for s in sorted(target['SOURCES']) if not s.endswith('.h'))]]
65 [[ source_list = ' \\\n '.join(source_list)]]
66 [[ sources = target['NAME'] + '_SOURCES']]
67 [[ cflags = target['NAME'] + '_CFLAGS']]
68 [[ flags = target.get('CFLAGS', [])]]
69 [[ flags.extend(target.get('CXXFLAGS', []))]]
70 [[ if len(targets) == 1:]]
71 [[ sources = 'SOURCES']]
72 [[ cflags = 'CFLAGS']]
74 [[ ExpandDict(cflags, flags)]]
75 [[ for define in target.get('DEFINES', []):]]
76 {{cflags}} += -D{{define}}
78 [[ if 'CFLAGS_GCC' in target:]]
79 ifneq ($(TOOLCHAIN),pnacl)
80 {{cflags}} += {{' '.join(target['CFLAGS_GCC'])}}
83 {{sources}} = {{source_list}}
85 # Build rules generated by macros from common.mk:
87 [[if targets[0].get('DEPS'):]]
88 $(foreach dep,$(DEPS),$(eval $(call DEPEND_RULE,$(dep))))
89 [[if len(targets) > 1:]]
90 [[ for target in targets:]]
91 [[ name = target['NAME'] ]]
92 $(foreach src,$({{name}}_SOURCES),$(eval $(call COMPILE_RULE,$(src),$({{name}}_CFLAGS))))
94 $(foreach src,$(SOURCES),$(eval $(call COMPILE_RULE,$(src),$(CFLAGS))))
97 [[for target in targets:]]
98 [[ sources = target['NAME'] + '_SOURCES']]
99 [[ name = target['NAME'] ]]
100 [[ if len(targets) == 1:]]
101 [[ sources = 'SOURCES']]
102 [[ name = '$(TARGET)']]
103 [[ if target['TYPE'] == 'so':]]
104 $(eval $(call SO_RULE,{{name}},$({{sources}})))
105 [[ elif target['TYPE'] == 'so-standalone':]]
106 $(eval $(call SO_RULE,{{name}},$({{sources}}),,,1))
108 # The PNaCl workflow uses both an unstripped and finalized/stripped binary.
109 # On NaCl, only produce a stripped binary for Release configs (not Debug).
110 ifneq (,$(or $(findstring pnacl,$(TOOLCHAIN)),$(findstring Release,$(CONFIG))))
111 $(eval $(call LINK_RULE,{{name}}_unstripped,$({{sources}}),$(LIBS),$(DEPS)))
112 $(eval $(call STRIP_RULE,{{name}},{{name}}_unstripped))
114 $(eval $(call LINK_RULE,{{name}},$({{sources}}),$(LIBS),$(DEPS)))
118 $(eval $(call NMF_RULE,$(TARGET),)){{post}}