1204431Sraj/* Helper routines for cygwin-specific command-line parsing.
2204431Sraj   Contributed by Christopher Faylor (cgf@redhat.com)
3204431Sraj   Copyright 2003 Free Software Foundation, Inc.
4204431Sraj
5204431SrajThis file is part of GCC.
6204431Sraj
7204431SrajGCC is free software; you can redistribute it and/or modify
8204431Srajit under the terms of the GNU General Public License as published by
9204431Srajthe Free Software Foundation; either version 2, or (at your option)
10204431Srajany later version.
11204431Sraj
12266130SianGCC is distributed in the hope that it will be useful,
13204431Srajbut WITHOUT ANY WARRANTY; without even the implied warranty of
14204431SrajMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15204431SrajGNU General Public License for more details.
16204431Sraj
17204431SrajYou should have received a copy of the GNU General Public License
18238742Simpalong with GCC; see the file COPYING.  If not, write to
19238742Simpthe Free Software Foundation, 51 Franklin Street, Fifth Floor,
20238742SimpBoston, MA 02110-1301, USA.  */
21238742Simp
22204431Sraj#include "config.h"
23204431Sraj#include "system.h"
24204431Sraj#include "coretypes.h"
25204431Sraj#include "tm.h"
26204431Sraj
27204431Sraj#include "safe-ctype.h"
28204431Sraj#include <string.h>
29204431Sraj
30204431Sraj/*
31204431Srajstatic void remove_w32api (void);
32204431Sraj*/
33204433Srajstatic void add_mingw (void);
34204433Srajstatic void set_mingw (void) __attribute__ ((constructor));
35204433Sraj
36204433Srajstatic void
37204433Srajadd_mingw (void)
38204433Sraj{
39204433Sraj  char **av;
40204433Sraj  char *p;
41204433Sraj  for (av = cvt_to_mingw; *av; av++)
42204433Sraj    {
43204433Sraj      int sawcygwin = 0;
44204431Sraj      while ((p = strstr (*av, "-cygwin")))
45204431Sraj	{
46204431Sraj	  char *over = p + sizeof ("-cygwin") - 1;
47204431Sraj	  memmove (over + 1, over, strlen (over));
48204431Sraj	  memcpy (p, "-mingw32", sizeof("-mingw32") - 1);
49204431Sraj	  p = ++over;
50204431Sraj	  while (ISALNUM (*p))
51243933Seadler	    p++;
52204431Sraj	  strcpy (over, p);
53204431Sraj	  sawcygwin = 1;
54204431Sraj	}
55204431Sraj      if (!sawcygwin && !strstr (*av, "mingw"))
56204431Sraj	strcat (*av, CYGWIN_MINGW_SUBDIR);
57204431Sraj    }
58204431Sraj}
59204431Sraj
60204431Sraj
61204431Srajstatic void
62204431Srajset_mingw (void)
63204431Sraj{
64204431Sraj  char *env = getenv ("GCC_CYGWIN_MINGW");
65204431Sraj  if (env && *env == '1')
66204431Sraj    add_mingw ();
67204431Sraj}
68204431Sraj