From ef8d82b0afa83a97f3bc9ba5b464d981457f3e85 Mon Sep 17 00:00:00 2001 From: Sunguk Lee Date: Tue, 6 Mar 2018 02:56:41 +0900 Subject: [PATCH] vita-libs-gen: Use firmware field if filled `firmware` in the root and this value isn't `3.60`, will attach postfix before `_stub.a` eg; pass to ``` firmware: 3.67 ``` all generated libs will end with `_367_stub.a` like `libSceCpuForKernel_367_stub.a` Related vitasdk/vita-headers#300 --- src/vita-import-parse.c | 30 +++++++++++---- src/vita-import.c | 9 +++++ src/vita-import.h | 2 + src/vita-libs-gen.c | 82 ++++++++++++++++++++++++----------------- 4 files changed, 82 insertions(+), 41 deletions(-) diff --git a/src/vita-import-parse.c b/src/vita-import-parse.c index 8bad5c5..86322fa 100644 --- a/src/vita-import-parse.c +++ b/src/vita-import-parse.c @@ -213,17 +213,33 @@ vita_imports_t *read_vita_imports(yaml_document *doc) { for(int n = 0; n < root->count; n++){ // check lhs is a scalar if (is_scalar(root->pairs[n]->lhs)) { - - if (strcmp(root->pairs[n]->lhs->data.scalar.value, "modules")==0) { + const char *root_value = root->pairs[n]->lhs->data.scalar.value; + if (strcmp(root_value, "firmware") == 0) { + if (!is_scalar(root->pairs[n]->rhs)) + return NULL; + const char *firm = root->pairs[n]->rhs->data.scalar.value; + // skip default firmware + if (strcmp(firm, "3.60") == 0) + continue; + imports->firmware = strdup(firm); + int i = 0; + int j = 0; + imports->postfix[j++] = '_'; + while (firm[i]) { + const char v = firm[i++]; + if (v == '.') + continue; + imports->postfix[j++] = v; + } + } + else if (strcmp(root_value, "modules") == 0) { if (yaml_iterate_mapping(root->pairs[n]->rhs, (mapping_functor)process_import_list, imports) < 0) return NULL; - continue; } - - fprintf(stderr, "warning: line: %zd, column: %zd, unknow tag '%s'.\n", root->pairs[n]->lhs->position.line, root->pairs[n]->lhs->position.column, root->pairs[n]->lhs->data.scalar.value); - + else { + fprintf(stderr, "warning: line: %zd, column: %zd, unknow tag '%s'.\n", root->pairs[n]->lhs->position.line, root->pairs[n]->lhs->position.column, root->pairs[n]->lhs->data.scalar.value); + } } - } return imports; diff --git a/src/vita-import.c b/src/vita-import.c index 966ae2d..f404d80 100644 --- a/src/vita-import.c +++ b/src/vita-import.c @@ -8,6 +8,10 @@ vita_imports_t *vita_imports_new(int n_libs) if (imp == NULL) return NULL; + imp->postfix = calloc(64, sizeof(char)); + + imp->firmware = NULL; + imp->n_libs = n_libs; imp->libs = calloc(n_libs, sizeof(*imp->libs)); @@ -22,6 +26,11 @@ void vita_imports_free(vita_imports_t *imp) for (i = 0; i < imp->n_libs; i++) { vita_imports_lib_free(imp->libs[i]); } + + if (imp->firmware) + free(imp->firmware); + + free(imp->postfix); free(imp); } } diff --git a/src/vita-import.h b/src/vita-import.h index 916a472..0a87776 100644 --- a/src/vita-import.h +++ b/src/vita-import.h @@ -36,6 +36,8 @@ typedef struct { } vita_imports_lib_t; typedef struct { + char *firmware; + char *postfix; vita_imports_lib_t **libs; int n_libs; } vita_imports_t; diff --git a/src/vita-libs-gen.c b/src/vita-libs-gen.c index 0c46833..8e0aec6 100644 --- a/src/vita-libs-gen.c +++ b/src/vita-libs-gen.c @@ -7,6 +7,14 @@ #define KERNEL_LIBS_STUB "SceKernel" +typedef struct { + int num; + struct { + const char *name; + const char *postfix; + } names[1024]; +} libs_t; + void usage(); int generate_assembly(vita_imports_t **imports, int imports_count); int generate_makefile(vita_imports_t **imports, int imports_count); @@ -92,6 +100,7 @@ int generate_assembly(vita_imports_t **imports, int imports_count) for (h = 0; h < imports_count; h++) { vita_imports_t *imp = imports[h]; + for (i = 0; i < imp->n_libs; i++) { vita_imports_lib_t *library = imp->libs[i]; for (j = 0; j < library->n_modules; j++) { @@ -101,7 +110,7 @@ int generate_assembly(vita_imports_t **imports, int imports_count) vita_imports_stub_t *function = module->functions[k]; const char *fname = function->name; char filename[4096]; - snprintf(filename, sizeof(filename), "%s_%s_%s.S", library->name, module->name, fname); + snprintf(filename, sizeof(filename), "%s_%s_%s%s.S", library->name, module->name, fname, imp->postfix); if ((fp = fopen(filename, "w")) == NULL) return 0; fprintf(fp, ".arch armv7a\n\n"); @@ -129,7 +138,7 @@ int generate_assembly(vita_imports_t **imports, int imports_count) vita_imports_stub_t *variable = module->variables[k]; const char *vname = variable->name; char filename[4096]; - snprintf(filename, sizeof(filename), "%s_%s_%s.S", library->name, module->name, vname); + snprintf(filename, sizeof(filename), "%s_%s_%s%s.S", library->name, module->name, vname, imp->postfix); if ((fp = fopen(filename, "w")) == NULL) return 0; fprintf(fp, ".arch armv7a\n\n"); @@ -177,21 +186,21 @@ void write_symbol(const char *symbol, int is_kernel) fprintf(fp, "%s", symbol); // write regardless if its kernel or not } -void write_cmake_sources(FILE *fp, const char *modname, vita_imports_module_t *library) +void write_cmake_sources(FILE *fp, const char *modname, const char *postfix, vita_imports_module_t *library) { int k; for (k = 0; k < library->n_functions; k++) { vita_imports_stub_t *function = library->functions[k]; - fprintf(fp, "\t\"%s_%s_%s.S\"\n", modname, library->name, function->name); + fprintf(fp, "\t\"%s_%s_%s%s.S\"\n", modname, library->name, function->name, postfix); } for (k = 0; k < library->n_variables; k++) { vita_imports_stub_t *variable = library->variables[k]; - fprintf(fp, "\t\"%s_%s_%s.S\"\n", modname, library->name, variable->name); + fprintf(fp, "\t\"%s_%s_%s%s.S\"\n", modname, library->name, variable->name, postfix); } } -int generate_cmake_user(FILE *fp, vita_imports_lib_t *module) +int generate_cmake_user(FILE *fp, const char *postfix, vita_imports_lib_t *module) { int i; int found_libs = 0; @@ -206,11 +215,11 @@ int generate_cmake_user(FILE *fp, vita_imports_lib_t *module) if (!found_libs) { - fprintf(fp, "set(%s_ASM\n", module->name); + fprintf(fp, "set(%s%s_ASM\n", module->name, postfix); found_libs = 1; } - write_cmake_sources(fp, module->name, library); + write_cmake_sources(fp, module->name, postfix, library); } if (found_libs) @@ -221,13 +230,13 @@ int generate_cmake_user(FILE *fp, vita_imports_lib_t *module) return found_libs; } -int generate_cmake_kernel(FILE *fp, const char *modname, vita_imports_module_t *library) +int generate_cmake_kernel(FILE *fp, const char *modname, const char *postfix, vita_imports_module_t *library) { if (!library->n_functions && !library->n_variables) return 0; - fprintf(fp, "set(%s_ASM\n", library->name); - write_cmake_sources(fp, modname, library); + fprintf(fp, "set(%s%s_ASM\n", library->name, postfix); + write_cmake_sources(fp, modname, postfix, library); fputs(")\n\n", fp); return 1; @@ -239,10 +248,8 @@ int generate_cmake(vita_imports_t **imports, int imports_count) int is_special; // TODO: something dynamic - const char *user_libs[1024]; - int num_user_libs = 0; - const char *kernel_libs[1024]; - int num_kernel_libs = 0; + libs_t user_libs = {0}; + libs_t kernel_libs = {0}; if ((fp = fopen("CMakeLists.txt", "w")) == NULL) { return 0; @@ -269,9 +276,11 @@ int generate_cmake(vita_imports_t **imports, int imports_count) vita_imports_lib_t *module = imp->libs[i]; // generate user libs first - if (generate_cmake_user(fp, module)) + if (generate_cmake_user(fp, imp->postfix, module)) { - user_libs[num_user_libs++] = module->name; + user_libs.names[user_libs.num].name = module->name; + user_libs.names[user_libs.num].postfix = imp->postfix; + user_libs.num++; } for (j = 0; j < imp->libs[i]->n_modules; j++) @@ -281,39 +290,41 @@ int generate_cmake(vita_imports_t **imports, int imports_count) if (!library->is_kernel) continue; - if (generate_cmake_kernel(fp, module->name, library)) + if (generate_cmake_kernel(fp, module->name, imp->postfix, library)) { - kernel_libs[num_kernel_libs++] = library->name; + kernel_libs.names[kernel_libs.num].name = library->name; + kernel_libs.names[kernel_libs.num].postfix = imp->postfix; + kernel_libs.num++; } } } } - if (num_user_libs > 0) + if (user_libs.num > 0) { fputs("set(USER_LIBRARIES\n", fp); - for (i = 0; i < num_user_libs; ++i) + for (i = 0; i < user_libs.num; ++i) { - fprintf(fp, "\t\"%s\"\n", user_libs[i]); + fprintf(fp, "\t\"%s%s\"\n", user_libs.names[i].name, user_libs.names[i].postfix); } fputs(")\n\n", fp); } - if (num_kernel_libs > 0) + if (kernel_libs.num > 0) { fputs("set(KERNEL_LIBRARIES\n", fp); - for (i = 0; i < num_kernel_libs; ++i) + for (i = 0; i < kernel_libs.num; ++i) { - fprintf(fp, "\t\"%s\"\n", kernel_libs[i]); + fprintf(fp, "\t\"%s%s\"\n", kernel_libs.names[i].name, kernel_libs.names[i].postfix); } fputs(")\n\n", fp); } - if (num_user_libs > 0) + if (user_libs.num > 0) { fputs( "foreach(library ${USER_LIBRARIES})\n" @@ -324,7 +335,7 @@ int generate_cmake(vita_imports_t **imports, int imports_count) "endforeach(library)\n\n", fp); } - if (num_kernel_libs > 0) + if (kernel_libs.num > 0) { fputs( "foreach(library ${KERNEL_LIBRARIES})\n" @@ -363,8 +374,9 @@ int generate_makefile(vita_imports_t **imports, int imports_count) for (h = 0; h < imports_count; h++) { vita_imports_t *imp = imports[h]; + for (i = 0; i < imp->n_libs; i++) { - fprintf(fp, " lib%s_stub.a", imp->libs[i]->name); + fprintf(fp, " lib%s%s_stub.a", imp->libs[i]->name, imp->postfix); for (j = 0; j < imp->libs[i]->n_modules; j++) { vita_imports_module_t *module = imp->libs[i]->modules[j]; @@ -372,7 +384,7 @@ int generate_makefile(vita_imports_t **imports, int imports_count) if (!module->is_kernel) continue; - fprintf(fp, " lib%s_stub.a", module->name); + fprintf(fp, " lib%s%s_stub.a", module->name, imp->postfix); } } } @@ -380,8 +392,9 @@ int generate_makefile(vita_imports_t **imports, int imports_count) fprintf(fp, "\nTARGETS_WEAK ="); for (h = 0; h < imports_count; h++) { vita_imports_t *imp = imports[h]; + for (i = 0; i < imp->n_libs; i++) { - fprintf(fp, " lib%s_stub_weak.a", imp->libs[i]->name); + fprintf(fp, " lib%s%s_stub_weak.a", imp->libs[i]->name, imp->postfix); } } @@ -389,6 +402,7 @@ int generate_makefile(vita_imports_t **imports, int imports_count) for (h = 0; h < imports_count; h++) { vita_imports_t *imp = imports[h]; + for (i = 0; i < imp->n_libs; i++) { vita_imports_lib_t *library = imp->libs[i]; is_special = (strcmp(KERNEL_LIBS_STUB, library->name) == 0); @@ -407,12 +421,12 @@ int generate_makefile(vita_imports_t **imports, int imports_count) char buf[4096]; for (k = 0; k < module->n_functions; k++) { vita_imports_stub_t *function = module->functions[k]; - snprintf(buf, sizeof(buf), " %s_%s_%s.%s", library->name, module->name, function->name, weak ? "wo" : "o"); + snprintf(buf, sizeof(buf), " %s_%s_%s%s.%s", library->name, module->name, function->name, imp->postfix, weak ? "wo" : "o"); write_symbol(buf, is_special); } for (k = 0; k < module->n_variables; k++) { vita_imports_stub_t *variable = module->variables[k]; - snprintf(buf, sizeof(buf), " %s_%s_%s.%s", library->name, module->name, variable->name, weak ? "wo" : "o"); + snprintf(buf, sizeof(buf), " %s_%s_%s%s.%s", library->name, module->name, variable->name, imp->postfix, weak ? "wo" : "o"); write_symbol(buf, is_special); } } @@ -434,13 +448,13 @@ int generate_makefile(vita_imports_t **imports, int imports_count) for (k = 0; k < module->n_functions; k++) { vita_imports_stub_t *function = module->functions[k]; - snprintf(buf, sizeof(buf), " %s_%s_%s.o", library->name, module->name, function->name); + snprintf(buf, sizeof(buf), " %s_%s_%s%s.o", library->name, module->name, function->name, imp->postfix); write_symbol(buf, 1); } for (k = 0; k < module->n_variables; k++) { vita_imports_stub_t *variable = module->variables[k]; - snprintf(buf, sizeof(buf), " %s_%s_%s.o", library->name, module->name, variable->name); + snprintf(buf, sizeof(buf), " %s_%s_%s%s.o", library->name, module->name, variable->name, imp->postfix); write_symbol(buf, 1); }