Blame agen5/agDep.c

Packit Service 96b5d3
Packit Service 96b5d3
/**
Packit Service 96b5d3
 * @file agDep.c
Packit Service 96b5d3
 *
Packit Service 96b5d3
 *  This module will load a template and return a template structure.
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * @addtogroup autogen
Packit Service 96b5d3
 * @{
Packit Service 96b5d3
 */
Packit Service 96b5d3
/*
Packit Service 96b5d3
 * This file is part of AutoGen.
Packit Service 96b5d3
 * Copyright (C) 1992-2016 Bruce Korb - all rights reserved
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * AutoGen is free software: you can redistribute it and/or modify it
Packit Service 96b5d3
 * under the terms of the GNU General Public License as published by the
Packit Service 96b5d3
 * Free Software Foundation, either version 3 of the License, or
Packit Service 96b5d3
 * (at your option) any later version.
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * AutoGen is distributed in the hope that it will be useful, but
Packit Service 96b5d3
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 96b5d3
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Packit Service 96b5d3
 * See the GNU General Public License for more details.
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * You should have received a copy of the GNU General Public License along
Packit Service 96b5d3
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit Service 96b5d3
 */
Packit Service 96b5d3
Packit Service 96b5d3
typedef struct flist flist_t;
Packit Service 96b5d3
struct flist {
Packit Service 96b5d3
    flist_t *   next;
Packit Service 96b5d3
    char        fname[1];
Packit Service 96b5d3
};
Packit Service 96b5d3
Packit Service 96b5d3
static flist_t * src_flist  = NULL;
Packit Service 96b5d3
static flist_t * targ_flist = NULL;
Packit Service 96b5d3
Packit Service 96b5d3
/**
Packit Service 96b5d3
 *  Add a source file to the dependency list
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * @param pz pointer to file name
Packit Service 96b5d3
 */
Packit Service 96b5d3
LOCAL void
Packit Service 96b5d3
add_source_file(char const * pz)
Packit Service 96b5d3
{
Packit Service 96b5d3
    flist_t ** lp;
Packit Service 96b5d3
Packit Service 96b5d3
    /*
Packit Service 96b5d3
     * If a source is also a target, then we've created it.
Packit Service 96b5d3
     * Do not list in source dependencies.
Packit Service 96b5d3
     */
Packit Service 96b5d3
    lp = &targ_flist;
Packit Service 96b5d3
    while (*lp != NULL) {
Packit Service 96b5d3
        if (strcmp(pz, (*lp)->fname) == 0)
Packit Service 96b5d3
            return;
Packit Service 96b5d3
        lp = &((*lp)->next);
Packit Service 96b5d3
    }
Packit Service 96b5d3
Packit Service 96b5d3
    /*
Packit Service 96b5d3
     * No check for duplicate in source list.  Add if not found.
Packit Service 96b5d3
     */
Packit Service 96b5d3
    lp = &src_flist;
Packit Service 96b5d3
    while (*lp != NULL) {
Packit Service 96b5d3
        if (strcmp(pz, (*lp)->fname) == 0)
Packit Service 96b5d3
            return;
Packit Service 96b5d3
        lp = &((*lp)->next);
Packit Service 96b5d3
    }
Packit Service 96b5d3
Packit Service 96b5d3
    {
Packit Service 96b5d3
        size_t    l = strlen(pz);
Packit Service 96b5d3
        flist_t * p = AGALOC(sizeof(*p) + l, "sfile");
Packit Service 96b5d3
        *lp = p;
Packit Service 96b5d3
        p->next = NULL;
Packit Service 96b5d3
        memcpy(p->fname, pz, l + 1);
Packit Service 96b5d3
        if (OPT_VALUE_TRACE >= TRACE_SERVER_SHELL)
Packit Service 96b5d3
            fprintf(trace_fp, TRACE_ADD_SRC_FILE_FMT, p->fname);
Packit Service 96b5d3
    }
Packit Service 96b5d3
}
Packit Service 96b5d3
Packit Service 96b5d3
/**
Packit Service 96b5d3
 *  remove a source file from the dependency list
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * @param pz pointer to file name
Packit Service 96b5d3
 */
