wscript 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import os
  2. import time
  3. import waflib
  4. import waflib.Tools
  5. import waftools.objcopy as objcopy
  6. import waftools.pebble_sdk_gcc as pebble_sdk_gcc
  7. from resources.types.resource_definition import ResourceDefinition
  8. from resources.types.resource_object import ResourceObject
  9. from pebble_sdk_platform import pebble_platforms, maybe_import_internal
  10. from pebble_sdk_version import set_env_sdk_version
  11. import generate_appinfo
  12. #
  13. # Make each of the apps within the stored_apps directory
  14. #
  15. # -----------------------------------------------------------------------------------
  16. def configure(conf):
  17. process_info = conf.path.parent.find_node('src/fw/process_management/pebble_process_info.h')
  18. set_env_sdk_version(conf, process_info)
  19. pebble_sdk_gcc.configure(conf)
  20. conf.env.append_value('DEFINES', 'RELEASE')
  21. # -----------------------------------------------------------------------------------
  22. def build_app(bld, app_name):
  23. sdk_folder = bld.path.parent.get_bld().make_node('sdk').make_node(bld.env.PLATFORM_NAME)
  24. # -----------------------------------------------------------------------------------
  25. # Generate the appinfo.auto.c file
  26. appinfo_json_node = bld.path.get_src().find_node('%s/appinfo.json' % (app_name))
  27. if appinfo_json_node is None:
  28. bld.fatal('Could not find appinfo.json')
  29. appinfo_c_node = bld.path.get_bld().make_node('%s/appinfo.auto.c' % (app_name))
  30. resource_ids_auto_node = bld.path.get_bld().make_node(
  31. '%s/src/resource_ids.auto.h' % (app_name))
  32. bld(rule='echo "#define DEFAULT_MENU_ICON 0" >> ${TGT}', target=resource_ids_auto_node)
  33. message_keys_auto_node = bld.path.get_bld().make_node(app_name).make_node("message_keys.auto.h")
  34. bld(rule='touch ${TGT}', target=message_keys_auto_node)
  35. def _generate_appinfo_c_file_rule(task):
  36. generate_appinfo.generate_appinfo(task.inputs[0].abspath(), task.outputs[0].abspath())
  37. bld(rule=_generate_appinfo_c_file_rule,
  38. source=appinfo_json_node,
  39. target=appinfo_c_node)
  40. # -----------------------------------------------------------------------------------
  41. # Generate the rule to compile and link the sources into an ELF
  42. includes = [sdk_folder.make_node('include'), app_name, '%s/src' % (app_name)]
  43. link_flags = ['-mcpu=cortex-m3','-mthumb','-fPIE', '-Wl,--emit-relocs']
  44. source = bld.path.ant_glob('%s/src/**/*.c' % (app_name)) + [appinfo_c_node]
  45. ld_script = bld.path.make_node('pebble_app.ld').path_from(bld.path)
  46. app_elf_file = bld.path.get_bld().make_node('%s/pebble-app.elf' % (app_name))
  47. stored_apps_env = bld.all_envs['stored_apps']
  48. maybe_import_internal(bld.env)
  49. # Fetch platform-specific defines and add them to CFLAGS
  50. platform_name = stored_apps_env['PLATFORM_NAME']
  51. platform_info = pebble_platforms.get(platform_name, None)
  52. if platform_info is None:
  53. bld.fatal("Unsupported platform: %s" % platform_name)
  54. platform_defines = platform_info['DEFINES']
  55. c_flags = ['-fPIE'] + ['-D%s' % define for define in platform_defines]
  56. gen = bld.program(env=stored_apps_env,
  57. source=source,
  58. target=app_elf_file,
  59. includes=includes,
  60. cflags=c_flags,
  61. ldscript=ld_script,
  62. linkflags=link_flags,
  63. stlibpath=[sdk_folder.make_node('lib').abspath()],
  64. stlib=['pebble'])
  65. # -----------------------------------------------------------------------------------
  66. # Create the bin file and inject the metadata
  67. app_raw_bin_file = bld.path.get_bld().make_node('%s/pebble-app.raw.bin' % (app_name))
  68. bld(rule=objcopy.objcopy_bin, source=app_elf_file, target=app_raw_bin_file)
  69. app_bin_file = bld.path.get_bld().make_node('%s/pebble-app.bin' % (app_name))
  70. # Use a dummy timestamp for the metadata in stored_apps. This timestamp is only used
  71. # to describe the resource version, and stored_apps have no resources. If we use the
  72. # real timestamp that will cause the CRC of the app to change from build to build,
  73. # which causes the pbpack's CRC to change from build to build, which means we have to
  74. # keep using image_resources in development every time we rebuild, even though the
  75. # content didn't change.
  76. pebble_sdk_gcc.gen_inject_metadata_rule(bld, src_bin_file=app_raw_bin_file,
  77. dst_bin_file=app_bin_file, elf_file=app_elf_file,
  78. resource_file=None, timestamp=0, has_pkjs=False,
  79. has_worker=False)
  80. # -----------------------------------------------------------------------------------
  81. # Copy into the resources directory as a .reso file
  82. def _make_reso(task):
  83. app_bin_data = task.inputs[0].read(flags='rb')
  84. reso = ResourceObject(
  85. ResourceDefinition('raw', 'STORED_APP_{}'.format(app_name.upper()), None),
  86. app_bin_data)
  87. reso.dump(task.outputs[0])
  88. resources_bld_node = bld.bldnode.make_node('resources/')
  89. app_resource_node = resources_bld_node.make_node('normal/base/raw/app_%s.bin.reso' % (app_name))
  90. bld(rule=_make_reso, source=app_bin_file, target=app_resource_node, name='stored_app_reso')
  91. bld.DYNAMIC_RESOURCES.append(app_resource_node)
  92. # -----------------------------------------------------------------------------------
  93. def build(bld):
  94. # When you add a new stored app, you must also do the following to include it into the
  95. # system resources and register it with the launcher:
  96. # 1.) Add a raw resource entry with a name of "STORED_APP_<appname>" to
  97. # resources/normal/resource_map.json.
  98. # The "file" field should be set to normal/raw/app_<appname>.bin
  99. # 2.) Add a new entry to the INIT_STORED_APPS array in system_app_registry.h
  100. apps = bld.path.ant_glob('*', dir=True, src=False)
  101. for app in apps:
  102. build_app(bld, app.name)
  103. # vim:filetype=python