Makefile.library.template 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. [[def ExpandDict(key, value_in, pre_list=[], post_list=[]):]]
  5. [[ value = value_in or [] ]]
  6. [[ pre = pre_list or [] ]]
  7. [[ post = post_list or [] ]]
  8. [[ if type(value) is not dict:]]
  9. [[ out = pre]]
  10. [[ out.extend(value)]]
  11. [[ out.extend(post)]]
  12. [[ if out:]]
  13. {{key}} = {{' '.join(out)}}
  14. [[ ]]
  15. [[ return]]
  16. [[ ]]
  17. [[ for subkey in value:]]
  18. [[ out = pre]]
  19. [[ out.extend(value[subkey])]]
  20. [[ out.extend(post)]]
  21. {{key}}_{{subkey}} = {{' '.join(out)}}
  22. [[ ]]
  23. {{key}} = $({{key}}_$(TOOLCHAIN))
  24. [[]]
  25. [[target = targets[0] ]]
  26. # GNU Makefile based on shared rules provided by the Native Client SDK.
  27. # See README.Makefiles for more details.
  28. VALID_TOOLCHAINS := {{' '.join(tools)}}
  29. NACL_SDK_ROOT ?= $(abspath $(CURDIR)/../..)
  30. [[if 'INCLUDES' in target:]]
  31. EXTRA_INC_PATHS={{' '.join(target['INCLUDES'])}}
  32. [[]]
  33. TARGET = {{target['NAME']}}
  34. include $(NACL_SDK_ROOT)/tools/common.mk
  35. [[ExpandDict('DEPS', targets[0].get('DEPS', []))]]
  36. [[ExpandDict('LIBS', targets[0].get('LIBS', []), pre_list=['$(DEPS)'])]]
  37. [[for target in targets:]]
  38. [[ if target['TYPE'] != 'linker-script':]]
  39. [[ source_list = (s for s in sorted(target['SOURCES']) if not s.endswith('.h'))]]
  40. [[ source_list = ' \\\n '.join(source_list)]]
  41. [[ sources = target['NAME'] + '_SOURCES']]
  42. [[ cflags = target['NAME'] + '_CFLAGS']]
  43. [[ flags = target.get('CFLAGS', [])]]
  44. [[ flags.extend(target.get('CXXFLAGS', []))]]
  45. [[ if len(targets) == 1:]]
  46. [[ sources = 'SOURCES']]
  47. [[ cflags = 'CFLAGS']]
  48. [[ ]]
  49. [[ ExpandDict(cflags, flags)]]
  50. [[ for define in target.get('DEFINES', []):]]
  51. {{cflags}} += -D{{define}}
  52. [[ ]]
  53. [[ if 'CFLAGS_GCC' in target:]]
  54. ifneq ($(TOOLCHAIN),pnacl)
  55. {{cflags}} += {{' '.join(target['CFLAGS_GCC'])}}
  56. endif
  57. [[ ]]
  58. {{sources}} = {{source_list}}
  59. [[]]
  60. all: install
  61. # Build rules generated by macros from common.mk:
  62. [[if targets[0].get('DEPS'):]]
  63. $(foreach dep,$(DEPS),$(eval $(call DEPEND_RULE,$(dep))))
  64. [[for target in targets:]]
  65. [[ name = target['NAME'] ]]
  66. [[ if len(targets) == 1:]]
  67. [[ sources = 'SOURCES']]
  68. [[ cflags = 'CFLAGS']]
  69. [[ else:]]
  70. [[ sources = name + '_SOURCES']]
  71. [[ cflags = name + '_CFLAGS']]
  72. [[ if target['TYPE'] == 'linker-script':]]
  73. $(eval $(call LINKER_SCRIPT_RULE,{{name}},{{target['SOURCES'][0]}},{{target['SOURCES'][1]}}))
  74. [[ else:]]
  75. $(foreach src,$({{sources}}),$(eval $(call COMPILE_RULE,$(src),$({{cflags}}))))
  76. $(eval $(call LIB_RULE,{{name}},$({{sources}})))
  77. [[ if target['TYPE'] != 'static-lib':]]
  78. ifneq (,$(findstring $(TOOLCHAIN),glibc))
  79. $(eval $(call SO_RULE,{{name}},$({{sources}}),$(LIBS),$(DEPS)))
  80. endif
  81. [[ ]]
  82. {{post}}