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
Created attachment 10768 [details] Fixup -undef option in specs file.
This is a target specific issue.
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.
IMO it should be coded in the executable itself that -undef skips reading the specs at all.
(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.
(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.