2016-08-17 Thomas Preud'homme <thomas.preudhomme@arm.com>
[official-gcc.git] / gcc / config / avr / driver-avr.c
blob8a8fd50449f5fbf4e508d0f94339774bbf9ec038
1 /* Subroutines for the gcc driver.
2 Copyright (C) 2009-2016 Free Software Foundation, Inc.
3 Contributed by Georg-Johann Lay <avr@gjlay.de>
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)
10 any later version.
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/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "diagnostic.h"
25 #include "tm.h"
27 // Remove -nodevicelib from the command line if not needed
28 #define X_NODEVLIB "%<nodevicelib"
30 static const char dir_separator_str[] = { DIR_SEPARATOR, 0 };
33 /* Implement spec function `device-specs-fileĀ“.
35 Validate mcu name given with -mmcu option. Compose
36 -specs=<specs-file-name>%s. If everything went well then argv[0] is the
37 inflated (absolute) first device-specs directory and argv[1] is a device
38 or core name as supplied by -mmcu=*. When building GCC the path might be
39 relative. */
41 const char*
42 avr_devicespecs_file (int argc, const char **argv)
44 const char *mmcu = NULL;
46 #ifdef DEBUG_SPECS
47 if (verbose_flag)
48 fnotice (stderr, "Running spec function '%s' with %d args\n\n",
49 __FUNCTION__, argc);
50 #endif
52 switch (argc)
54 case 0:
55 fatal_error (input_location,
56 "bad usage of spec function %qs", "device-specs-file");
57 return X_NODEVLIB;
59 case 1:
60 if (0 == strcmp ("device-specs", argv[0]))
62 /* FIXME: This means "device-specs%s" from avr.h:DRIVER_SELF_SPECS
63 has not been resolved to a path. That case can occur when the
64 c++ testsuite is run from the build directory. DejaGNU's
65 libgloss.exp:get_multilibs runs $compiler without -B, i.e.runs
66 xgcc without specifying a prefix. Without any prefix, there is
67 no means to find out where the specs files might be located.
68 get_multilibs runs xgcc --print-multi-lib, hence we don't actually
69 need information form a specs file and may skip it here. */
70 return X_NODEVLIB;
73 mmcu = AVR_MMCU_DEFAULT;
74 break;
76 default:
77 mmcu = argv[1];
79 // Allow specifying the same MCU more than once.
81 for (int i = 2; i < argc; i++)
82 if (0 != strcmp (mmcu, argv[i]))
84 error ("specified option %qs more than once", "-mmcu");
85 return X_NODEVLIB;
88 break;
91 // Filter out silly -mmcu= arguments like "foo bar".
93 for (const char *s = mmcu; *s; s++)
94 if (!ISALNUM (*s)
95 && '-' != *s
96 && '_' != *s)
98 error ("strange device name %qs after %qs: bad character %qc",
99 mmcu, "-mmcu=", *s);
100 return X_NODEVLIB;
103 return concat ("-specs=device-specs", dir_separator_str, "specs-",
104 mmcu, "%s"
105 #if defined (WITH_AVRLIBC)
106 " %{mmcu=avr*:" X_NODEVLIB "} %{!mmcu=*:" X_NODEVLIB "}",
107 #else
108 " " X_NODEVLIB,
109 #endif
110 NULL);