Makefile.example.template 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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.
  4. # GNU Makefile based on shared rules provided by the Native Client SDK.
  5. # See README.Makefiles for more details.
  6. [[]]
  7. [[def ExpandDict(key, value_in, pre_list=[], post_list=[]):]]
  8. [[ value = value_in or [] ]]
  9. [[ pre = pre_list or [] ]]
  10. [[ post = post_list or [] ]]
  11. [[ if type(value) is not dict:]]
  12. [[ out = pre]]
  13. [[ out.extend(value)]]
  14. [[ out.extend(post)]]
  15. [[ if out:]]
  16. {{key}} = {{' '.join(out)}}
  17. [[ ]]
  18. [[ return]]
  19. [[ ]]
  20. [[ for subkey in value:]]
  21. [[ out = pre]]
  22. [[ out.extend(value[subkey])]]
  23. [[ out.extend(post)]]
  24. {{key}}_{{subkey}} = {{' '.join(out)}}
  25. [[ ]]
  26. {{key}} = $({{key}}_$(TOOLCHAIN))
  27. [[]]
  28. VALID_TOOLCHAINS := {{' '.join(tools)}}
  29. {{pre}}
  30. NACL_SDK_ROOT ?= $(abspath $(CURDIR)/{{rel_sdk}})
  31. [[if 'INCLUDES' in targets[0]:]]
  32. EXTRA_INC_PATHS={{' '.join(targets[0]['INCLUDES'])}}
  33. [[]]
  34. TARGET = {{targets[0]['NAME']}}
  35. [[if multi_platform:]]
  36. # Build with platform-specific subdirectories, to reduce the download size of
  37. # the app.
  38. MULTI_PLATFORM = 1
  39. [[]]
  40. include $(NACL_SDK_ROOT)/tools/common.mk
  41. [[if desc.get('SOCKET_PERMISSIONS'):]]
  42. CHROME_ARGS += --allow-nacl-socket-api=localhost
  43. [[]]
  44. [[ExpandDict('DEPS', targets[0].get('DEPS', []))]]
  45. [[ExpandDict('LIBS', targets[0].get('LIBS', []))]]
  46. [[for target in targets:]]
  47. [[ source_list = sorted(target['SOURCES'] + target.get('EXTRA_SOURCES', []))]]
  48. [[ source_list = (s for s in source_list if not s.endswith('.h'))]]
  49. [[ source_list = ' \\\n '.join(source_list)]]
  50. [[ sources = target['NAME'] + '_SOURCES']]
  51. [[ cflags = target['NAME'] + '_CFLAGS']]
  52. [[ flags = target.get('CFLAGS', [])]]
  53. [[ flags.extend(target.get('CXXFLAGS', []))]]
  54. [[ if len(targets) == 1:]]
  55. [[ sources = 'SOURCES']]
  56. [[ cflags = 'CFLAGS']]
  57. [[ ]]
  58. [[ ExpandDict(cflags, flags)]]
  59. [[ for define in target.get('DEFINES', []):]]
  60. {{cflags}} += -D{{define}}
  61. [[ ]]
  62. [[ if 'CFLAGS_GCC' in target:]]
  63. ifneq ($(TOOLCHAIN),pnacl)
  64. {{cflags}} += {{' '.join(target['CFLAGS_GCC'])}}
  65. endif
  66. [[ ]]
  67. {{sources}} = {{source_list}}
  68. [[]]
  69. # Build rules generated by macros from common.mk:
  70. [[if targets[0].get('DEPS'):]]
  71. $(foreach dep,$(DEPS),$(eval $(call DEPEND_RULE,$(dep))))
  72. [[if len(targets) > 1:]]
  73. [[ for target in targets:]]
  74. [[ name = target['NAME'] ]]
  75. $(foreach src,$({{name}}_SOURCES),$(eval $(call COMPILE_RULE,$(src),$({{name}}_CFLAGS))))
  76. [[else:]]
  77. $(foreach src,$(SOURCES),$(eval $(call COMPILE_RULE,$(src),$(CFLAGS))))
  78. [[]]
  79. [[for target in targets:]]
  80. [[ sources = target['NAME'] + '_SOURCES']]
  81. [[ name = target['NAME'] ]]
  82. [[ if len(targets) == 1:]]
  83. [[ sources = 'SOURCES']]
  84. [[ name = '$(TARGET)']]
  85. [[ if target['TYPE'] == 'so':]]
  86. $(eval $(call SO_RULE,{{name}},$({{sources}})))
  87. [[ elif target['TYPE'] == 'so-standalone':]]
  88. $(eval $(call SO_RULE,{{name}},$({{sources}}),,,1))
  89. [[ else:]]
  90. # The PNaCl workflow uses both an unstripped and finalized/stripped binary.
  91. # On NaCl, only produce a stripped binary for Release configs (not Debug).
  92. ifneq (,$(or $(findstring pnacl,$(TOOLCHAIN)),$(findstring Release,$(CONFIG))))
  93. $(eval $(call LINK_RULE,{{name}}_unstripped,$({{sources}}),$(LIBS),$(DEPS)))
  94. $(eval $(call STRIP_RULE,{{name}},{{name}}_unstripped))
  95. else
  96. $(eval $(call LINK_RULE,{{name}},$({{sources}}),$(LIBS),$(DEPS)))
  97. endif
  98. [[]]
  99. $(eval $(call NMF_RULE,$(TARGET),)){{post}}