Mkprom2 linking library issue

I’m trying to use the mkprom2 program to produce an ROM file to be integrated in my firmware. The problem: it expects a list of files in elf (or aout) format while I want to give it some libxxx.a archives as one would give to ld.
The interesting thing is that it actually uses ld (or gcc) under the hood to do the actual linking.

As the source of mkprom2 is available, I changed it a little, like

    if (strcmp(fn + strlen(fn) - 2, ".a") == 0) {
        char *lib = strrchr(fn, '/');
        if (lib == NULL) lib = fn; 
        else lib++;

        if (strncmp(lib, "lib", 3)) {
            fprintf(stderr, "bad file name %s\n", fn, result);
            exit(1);
        } else {
            // unpack the lib and scan it
            char template[] = "/tmp/tmpdir.XXXXXX";
            char *tmp_dirname = mkdtemp(template);
            char arcmd[256];
            sprintf(arcmd, "ar xv --output %s %s", tmp_dirname, fn);
            trysystem(arcmd);
            scanDir(tmp_dirname);
        }   
    }

where “scanDir” scans over the directory and runs the usual “elf_load” on the .o files in it as the original program would do. This does include some .o files that will not end up in the final ROM.

It seems to work fine now, but it feels like an ugly hack to me. There should be a more sensible way to process archive library?

I’m happy to share the version I created of course.