Packit Service 96b5d3
LOCAL void
Packit Service 96b5d3
rm_source_file(char const * pz)
Packit Service 96b5d3
{
Packit Service 96b5d3
    flist_t ** pp = &src_flist; //!< point to where to stash removed "next"
Packit Service 96b5d3
    flist_t ** lp = &src_flist; //!< list scanning pointer
Packit Service 96b5d3
Packit Service 96b5d3
    for (;;) {
Packit Service 96b5d3
        if (*lp == NULL)
Packit Service 96b5d3
            return;
Packit Service 96b5d3
        if (strcmp(pz, (*lp)->fname) == 0)
Packit Service 96b5d3
            break;
Packit Service 96b5d3
        pp = lp;
Packit Service 96b5d3
        lp = &((*lp)->next);
Packit Service 96b5d3
    }
Packit Service 96b5d3
    {
Packit Service 96b5d3
        flist_t * p = *lp;
Packit Service 96b5d3
        *pp = p->next;
Packit Service 96b5d3
        if (OPT_VALUE_TRACE >= TRACE_SERVER_SHELL)
Packit Service 96b5d3
            fprintf(trace_fp, TRACE_RM_SRC_FILE_FMT, p->fname);
Packit Service 96b5d3
        AGFREE(p);
Packit Service 96b5d3
    }
Packit Service 96b5d3
}
Packit Service 96b5d3
Packit Service 96b5d3
/**
Packit Service 96b5d3
 *  Add a target file to the dependency list.  Avoid files in temp directories.
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * @param pz pointer to file name
Packit Service 96b5d3
 */
Packit Service 96b5d3
LOCAL void
Packit Service 96b5d3
add_target_file(char const * pz)
Packit Service 96b5d3
{
Packit Service 96b5d3
    flist_t ** lp;
Packit Service 96b5d3
Packit Service 96b5d3
    /*
Packit Service 96b5d3
     *  Skip anything stashed in the temp directory.
Packit Service 96b5d3
     */
Packit Service 96b5d3
    if (  (temp_tpl_dir_len > 0)
Packit Service 96b5d3
       && (strncmp(pz, pz_temp_tpl, temp_tpl_dir_len) == 0)
Packit Service 96b5d3
       && (pz[temp_tpl_dir_len] == NUL))
Packit Service 96b5d3
        return;
Packit Service 96b5d3
Packit Service 96b5d3
    /*
Packit Service 96b5d3
     *  Target files override sources, just in case.
Packit Service 96b5d3
     *  (We sometimes extract from files we are about to replace.)
Packit Service 96b5d3
     */
Packit Service 96b5d3
    rm_source_file(pz);
Packit Service 96b5d3
Packit Service 96b5d3
    /*
Packit Service 96b5d3
     *  avoid duplicates and add to end of list
Packit Service 96b5d3
     */
Packit Service 96b5d3
    lp = &targ_flist;
Packit Service 96b5d3
    while (*lp != NULL) {
Packit Service 96b5d3
        if (strcmp(pz, (*lp)->fname) == 0)
Packit Service 96b5d3
            return;
Packit Service 96b5d3
        lp = &((*lp)->next);
Packit Service 96b5d3
    }
Packit Service 96b5d3
Packit Service 96b5d3
    {
Packit Service 96b5d3
        size_t    l = strlen(pz);
Packit Service 96b5d3
        flist_t * p = AGALOC(sizeof(*p) + l, "tfile");
Packit Service 96b5d3
        *lp = p;
Packit Service 96b5d3
        p->next = NULL;
Packit Service 96b5d3
        memcpy(p->fname, pz, l + 1);
Packit Service 96b5d3
        if (OPT_VALUE_TRACE >= TRACE_SERVER_SHELL)
Packit Service 96b5d3
            fprintf(trace_fp, TRACE_ADD_TARG_FILE_FMT, p->fname);
Packit Service 96b5d3
    }
Packit Service 96b5d3
}
Packit Service 96b5d3
Packit Service 96b5d3
/**
Packit Service 96b5d3
 *  Remove a target file from the dependency list
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * @param pz pointer to file name
Packit Service 96b5d3
 */
