def generate_resource_index(target, source, env): res_source_path = str(target[0]) res_header_path = str(target[1]) if not os.path.exists(os.path.dirname(res_header_path)): os.mkdir(os.path.dirname(res_header_path)) h = open(res_header_path, 'w') c = open(res_source_path, 'w') source_path = env["SOURCE_PATH"] full_name = blade_util.regular_variable_name( "%s/%s" % (source_path, env["TARGET_NAME"])) guard_name = 'BLADE_RESOURCE_%s_H' % full_name.upper() print >> h, '#ifndef %s\n#define %s' % (guard_name, guard_name) print >> h, ''' // This file was automatically generated by blade #ifdef __cplusplus extern "C" { #endif #ifndef BLADE_RESOURCE_TYPE_DEFINED #define BLADE_RESOURCE_TYPE_DEFINED struct BladeResourceEntry { const char* name; const char* data; unsigned int size; }; #endif ''' res_index_name = 'RESOURCE_INDEX_%s' % full_name print >> c, '// This file was automatically generated by blade\n' print >> c, '#include "%s"\n' % res_header_path print >> c, 'const struct BladeResourceEntry %s[] = {' % res_index_name for s in source: src = str(s) var_name = blade_util.regular_variable_name(src) org_src = blade_util.relative_path(src, source_path) print >> h, '// %s' % org_src print >> h, 'extern const char RESOURCE_%s[%d];' % (var_name, s.get_size()) print >> h, 'extern const unsigned RESOURCE_%s_len;\n' % var_name print >> c, ' { "%s", RESOURCE_%s, %s },' % (org_src, var_name, s.get_size()) print >> c, '};' print >> c, 'const unsigned %s_len = %s;' % (res_index_name, len(source)) print >> h, '// Resource index' print >> h, 'extern const struct BladeResourceEntry %s[];' % res_index_name print >> h, 'extern const unsigned %s_len;' % res_index_name print >> h, '\n#ifdef __cplusplus\n} // extern "C"\n#endif\n' print >> h, '\n#endif // %s' % guard_name c.close() h.close()
def generate_resource_index(targets, sources, name, path): header, source = targets h, c = open(header, 'w'), open(source, 'w') full_name = blade_util.regular_variable_name(os.path.join(path, name)) guard_name = 'BLADE_RESOURCE_%s_H_' % full_name.upper() index_name = 'RESOURCE_INDEX_%s' % full_name print >> h, '''// This file was automatically generated by blade #ifndef {0} #define {0} #ifdef __cplusplus extern "C" {{ #endif #ifndef BLADE_RESOURCE_TYPE_DEFINED #define BLADE_RESOURCE_TYPE_DEFINED struct BladeResourceEntry {{ const char* name; const char* data; unsigned int size; }}; #endif '''.format(guard_name) print >> c, '''// This file was automatically generated by blade #include "{0}" const struct BladeResourceEntry {1}[] = {{'''.format(header, index_name) for s in sources: entry_var = blade_util.regular_variable_name(s) entry_name = os.path.relpath(s, path) entry_size = os.path.getsize(s) print >> h, '// %s' % entry_name print >> h, 'extern const char RESOURCE_%s[%d];' % (entry_var, entry_size) print >> h, 'extern const unsigned RESOURCE_%s_len;\n' % entry_var print >> c, ' { "%s", RESOURCE_%s, %s },' % (entry_name, entry_var, entry_size) print >> c, '''}}; const unsigned {0}_len = {1};'''.format(index_name, len(sources)) print >> h, '''// Resource index extern const struct BladeResourceEntry {0}[]; extern const unsigned {0}_len; #ifdef __cplusplus }} // extern "C" #endif #endif // {1}'''.format(index_name, guard_name) h.close() c.close()
def generate_resource_index(target, source, env): res_source_path = str(target[0]) res_header_path = str(target[1]) if not os.path.exists(os.path.dirname(res_header_path)): os.mkdir(os.path.dirname(res_header_path)) h = open(res_header_path, 'w') c = open(res_source_path, 'w') source_path = env["SOURCE_PATH"] full_name = blade_util.regular_variable_name("%s/%s" % (source_path, env["TARGET_NAME"])) guard_name = 'BLADE_RESOURCE_%s_H' % full_name.upper() print >>h, '#ifndef %s\n#define %s' % (guard_name, guard_name) print >>h, ''' // This file was automatically generated by blade #ifdef __cplusplus extern "C" { #endif #ifndef BLADE_RESOURCE_TYPE_DEFINED #define BLADE_RESOURCE_TYPE_DEFINED struct BladeResourceEntry { const char* name; const char* data; unsigned int size; }; #endif ''' res_index_name = 'RESOURCE_INDEX_%s' % full_name print >>c, '// This file was automatically generated by blade\n' print >>c, '#include "%s"\n' % res_header_path print >>c, 'const struct BladeResourceEntry %s[] = {' % res_index_name for s in source: src = str(s) var_name = blade_util.regular_variable_name(src) org_src = blade_util.relative_path(src, source_path) print >>h, '// %s' % org_src print >>h, 'extern const char RESOURCE_%s[%d];' % (var_name, s.get_size()) print >>h, 'extern const unsigned RESOURCE_%s_len;\n' % var_name print >>c, ' { "%s", RESOURCE_%s, %s },' % (org_src, var_name, s.get_size()) print >>c, '};' print >>c, 'const unsigned %s_len = %s;' % (res_index_name, len(source)) print >>h, '// Resource index' print >>h, 'extern const struct BladeResourceEntry %s[];' % res_index_name print >>h, 'extern const unsigned %s_len;' % res_index_name print >>h, '\n#ifdef __cplusplus\n} // extern "C"\n#endif\n' print >>h, '\n#endif // %s' % guard_name c.close() h.close()
def generate_resource_index(targets, sources, name, path): header, source = targets h, c = open(header, 'w'), open(source, 'w') full_name = blade_util.regular_variable_name(os.path.join(path, name)) guard_name = 'BLADE_RESOURCE_%s_H_' % full_name.upper() index_name = 'RESOURCE_INDEX_%s' % full_name print >>h, '''// This file was automatically generated by blade #ifndef {0} #define {0} #ifdef __cplusplus extern "C" {{ #endif #ifndef BLADE_RESOURCE_TYPE_DEFINED #define BLADE_RESOURCE_TYPE_DEFINED struct BladeResourceEntry {{ const char* name; const char* data; unsigned int size; }}; #endif '''.format(guard_name) print >>c, '''// This file was automatically generated by blade #include "{0}" const struct BladeResourceEntry {1}[] = {{'''.format(header, index_name) for s in sources: entry_var = blade_util.regular_variable_name(s) entry_name = os.path.relpath(s, path) entry_size = os.path.getsize(s) print >>h, '// %s' % entry_name print >>h, 'extern const char RESOURCE_%s[%d];' % (entry_var, entry_size) print >>h, 'extern const unsigned RESOURCE_%s_len;\n' % entry_var print >>c, ' { "%s", RESOURCE_%s, %s },' % (entry_name, entry_var, entry_size) print >>c, '''}}; const unsigned {0}_len = {1};'''.format(index_name, len(sources)) print >>h, '''// Resource index extern const struct BladeResourceEntry {0}[]; extern const unsigned {0}_len; #ifdef __cplusplus }} // extern "C" #endif #endif // {1}'''.format(index_name, guard_name) h.close() c.close()