From: Alan Cox Date: Sun, 20 Mar 2016 21:03:20 +0000 (+0000) Subject: fcc: support -o option with -c X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=480cb6ea79a2936e5d1b725871febe6fae1720f2;p=FUZIX.git fcc: support -o option with -c --- diff --git a/Library/tools/fcc.c b/Library/tools/fcc.c index f46486b8..fa8b5a96 100644 --- a/Library/tools/fcc.c +++ b/Library/tools/fcc.c @@ -236,6 +236,18 @@ static char *rebuildname(const char *r, const char *i, char *ext) return p; } +char *filebasename(char *path) +{ + /* The POSIX one can mangle the input - so given its trivial do it + sanely ourselves */ + char *p = strrchr(path, '/'); + if (p == NULL) + return path; + /* We don't care about trailing slashes, we only work on files */ + return p + 1; +} + + static char *chopname(const char *i) { char *p = mstrdup(i); @@ -400,6 +412,10 @@ static void build_command(void) exit(1); } add_argument("-c"); + if (srchead->next && target) { + fprintf(stderr, "Cannot use -c together with -o with multiple input files.\n"); + exit(1); + } } if (mode == MODE_LINK) { if (target == NULL) @@ -536,6 +552,14 @@ int main(int argc, const char *argv[]) { ret = do_command(); if (ret) break; + if (mode == MODE_OBJ && target) { + char *orel = filebasename(rebuildname("", srchead->p, "rel")); + if (rename(orel, target) == -1) { + fprintf(stderr, "Unable to rename %s to %s.\n", orel, target); + perror(srchead->p); + exit(1); + } + } srchead = srchead->next; argp = 0; }