summaryrefslogtreecommitdiff
path: root/gcc/config/avr/driver-avr.c
blob: b0079544a2256efed16d7fadcd10f5340cbecf24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/* Subroutines for the gcc driver.
   Copyright (C) 2009-2019 Free Software Foundation, Inc.
   Contributed by Georg-Johann Lay <avr@gjlay.de>

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.

GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.  */

#define IN_TARGET_CODE 1

#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "diagnostic.h"
#include "tm.h"

// Remove -nodevicelib from the command line if not needed
#define X_NODEVLIB "%<nodevicelib"

static const char dir_separator_str[] = { DIR_SEPARATOR, 0 };


/* Implement spec function `device-specs-fileĀ“.

   Validate mcu name given with -mmcu option. Compose
   -specs=<specs-file-name>%s. If everything went well then argv[0] is the
   inflated (absolute) first device-specs directory and argv[1] is a device
   or core name as supplied by -mmcu=*. When building GCC the path might be
   relative.  */

const char*
avr_devicespecs_file (int argc, const char **argv)
{
  const char *mmcu = NULL;

#ifdef DEBUG_SPECS
  if (verbose_flag)
    fnotice (stderr, "Running spec function '%s' with %d args\n\n",
             __FUNCTION__, argc);
#endif

  switch (argc)
    {
    case 0:
      fatal_error (input_location,
                   "bad usage of spec function %qs", "device-specs-file");
      return X_NODEVLIB;

    case 1:
      if (strcmp ("device-specs", argv[0]) == 0)
        {
          /* FIXME:  This means "device-specs%s" from avr.h:DRIVER_SELF_SPECS
             has not been resolved to a path.  That case can occur when the
             c++ testsuite is run from the build directory.  DejaGNU's
             libgloss.exp:get_multilibs runs $compiler without -B, i.e.runs
             xgcc without specifying a prefix.  Without any prefix, there is
             no means to find out where the specs files might be located.
             get_multilibs runs xgcc --print-multi-lib, hence we don't actually
             need information form a specs file and may skip it here.  */
          return X_NODEVLIB;
        }

      mmcu = AVR_MMCU_DEFAULT;
      break;

    default:
      mmcu = argv[1];

      // Allow specifying the same MCU more than once.

      for (int i = 2; i < argc; i++)
	if (strcmp (mmcu, argv[i]) != 0)
          {
            error ("specified option %qs more than once", "-mmcu");
            return X_NODEVLIB;
          }

      break;
    }

  // Filter out silly -mmcu= arguments like "foo bar".

  for (const char *s = mmcu; *s; s++)
    if (!ISALNUM (*s)
        && '-' != *s
        && '_' != *s)
      {
        error ("strange device name %qs after %qs: bad character %qc",
               mmcu, "-mmcu=", *s);
        return X_NODEVLIB;
      }

  return concat ("-specs=device-specs", dir_separator_str, "specs-",
                 mmcu, "%s"
#if defined (WITH_AVRLIBC)
                 " %{mmcu=avr*:" X_NODEVLIB "} %{!mmcu=*:" X_NODEVLIB "}",
#else
                 " " X_NODEVLIB,
#endif
                 NULL);
}


/* Re-build the -mdouble= and -mlong-double= options.  This is needed
   because these options are not independent of each other.  */

const char*
avr_double_lib (int argc, const char **argv)
{
#if defined (WITH_DOUBLE64)
  int dbl = 64;
#elif defined (WITH_DOUBLE32)
  int dbl = 32;
#else
#error "align this with config.gcc"
#endif

#if defined (WITH_LONG_DOUBLE64)
  int ldb = 64;
#elif defined (WITH_LONG_DOUBLE32)
  int ldb = 32;
#else
#error "align this with config.gcc"
#endif

  for (int i = 0; i < argc; i++)
    {
      if (strcmp (argv[i], "mdouble=32") == 0)
        {
          dbl = 32;
#ifdef HAVE_LONG_DOUBLE_IS_DOUBLE
          ldb = dbl;
#endif
        }
      else if (strcmp (argv[i], "mdouble=64") == 0)
        {
          ldb = dbl = 64;
        }
      else if (strcmp (argv[i], "mlong-double=32") == 0)
        {
          ldb = dbl = 32;
        }
      else if (strcmp (argv[i], "mlong-double=64") == 0)
        {
          ldb = 64;
#ifdef HAVE_LONG_DOUBLE_IS_DOUBLE
          dbl = ldb;
#endif
        }
    }

  return concat (" %<mdouble=* -mdouble=", dbl == 32 ? "32" : "64",
                 " %<mlong-double=* -mlong-double=", ldb == 32 ? "32" : "64",
                 NULL);
}