Packit Service 96b5d3
LOCAL void
Packit Service 96b5d3
rm_target_file(char const * pz)
Packit Service 96b5d3
{
Packit Service 96b5d3
    flist_t ** lp = &targ_flist; //!< list scanning pointer
Packit Service 96b5d3
Packit Service 96b5d3
    for (;;) {
Packit Service 96b5d3
        if (*lp == NULL)
Packit Service 96b5d3
            return;
Packit Service 96b5d3
        if (strcmp(pz, (*lp)->fname) == 0)
Packit Service 96b5d3
            break;
Packit Service 96b5d3
        lp = &((*lp)->next);
Packit Service 96b5d3
    }
Packit Service 96b5d3
    {
Packit Service 96b5d3
        flist_t * p = *lp;
Packit Service 96b5d3
        *lp = p->next;
Packit Service 96b5d3
        if (OPT_VALUE_TRACE >= TRACE_SERVER_SHELL)
Packit Service 96b5d3
            fprintf(trace_fp, TRACE_RM_TARG_FILE_FMT, p->fname);
Packit Service 96b5d3
        AGFREE(p);
Packit Service 96b5d3
    }
Packit Service 96b5d3
}
Packit Service 96b5d3
Packit Service 96b5d3
/**
Packit Service 96b5d3
 * Create a dependency output file
Packit Service 96b5d3
 */
Packit Service 96b5d3
LOCAL void
Packit Service 96b5d3
start_dep_file(void)
Packit Service 96b5d3
{
Packit Service 96b5d3
    /*
Packit Service 96b5d3
     * Set dep_file to a temporary file name
Packit Service 96b5d3
     */
Packit Service 96b5d3
    {
Packit Service 96b5d3
        char * tfile_name;
Packit Service 96b5d3
        size_t dep_name_len;
Packit Service 96b5d3
        int    fd;
Packit Service 96b5d3
Packit Service 96b5d3
        if (dep_file == NULL) {
Packit Service 96b5d3
            dep_name_len = strlen(OPT_ARG(BASE_NAME));
Packit Service 96b5d3
            tfile_name = AGALOC(dep_name_len + TEMP_SUFFIX_LEN + 1, "dfileb");
Packit Service 96b5d3
            memcpy(tfile_name, OPT_ARG(BASE_NAME), dep_name_len);
Packit Service 96b5d3
            memcpy(tfile_name + dep_name_len, TEMP_SUFFIX,
Packit Service 96b5d3
                   TEMP_SUFFIX_LEN + 1);
Packit Service 96b5d3
Packit Service 96b5d3
        } else {
Packit Service 96b5d3
            dep_name_len = strlen(dep_file);
Packit Service 96b5d3
            tfile_name = AGALOC(dep_name_len + TEMP_SUFFIX_LEN, "dfile");
Packit Service 96b5d3
            memcpy(tfile_name, dep_file, dep_name_len);
Packit Service 96b5d3
            memcpy(tfile_name + dep_name_len, TEMP_SUFFIX + 2,
Packit Service 96b5d3
                   TEMP_SUFFIX_LEN - 1);
Packit Service 96b5d3
        }
Packit Service 96b5d3
Packit Service 96b5d3
        if (dep_target == NULL) {
Packit Service 96b5d3
            /*
Packit Service 96b5d3
             * If there is no target name, then the target is our output file.
Packit Service 96b5d3
             */
Packit Service 96b5d3
            char * q = AGALOC(dep_name_len + 1, "t-name");
Packit Service 96b5d3
            dep_target = q;
Packit Service 96b5d3
            memcpy(q, tfile_name, dep_name_len);
Packit Service 96b5d3
            q[dep_name_len] = NUL;
Packit Service 96b5d3
        }
Packit Service 96b5d3
Packit Service 96b5d3
        fd = mkstemp(tfile_name);
Packit Service 96b5d3
        if (fd < 0)
Packit Service 96b5d3
            AG_CANT(START_DEP_FOPEN_MSG, tfile_name);
Packit Service 96b5d3
        dep_file = tfile_name;
Packit Service 96b5d3
Packit Service 96b5d3
        /*
Packit Service 96b5d3
         * Create the file and write the leader.
Packit Service 96b5d3
         */
Packit Service 96b5d3
        dep_fp = fdopen(fd, "w");
Packit Service 96b5d3
    }
Packit Service 96b5d3
Packit Service 96b5d3
    if (dep_fp == NULL)
Packit Service 96b5d3
        AG_CANT(START_DEP_FOPEN_MSG, dep_file);
Packit Service 96b5d3
Packit Service 96b5d3
    fprintf(dep_fp, START_DEP_FILE_FMT, autogenOptions.pzProgPath);
Packit Service 96b5d3
Packit Service 96b5d3
    {
Packit Service 96b5d3
        int     ac = (int)autogenOptions.origArgCt - 1;
Packit Service 96b5d3
        char ** av = autogenOptions.origArgVect + 1;
Packit Service 96b5d3
Packit Service 96b5d3
        for (;;) {
Packit Service 96b5d3
            char * arg = *(av++);
Packit Service 96b5d3
            fprintf(dep_fp, START_DEP_ARG_FMT, arg);
Packit Service 96b5d3
            if (--ac == 0) break;
Packit Service 96b5d3
            fputs(DEP_FILE_SPLICE_STR, dep_fp);
Packit Service 96b5d3
        }
Packit Service 96b5d3
        putc('\n', dep_fp);
Packit Service 96b5d3
    }
Packit Service 96b5d3
Packit Service 96b5d3
    {
Packit Service 96b5d3
        char const * pnm = autogenOptions.pzPROGNAME;
Packit Service 96b5d3
        char const * bnm = strchr(dep_target, '/');
Packit Service 96b5d3
        char * pz;
Packit Service 96b5d3
Packit Service 96b5d3
        if (bnm != NULL)
Packit Service 96b5d3
            bnm++;
Packit Service 96b5d3
        else
Packit Service 96b5d3
            bnm = dep_target;
Packit Service 96b5d3
Packit Service 96b5d3
        {
Packit Service 96b5d3
            size_t pnm_sz = strlen(pnm);
Packit Service 96b5d3
            size_t bnm_sz = strlen(bnm);
Packit Service 96b5d3
Packit Service 96b5d3
            pz_targ_base = pz = AGALOC(pnm_sz + bnm_sz + 2, "t list");
Packit Service 96b5d3
            memcpy(pz, pnm, pnm_sz);
Packit Service 96b5d3
            pz += pnm_sz;
Packit Service 96b5d3
            *(pz++) = '_';
Packit Service 96b5d3
            memcpy(pz, bnm, bnm_sz + 1);
Packit Service 96b5d3
        }
Packit Service 96b5d3
Packit Service 96b5d3
        /*
Packit Service 96b5d3
         * Now scan over the characters in "pz_targ_base".  Anything that
Packit Service 96b5d3
         * is not a legal name character gets replaced with an underscore.
Packit Service 96b5d3
         */
Packit Service 96b5d3
        for (;;) {
Packit Service 96b5d3
            unsigned int ch = (unsigned int)*(pz++);
Packit Service 96b5d3
            if (ch == NUL)
Packit Service 96b5d3
                break;
Packit Service 96b5d3
            if (! IS_ALPHANUMERIC_CHAR(ch))
Packit Service 96b5d3
                pz[-1] = '_';
Packit Service 96b5d3
        }
Packit Service 96b5d3
    }
Packit Service 96b5d3
}
Packit Service 96b5d3
Packit Service 96b5d3
/**
Packit Service 96b5d3
 *  Set modification time and rename into result file name.
Packit Service 96b5d3
 */
