1 /* Subroutines for the gcc driver.
2 Copyright (C) 2009 Free Software Foundation, Inc.
3 Contributed by Arthur Loiret <aloiret@debian.org>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
26 /* This will be called by the spec parser in gcc.c when it sees
27 a %:local_cpu_detect(args) construct. Currently it will be called
28 with either "cpu" or "tune" as argument depending on if -mcpu=native
29 or -mtune=native is to be substituted.
31 It returns a string containing new command line parameters to be
32 put at the place of the above two options, depending on what CPU
33 this is executed. E.g. "-mcpu=ev6" on an Alpha 21264 for
34 -mcpu=native. If the routine can't detect a known processor,
35 the -mcpu or -mtune option is discarded.
37 ARGC and ARGV are set depending on the actual arguments given
40 host_detect_local_cpu (int argc, const char **argv)
42 const char *cpu = NULL;
46 static const struct cpu_names {
47 const char *const name;
48 const char *const cpu;
66 /* { "EV3", "ev3" }, */
75 if (strcmp (argv[0], "cpu") && strcmp (argv[0], "tune"))
78 f = fopen ("/proc/cpuinfo", "r");
82 while (fgets (buf, sizeof (buf), f) != NULL)
83 if (strncmp (buf, "cpu model", sizeof ("cpu model") - 1) == 0)
85 for (i = 0; cpu_names [i].name; i++)
86 if (strstr (buf, cpu_names [i].name) != NULL)
88 cpu = cpu_names [i].cpu;
99 return concat ("-m", argv[0], "=", cpu, NULL);