• Skip to sidebar navigation
  • Skip to content

Bitbucket

  • More
    ProjectsRepositories
  • Help
    • Online help
    • Learn Git
    • Welcome to Bitbucket
    • Keyboard shortcuts
  • Log In
Alexander Dahl
  1. Alexander Dahl

buildroot

Public
Actions
  • Clone
  • Compare

Learn more about cloning repositories

You have read-only access

Navigation
  • Source
  • Commits
  • Branches
  • All Branches Graph
  • Forks
  1. Alexander Dahl
  2. buildroot

Source

buildroot/toolchain/toolchain-wrapper.c
Yann E. MORINYann E. MORIN committed 1c8c0d91a4320 Feb 2017
  • Unified diff
  • Side-by-side diff
  • Ignore whitespace
  • Show whitespace characters
  • Hide e-diff
  • Show annotations
Source viewDiff to previous
xxxxxxxxxx
 
 * kind, whether express or implied.
 */
​
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h>
​
#ifdef BR_CCACHE
static char ccache_path[PATH_MAX];
#endif
static char path[PATH_MAX];
static char sysroot[PATH_MAX];
static char source_time[sizeof("-D__TIME__=\"HH:MM:SS\"")];
static char source_date[sizeof("-D__DATE__=\"MMM DD YYYY\"")];
​
/**
 * GCC errors out with certain combinations of arguments (examples are
 * -mfloat-abi={hard|soft} and -m{little|big}-endian), so we have to ensure
 * that we only pass the predefined one to the real compiler if the inverse
 * option isn't in the argument list.
 * This specifies the worst case number of extra arguments we might pass
 * Currently, we have:
 *  -mfloat-abi=
 *  -march=
 *  -mcpu=
 *  -D__TIME__=
 *  -D__DATE__=
 *  -Wno-builtin-macro-redefined
 */
#define EXCLUSIVE_ARGS  6
#define EXCLUSIVE_ARGS  3
​
static char *predef_args[] = {
#ifdef BR_CCACHE
    ccache_path,
#endif
    path,
    "--sysroot", sysroot,
#ifdef BR_ABI
    "-mabi=" BR_ABI,
#endif
            program_invocation_short_name,
            paranoid ? "ERROR" : "WARNING",
            arg,
            arg_has_path ? "" : "' '", /* close single-quote, space, open single-quote */
            arg_has_path ? "" : path); /* so that arg and path are properly quoted. */
        if (paranoid)
            exit(1);
    }
}
​
/* Read SOURCE_DATE_EPOCH from environment to have a deterministic
 * timestamp to replace embedded current dates to get reproducible
 * results.  Returns -1 if SOURCE_DATE_EPOCH is not defined.
 */
static time_t get_source_date_epoch()
{
    char *source_date_epoch;
    long long epoch;
    char *endptr;
​
    source_date_epoch = getenv("SOURCE_DATE_EPOCH");
    if (!source_date_epoch)
        return (time_t) -1;
​
    errno = 0;
    epoch = strtoll(source_date_epoch, &endptr, 10);
    if ((errno == ERANGE && (epoch == LLONG_MAX || epoch == LLONG_MIN))
            || (errno != 0 && epoch == 0)) {
        fprintf(stderr, "environment variable $SOURCE_DATE_EPOCH: "
                "strtoll: %s\n", strerror(errno));
        exit(2);
    }
    if (endptr == source_date_epoch) {
        fprintf(stderr, "environment variable $SOURCE_DATE_EPOCH: "
                "no digits were found: %s\n", endptr);
        exit(2);
    }
    if (*endptr != '\0') {
        fprintf(stderr, "environment variable $SOURCE_DATE_EPOCH: "
                "trailing garbage: %s\n", endptr);
        exit(2);
    }
    if (epoch < 0) {
        fprintf(stderr, "environment variable $SOURCE_DATE_EPOCH: "
                "value must be nonnegative: %lld \n", epoch);
        exit(2);
    }
​
    return (time_t) epoch;
}
​
int main(int argc, char **argv)
{
    char **args, **cur, **exec_args;
    char *relbasedir, *absbasedir;
    char *progpath = argv[0];
    char *basename;
    char *env_debug;
    char *paranoid_wrapper;
    int paranoid;
    int ret, i, count = 0, debug;
    time_t source_date_epoch;
​
    /* Calculate the relative paths */
    basename = strrchr(progpath, '/');
    if (basename) {
        *basename = '\0';
        basename++;
        relbasedir = malloc(strlen(progpath) + 7);
        if (relbasedir == NULL) {
            perror(__FILE__ ": malloc");
            return 2;
    if (i == argc) {
#ifdef BR_ARCH
        *cur++ = "-march=" BR_ARCH;
#endif
#ifdef BR_CPU
        *cur++ = "-mcpu=" BR_CPU;
#endif
    }
#endif /* ARCH || CPU */
​
    source_date_epoch = get_source_date_epoch();
    if (source_date_epoch != -1) {
        struct tm *tm = localtime(&source_date_epoch);
        if (!tm) {
            perror("__FILE__: localtime");
            return 3;
        }
        ret = strftime(source_time, sizeof(source_time), "-D__TIME__=\"%T\"", tm);
        if (!ret) {
            perror("__FILE__: overflow");
            return 3;
        }
        *cur++ = source_time;
        ret = strftime(source_date, sizeof(source_date), "-D__DATE__=\"%b %e %Y\"", tm);
        if (!ret) {
            perror("__FILE__: overflow");
            return 3;
        }
        *cur++ = source_date;
        *cur++ = "-Wno-builtin-macro-redefined";
    }
​
    paranoid_wrapper = getenv("BR_COMPILER_PARANOID_UNSAFE_PATH");
    if (paranoid_wrapper && strlen(paranoid_wrapper) > 0)
        paranoid = 1;
    else
        paranoid = 0;
​
    /* Check for unsafe library and header paths */
    for (i = 1; i < argc; i++) {
        const struct str_len_s *opt;
        for (opt=unsafe_opts; opt->str; opt++ ) {
  • Git repository management for enterprise teams powered by Atlassian Bitbucket
  • Atlassian Bitbucket v6.7.2
  • Documentation
  • Request a feature
  • About
  • Contact Atlassian
Atlassian

Everything looks good. We'll let you know here if there's anything you should know about.