Packit Service 96b5d3
static void
Packit Service 96b5d3
tidy_dep_file(void)
Packit Service 96b5d3
{
Packit Service 96b5d3
    static mode_t const fil_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
Packit Service 96b5d3
Packit Service 96b5d3
    /*
Packit Service 96b5d3
     * Trim off the temporary suffix and rename the dependency file into
Packit Service 96b5d3
     * place.  We used a mkstemp name in case autogen failed.
Packit Service 96b5d3
     */
Packit Service 96b5d3
    do  {
Packit Service 96b5d3
        char * pze = strrchr(dep_file, '-');
Packit Service 96b5d3
        char * pzn;
Packit Service 96b5d3
        size_t len;
Packit Service 96b5d3
Packit Service 96b5d3
        if (pze == NULL) break;
Packit Service 96b5d3
Packit Service 96b5d3
        len = (size_t)(pze - dep_file);
Packit Service 96b5d3
        pzn = AGALOC(len + 1, "dep file");
Packit Service 96b5d3
        memcpy(pzn, dep_file, len);
Packit Service 96b5d3
        pzn[len] = NUL;
Packit Service 96b5d3
Packit Service 96b5d3
        unlink(pzn);
Packit Service 96b5d3
        rename(dep_file, pzn);
Packit Service 96b5d3
        AGFREE(dep_file);
Packit Service 96b5d3
        dep_file = pzn;
Packit Service 96b5d3
    } while (false);
Packit Service 96b5d3
Packit Service 96b5d3
#ifdef HAVE_FCHMOD
Packit Service 96b5d3
    fchmod(fileno(dep_fp), fil_mode);
Packit Service 96b5d3
    fclose(dep_fp);
Packit Service 96b5d3
#else
Packit Service 96b5d3
    fclose(dep_fp);
Packit Service 96b5d3
    chmod(dep_file, fil_mode);
Packit Service 96b5d3
#endif
Packit Service 96b5d3
    dep_fp = NULL;
Packit Service 96b5d3
Packit Service 96b5d3
    {
Packit Service 96b5d3
        struct utimbuf tbuf = {
Packit Service 96b5d3
            .actime  = time(NULL),
Packit Service 96b5d3
            .modtime = start_time
Packit Service 96b5d3
        };
Packit Service 96b5d3
Packit Service 96b5d3
        utime(dep_file, &tbuf);
Packit Service 96b5d3
Packit Service 96b5d3
        /*
Packit Service 96b5d3
         * If the target is not the dependency file, then ensure that the
Packit Service 96b5d3
         * file exists and set its time to the same time.  Ignore all errors.
Packit Service 96b5d3
         */
Packit Service 96b5d3
        if (strcmp(dep_file, dep_target) != 0) {
Packit Service 96b5d3
            if (access(dep_target, R_OK) != 0)
Packit Service 96b5d3
                close( open(dep_target, O_CREAT, fil_mode));
Packit Service 96b5d3
Packit Service 96b5d3
            utime(dep_target, &tbuf);
Packit Service 96b5d3
            AGFREE(dep_target);
Packit Service 96b5d3
        }
Packit Service 96b5d3
    }
Packit Service 96b5d3
Packit Service 96b5d3
    AGFREE(dep_file);
Packit Service 96b5d3
}
Packit Service 96b5d3
Packit Service 96b5d3
/**
Packit Service 96b5d3
 *  Print out and free a list of files.
Packit Service 96b5d3
 */
