Bug 26052 - cygwin's defnes does not honor the -undef option and -std=c89 is not the same as -ansi
Summary: cygwin's defnes does not honor the -undef option and -std=c89 is not the same...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.4.4
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: 545
  Show dependency treegraph
 
Reported: 2006-01-31 22:09 UTC by Peter Rosin
Modified: 2019-09-26 04:41 UTC (History)
3 users (show)

See Also:
Host:
Target: i686-pc-cygwin
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-01-31 22:15:09


Attachments
Fixup -undef option in specs file. (484 bytes, patch)
2006-01-31 22:11 UTC, Peter Rosin
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Rosin 2006-01-31 22:09:13 UTC
I recently tried to build a package that was using cpp for other purposes than preprocessing C files. Its configure script was looking for a way to not have cpp predefine anything, and it specifically tried the -undef option, but failed. From reading the docs, I couldn't figure out why. Here's a quote from "info cpp":

'-undef'
     Do not predefine any system-specific or GCC-specific macros.  The
     standard predefined macros remain defined.  *Note Standard
     Predefined Macros::.

So I searched the web a bit and figured that I could probably fix it in the specs file. I realise that the specs file probably isn't the canonical place to change this.

I'll attach a patch for the specs file that wraps all old define rules for cpp inside the following:

%{!undef:old define rules}

I don't know if this is the correct thing to do, but it works for me<TM>.

"cpp -undef -mD < /dev/null" gives me this list:

#define __unix 1
#define __STDC_HOSTED__ 1
#define __unix__ 1
#define unix 1
#define __CYGWIN__ 1
#define __CYGWIN32__ 1

All but __STDC_HOSTED__ are system/gcc-specific according to "*Note Standard Predefined Macros".

In my specific case, the configure script is looking for a way to not have "unix" defined.

FWIW, the provided patch fixes all of the above, so that the output from the above command is:

#define __STDC_HOSTED__ 1

Cheers,
Peter
Comment 1 Peter Rosin 2006-01-31 22:11:00 UTC
Created attachment 10768 [details]
Fixup -undef option in specs file.
Comment 2 Andrew Pinski 2006-01-31 22:13:07 UTC
This is a target specific issue.
Comment 3 Andrew Pinski 2006-01-31 22:15:09 UTC
The bug is in the SPECs but it is generated from
gcc/config/i386/cygwin.h:
#define CPP_SPEC "%(cpp_cpu) %{posix:-D_POSIX_SOURCE} \
  %{mno-win32:%{mno-cygwin: %emno-cygwin and mno-win32 are not compatible}} \
  %{mno-cygwin:-D__MSVCRT__ -D__MINGW32__ %{!ansi:%{mthreads:-D_MT}}}\
  %{!mno-cygwin:-D__CYGWIN32__ -D__CYGWIN__ %{!ansi:-Dunix} -D__unix__ -D__unix }\
  %{mwin32|mno-cygwin:-DWIN32 -D_WIN32 -D__WIN32 -D__WIN32__ %{!ansi:-DWINNT}}\
  %{!nostdinc:%{!mno-win32|mno-cygwin:-idirafter ../include/w32api%s -idirafter ../../include/w32api%s}}\
"


Really there should be a better way of doing this instead of using a SPECs.
Comment 4 Gerrit P. Haase 2006-02-02 16:09:50 UTC
IMO it should be coded in the executable itself that -undef skips reading the specs at all.
Comment 5 Andrew Pinski 2006-02-02 16:39:15 UTC
(In reply to comment #4)
> IMO it should be coded in the executable itself that -undef skips reading the
> specs at all.

No, that would not work as this SPECs is used for other things too.
The correct way to fix this is to move the specs handling of defines to TARGET_OS_CPP_BUILTINS.
That will also fix the problems referenced in PR 545.
Comment 6 Andrew Pinski 2006-02-02 16:42:10 UTC
(In reply to comment #5)
> (In reply to comment #4)
> No, that would not work as this SPECs is used for other things too.
> The correct way to fix this is to move the specs handling of defines to
> TARGET_OS_CPP_BUILTINS.

For cygwin.h, the correct macro is EXTRA_OS_CPP_BUILTINS as TARGET_OS_CPP_BUILTINS is used in cygming.h already and just calls EXTRA_OS_CPP_BUILTINS for the cygwin specific defines.