From 2976cecf4e13db1ac5d4c20aaac483e6116a9405 Mon Sep 17 00:00:00 2001 From: "Magomed Kostoev (mkostoevr)" Date: Sat, 24 Jul 2021 08:39:13 +0000 Subject: [PATCH] [clink] Update to revision ed897ae9c5dd7e13444aad65506698a34802a69e - Allow to set output file name git-svn-id: svn://kolibrios.org@9080 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/develop/clink/main.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/programs/develop/clink/main.c b/programs/develop/clink/main.c index 53ac412135..66c34add19 100644 --- a/programs/develop/clink/main.c +++ b/programs/develop/clink/main.c @@ -164,8 +164,8 @@ static void add_name_to_set(char *sym_name, char ***set) { cvec_pchar_push_back(set, sym_name); } -static void build(ObjectIr *ir) { - FILE *out = fopen("a.out.obj", "wb"); +static void build(ObjectIr *ir, const char *outname) { + FILE *out = fopen(outname, "wb"); char *strtab = cvec_char_new(1024); size_t size_of_sections = 0; size_t number_of_relocations = 0; @@ -624,8 +624,30 @@ static ObjectIr parse_objects(int argc, char **argv) { return ir; } +int first_arg(int argc, char **argv, const char *arg) { + return argc >= 2 && !strcmp(argv[1], arg); +} + int main(int argc, char **argv) { + const char *outname = "a.out.obj"; + + if (argc >= 3 && !strcmp(argv[1], "-o")) { + outname = argv[2]; + argv += 2; + argc -= 2; + } else if (first_arg(argc, argv, "-h") + || first_arg(argc, argv, "-help") + || first_arg(argc, argv, "--help") + || argc == 1) { + printf("Usage cases:\n"); + printf(" %s [-o outname] object files list\n", argv[0]); + printf(" Link COFF files into one, optionally set name of output\n"); + printf(" %s [-h|-help|--help]\n", argv[0]); + printf(" Output this help\n"); + return 0; + } + ObjectIr ir = parse_objects(argc, argv); - build(&ir); + build(&ir, outname); return 0; }