Packit Service 96b5d3
static void
Packit Service 96b5d3
print_list(flist_t * flist, char const * TMPDIR, size_t tmpdir_len)
Packit Service 96b5d3
{
Packit Service 96b5d3
    /*
Packit Service 96b5d3
     *  Omit temporary sources.  They are identified several ways:
Packit Service 96b5d3
     *  1. the file must be accessible
Packit Service 96b5d3
     *  2. the file must not match our temporary file template
Packit Service 96b5d3
     *  3. the file must not match TMPDIR from the environment
Packit Service 96b5d3
     */
Packit Service 96b5d3
    while (flist != NULL) {
Packit Service 96b5d3
        flist_t * p = flist;
Packit Service 96b5d3
Packit Service 96b5d3
        do  {
Packit Service 96b5d3
            if (access(p->fname, R_OK) != 0)
Packit Service 96b5d3
                break; // no longer accessible
Packit Service 96b5d3
Packit Service 96b5d3
            if (  (temp_tpl_dir_len > 0)
Packit Service 96b5d3
               && (strncmp(pz_temp_tpl, p->fname, temp_tpl_dir_len) == 0)
Packit Service 96b5d3
               && (p->fname[temp_tpl_dir_len] == DIRCH))
Packit Service 96b5d3
                break; // autogen temp file
Packit Service 96b5d3
Packit Service 96b5d3
            if (  (strncmp(TMPDIR, p->fname, tmpdir_len) == 0)
Packit Service 96b5d3
               && (p->fname[tmpdir_len] == DIRCH) )
Packit Service 96b5d3
                break; // TMPDIR directory file
Packit Service 96b5d3
Packit Service 96b5d3
            fprintf(dep_fp, DEP_List, p->fname);
Packit Service 96b5d3
        } while (false);
Packit Service 96b5d3
Packit Service 96b5d3
        flist = p->next;
Packit Service 96b5d3
        AGFREE(p);
Packit Service 96b5d3
    }
Packit Service 96b5d3
}
Packit Service 96b5d3
Packit Service 96b5d3
/**
Packit Service 96b5d3
 *  Finish off the dependency file.  Write out the lists of files,
Packit Service 96b5d3
 *  a rule to fulfill make's needs and, optionally, clean up rules.
Packit Service 96b5d3
 *  then close the file and tidy up.
Packit Service 96b5d3
 */
