Exemplo n.º 1
0
void makefile_create_target(struct makefile *m, const char *name)
{
    assert(m->state == MAKEFILE_STATE_NONE);
    m->state = MAKEFILE_STATE_TARGET;

    if (stringlist_include(m->every_target, name)) {
        m->skip_target = true;
    }
    else {
        char *tmp;

        tmp = talloc_strdup(m, name);
        stringlist_add(m->every_target, tmp);
        talloc_unlink(m, tmp);
        fprintf(m->file, "%s:", name);
        m->skip_target = false;
    }
}
Exemplo n.º 2
0
int context_source_destructor(struct context *c)
{
    struct language *l;
    void *context;
    const char *obj_name;

    assert(c->type == CONTEXT_TYPE_SOURCE);
#ifdef DEBUG
    fprintf(stderr, "context_source_destructor('%s', '%s')\n",
            c->full_path, c->parent->full_path);
#endif

    /* Try to find a language that's compatible with the language already used
     * in this binary, and is compatible with this current source file. */
    l = languagelist_search(c->ll, c->parent->language, c->full_path, c);
    if (l == NULL) {
        fprintf(stderr, "No language found for '%s'\n", c->full_path);

        if ((c->parent == NULL) || (c->parent->language == NULL))
            abort();

        fprintf(stderr, "Parent language is '%s', from '%s'\n",
                c->parent->language->name, c->parent->full_path);
        abort();
    }
    c->parent->language = l;
#ifdef DEBUG
    fprintf(stderr, "\tc->parent->language->name: '%s'\n",
            c->parent->language->name);
#endif

    /* Try and figure out if the grandparent of this code should be a
     * shared or static library. */
    if (l->cares_about_static == true) {
        struct context *lc;

        lc = c;
        while (lc != NULL) {
            if (lc->type == CONTEXT_TYPE_LIBRARY)
                break;

            if (lc->parent == lc) {
                lc = NULL;
                break;
            }

            lc = lc->parent;
        }

        /* It's very possible we ended up with something that
         * _doesn't_ target a library, which is perfectly fine. */
        if (lc != NULL) {
            char *ext;

            ext = strstr(lc->full_path, ".");
            if (ext == NULL)
                abort();
            ext++;

            if (strcmp(ext, lc->language->so_ext_canon) == 0)
                c->shared_target = true;
            else if (strcmp(ext, lc->language->a_ext_canon) == 0)
                c->shared_target = false;
            else
                abort();
        }
    }

    /* We need to allocate some temporary memory */
    context = talloc_new(NULL);

    /* Some languages don't need to be compiled (just linked) so we skip the
     * entire compiling phase. */
    if (language_needs_compile(l, c) == true) {
        /* This is the name that our code will be compiled into.  This must
         * succeed, as we just checked that it's necessary. */
        obj_name = language_objname(l, context, c);
        assert(obj_name != NULL);

        /* This handles half of the whole "--binname --objname" stuff,
         * which is why it's so messy! */
        if (found_binary && c->called_path != NULL) {
            if (strcmp(c->called_path, o->srcname) == 0) {
                printf("%s\n", obj_name);
                talloc_disable_null_tracking();
                exit(0);
            }
        }

        /* If we've already built this dependency, then it's not necessary to
         * add it to the build list again, so skip it. */
        if (!stringlist_include(c->mf->targets, obj_name)) {
            makefile_add_targets(c->mf, obj_name);
            makefile_create_target(c->mf, obj_name);

            makefile_start_deps(c->mf);
            language_deps_vadd_dep(l, c, c->mf);
            makefile_end_deps(c->mf);

            makefile_start_cmds(c->mf);
            language_build_pass_vcmd(l, c);
            makefile_end_cmds(c->mf);

            makefile_add_targets(c->mf, obj_name);
            makefile_add_clean(c->mf, obj_name);
            makefile_add_cleancache(c->mf, c->obj_dir);
        }
    } else {
        /* The "objects" for languages that aren't compiled are really just the
         * included sources. */
        obj_name = talloc_reference(context, c->full_path);
    }

    /* Adds every "extra" (which is defined as any other sources that should be 
     * linked in as a result of this SOURCES += line) to the stack. */
    if (stringlist_include(c->parent->objects, obj_name) == false) {
        language_extras_pass_cs_push_fs(l, c, context, c->s);
        stringlist_add(c->parent->objects, obj_name);
    }

    /* Run some language-specific quirks here */
    language_quirks(l, c, c->mf);

    /* Everything succeeded! */
    TALLOC_FREE(context);
    return 0;
}