Packit Service 96b5d3
LOCAL void
Packit Service 96b5d3
wrap_up_depends(void)
Packit Service 96b5d3
{
Packit Service 96b5d3
    char const * TMPDIR = getenv("TMPDIR");
Packit Service 96b5d3
    size_t       tmpdir_len;
Packit Service 96b5d3
    if (TMPDIR != NULL) {
Packit Service 96b5d3
        tmpdir_len = strlen(TMPDIR);
Packit Service 96b5d3
    } else {
Packit Service 96b5d3
        TMPDIR = "/tmp";
Packit Service 96b5d3
        tmpdir_len = 4;
Packit Service 96b5d3
    }
Packit Service 96b5d3
Packit Service 96b5d3
    fprintf(dep_fp, DEP_TList, pz_targ_base);
Packit Service 96b5d3
    print_list(targ_flist, TMPDIR, tmpdir_len);
Packit Service 96b5d3
Packit Service 96b5d3
    fprintf(dep_fp, DEP_SList, pz_targ_base);
Packit Service 96b5d3
    print_list(src_flist, TMPDIR, tmpdir_len);
Packit Service 96b5d3
Packit Service 96b5d3
    targ_flist = src_flist = NULL;
Packit Service 96b5d3
    fprintf(dep_fp, DEP_FILE_WRAP_FMT, pz_targ_base, dep_target);
Packit Service 96b5d3
Packit Service 96b5d3
    if (dep_phonies) {
Packit Service 96b5d3
        /*
Packit Service 96b5d3
         *  Remove the target file name IFF it is different from
Packit Service 96b5d3
         *  the dependency file name.  The dependency file will not be
Packit Service 96b5d3
         *  removed, but it will be sent waaay back in time.
Packit Service 96b5d3
         */
Packit Service 96b5d3
        char * p, *q;
Packit Service 96b5d3
        AGDUPSTR(p, dep_file, "xx");
Packit Service 96b5d3
Packit Service 96b5d3
        q = p + strlen(p) - (TEMP_SUFFIX_LEN - 2);
Packit Service 96b5d3
        if ((q > p) && (*q == '-'))
Packit Service 96b5d3
            *q = NUL;
Packit Service 96b5d3
        q = p;
Packit Service 96b5d3
Packit Service 96b5d3
        /* DO NOT REMOVE DEPENDENCY FILE */
Packit Service 96b5d3
        if (strcmp(dep_target, p) == 0)
Packit Service 96b5d3
            p = (char *)zNil;
Packit Service 96b5d3
        fprintf(dep_fp, DEP_FILE_CLEAN_FMT, dep_target, pz_targ_base, p);
Packit Service 96b5d3
        AGFREE(q);
Packit Service 96b5d3
    }
Packit Service 96b5d3
Packit Service 96b5d3
#if 0
Packit Service 96b5d3
    if (serv_id != NULLPROCESS) {
Packit Service 96b5d3
        char * pz = shell_cmd("echo ${AG_Dep_File}");
Packit Service 96b5d3
        if (*pz != NUL) {
Packit Service 96b5d3
            /*
Packit Service 96b5d3
             * The target we are crating will now depend upon the target
Packit Service 96b5d3
             * created by the spawned autogen run.  That spawned run script
Packit Service 96b5d3
             * is responsible for ensuring that if there are multiple targets,
Packit Service 96b5d3
             * then they are all chained together so we only worry about one.
Packit Service 96b5d3
             */
Packit Service 96b5d3
            static char const incfmt[] =
Packit Service 96b5d3
                "\n%s : %s\ninclude %s\n";
Packit Service 96b5d3
            static char const targ[] = ".targ";
Packit Service 96b5d3
            size_t ln = strlen(pz);
Packit Service 96b5d3
            char * pt = AGALOC(ln + sizeof(targ), targ);
Packit Service 96b5d3
            if (strcmp(pz + ln - 4, ".dep") == 0)
Packit Service 96b5d3
                ln -= 4;
Packit Service 96b5d3
            memcpy(pt, pz, ln);
Packit Service 96b5d3
            memcpy(pt + ln, targ, sizeof(targ));
Packit Service 96b5d3
            fprintf(dep_fp, incfmt, dep_target, pt, pz);
Packit Service 96b5d3
            AGFREE(pt);
Packit Service 96b5d3
        }
Packit Service 96b5d3
Packit Service 96b5d3
        AGFREE(pz);
Packit Service 96b5d3
    }
Packit Service 96b5d3
#endif
Packit Service 96b5d3
    tidy_dep_file();
Packit Service 96b5d3
}
Packit Service 96b5d3
Packit Service 96b5d3
/**
Packit Service 96b5d3
 * @}
Packit Service 96b5d3
 *
Packit Service 96b5d3
 * Local Variables:
Packit Service 96b5d3
 * mode: C
Packit Service 96b5d3
 * c-file-style: "stroustrup"
Packit Service 96b5d3
 * indent-tabs-mode: nil
Packit Service 96b5d3
 * End:
Packit Service 96b5d3
 * end of agen5/agDep.c */