This is the mail archive of the cygwin-apps mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gcc-3 -mno-cygwin with sysroot mingw runtime [Was: Re: cygport cross-compiling beta1]

On 7/20/2010 8:46 PM, Yaakov (Cygwin/X) wrote:
> On Tue, 2010-07-20 at 10:51 -0400, Charles Wilson wrote:
>> Well, I guess the replacement package for the gcc(3)-mingw stuff can 
>> just create symlinks:
>>     /usr/lib/mingw     -> /usr/i686-pc-mingw32/sys-root/mingw/lib
>>     /usr/include/mingw -> /usr/i686-pc-mingw32/sys-root/mingw/include
>> (or, rather, gcc-mingw-* could simply be obsoleted -- and the 
>> replacement version having a postinstall script that does what the 
>> gcc-mingw-* preremove scripts SHOULD have done, which is to remove the 
>> /usr/i686-pc-mingw32/{bin,include/lib} symlinks, and a new repackaged 
>> version of gcc(3)-core could generate the /usr/{lib,include}/mingw 
>> symlinks itself.
> If gcc-mingw* go away then you don't need /usr/{include,lib}/mingw,
> because -mno-cygwin will no longer work, right?
> Either way, changing /usr/{include,lib}/mingw from directories into
> symlinks is not so simple, as the current mingw-* packages all install
> into there.
>> However, depending on how the system includes are ordered, gcc3 
>> -mno-cygwin will then either use the "cygwin" w32api in 
>> /usr/include/w32api, or the cross versions mixed in to 
>> /usr/i686-pc-mingw32/sys-root/mingw/include.
> How would gcc3 know about the mingw sysroot?

So, here's how I got a working 'gcc-3 -mno-cygwin' and 'g++-3
-mno-cygwin' with the new sysroot-style mingw-runtime and mingw-w32api.

::: technically, steps #1--#3 below have to be done before you try
::: to install, build, or use the new i686-mingw cross toolchain, but
::: I list them here for completeness.

1) Upgraded the old mingw-runtime-3.18-1 (in /usr/{lib,include}/mingw to
the new cross-compiled mingw-runtime-3.18-2 (in

2) Uninstalled
   and basically any other gcc-mingw-* you might have installed.
setup.exe will whine about this, because these packages are listed as
requirements of the corresponding gcc-X-3.4.4-999 package(s).  However,
as far as I can tell, the regular cygwin personality of those compilers
works just fine, even without the gcc-mingw-* packages, so long as you
don't try to use -mno-cygwin.

3) Fixup some stuff that the gcc-mingw-* preremove scripts should have done:

    rm -f /usr/i686-pc-mingw32/{lib,include,bin}

4) Upgraded ALL of the following:

                               /usr/*/mingw      $sysroot$prefix
mingw-zlib                      1.2.3-10         -> 1.2.5-2
mingw-zlib-devel                1.2.3-10         -> 1.2.5-2
mingw-zlib0                     1.2.3-10         -> 1.2.5-2

mingw-bzip2                     1.0.5-10         -> 1.0.5-12
mingw-libbz2-devel              1.0.5-10         -> 1.0.5-12
mingw-libbz2_1                  1.0.5-10         -> 1.0.5-12

mingw-liblzma-devel             4.999.9beta-11   -> 4.999.9beta-13
mingw-liblzma1                  4.999.9beta-11   -> 4.999.9beta-13
mingw-xz                        4.999.9beta-11   -> 4.999.9beta-13

mingw-libgpg-error              1.7-1            -> 1.8-2
mingw-libgpg-error-devel        1.7-1            -> 1.8-2
mingw-libgpg-error0             1.7-1            -> 1.8-2

mingw-libgcrypt                 1.4.5-1          -> 1.4.5-3
mingw-libgcrypt-devel           1.4.5-1          -> 1.4.5-3
mingw-libgcrypt11               1.4.5-1          -> 1.4.5-3

At that point, /usr/include/mingw and /usr/lib/mingw were both empty.

5) rm -f /usr/lib/mingw /usr/include/mingw

6) Now, manually download gcc-mingw-core and gcc-mingw-g++ (Yes, I know,
we just uninstalled them, but run with me here).  I didn't test any of
the other languages, and they may or may not work; I dunno.  But I was
able to get C and C++ working, so I figure that's sufficient for now.


These packages are constructed in a very odd way; I've never really
understood why.  But, the contents of each tarball look like this:



We're interested in the inner tarballs, so unpack the outer ones
someplace safe, like /tmp.

7) The inner tarballs have contents like this:



That is, *everything* is entirely under lib/gcc/i686-pc-mingw32/3.4.4.
That won't conflict with anything, so it's safe to unpack.

cd to /usr, and
	tar xzf gcc-mingw-core-3.4.4-20050522-1.tgz
	tar xzf gcc-mingw-g++-3.4.4-20050522-1.tgz

8) Almost done.  Next, we need to ensure that the various startup
objects are "findable" by gcc-3 -mno-cygwin.  We'll copy them from the
the mingw sys-root:

	cd /usr/i686-pc-mingw32/s
	cp sys-root/mingw/lib/*.o lib/

I'm a little nervous about this step, but see the note at the end.

9) Last, but not least, we have to modify the -mno-cygwin specs file.
It's located here:

but right now it's a symlink to the cygwin version (this symlink was
part of gcc-mingw-core-3.4.4-20050522-1.tgz).  So,

	cd /usr/lib/gcc/i686-pc-mingw32/3.4.4/
	rm -f specs
	cp /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs .

There are three things we have to fix: the C pre-processor's include
path, the C++ pre-processor's include path, and the linker's search path.

a) Look for:

%(cpp_cpu) ....

and add '-I /usr/i686-pc-mingw32/sys-root/mingw/include' at the end of
the %(cpp_cpu) line -- without the quotation marks.

b) Look for:


and add an entry '-I /usr/i686-pc-mingw32/sys-root/mingw/include'
directly below it (without the quotation marks).

c) Look for:


and add '-L /usr/i686-pc-mingw32/sys-root/mingw/lib' after %D on the
same line (with a space between, and without the quotation marks).

OR, apply the attached patch.

The downside to this approach, is that -nostdinc will no longer work
properly, nor will -nostdlib. can easily emulate that by
preserving a copy of the OLD specs file (call it "orig.specs"), and then
just use "-specs orig.specs" along with -nostd*.

And there you have it: a kinda crippled, but mostly functional gcc-3
-mno-cygwin that uses the new cross-compiler's sysroot instead of
/usr/{lib,include}/mingw.  It will also find all of your other
cross-compiled stuff including the cross-w32api, but as that the
$sysroot dirs are the last of the system includes in our modified specs
file, the "cygwin" /usr/{include,lib}/w32api will be preferred.

Now, in this arrangement, the is NO /usr/{include,lib}/mingw directory.
 That's because the only reason the original gcc-3 -mno-cygwin ever
actually LOOKED in /usr/{include,lib}/mingw was that there were symlinks
over in /usr/i686-pc-mingw32/*, which is where it was REALLY looking,
that pointed over to /usr/*/mingw.

NOTE: I'm concerned that the actual cross-compiler might look in
/usr/i686-pc-mingw32/{lib,include} for stuff, so it's probably a good
idea to make sure that whatever is there, is kept strictly in sync with
the stuff in /usr/i686-pc-mingw32/sys-root/mingw/{lib,include} from
which it was copied.

Now, with all these changes, and ONLY the attached setup-gcc3.patch
applied to the setup source directory (that is, without Yaakov's
setup-gcc45.patch or setup-no-autoload.patch, and certainly not my
chucks-doconfigure-updates.patch), I was able to build a working setup.exe.

Note that this setup.exe was linked against static libs compiled using
the gcc-4.5 cross compiler, but that appears to be ok.  I did have to
play games with $PATH to convince setup's configure to locate the
correct foo-config scripts.

setup-gcc3.patch mostly just adds the sysroot include and lib to
CPPFLAGS and LDFLAGS.  It really shouldn't have to, since we added it to
the specs file; I think I had to do that to ensure that the sysroot dirs
came before "/mingw/lib", but I don't recall.

So, finally: I think we can see a relatively straightforward approach to
a "fixed" gcc-mingw-* set of packages, at least for C and C++.
Basically: take the "inner" tarball of the current ones, relocate from
"/lib/*" to "/usr/lib/*" (I know, but everything ELSE that setup unpacks
is specified with the /usr prefix!), copy in the modified specs file in
place of the current symlink, and repackage as
Oh, and remove the requires: gcc-mingw-* from the top-level gcc
setup.hint, and from all the other gcc-ish setup.hints.

That part's relatively straightforward. The tricky bit is arranging so
that the current symlinks in /usr/i686-pc-mingw32/{lib,bin,include} get
removed properly, before any of the new cross tools are ever installed.

Oh, and I'm not sure how we should handle the copies of the startup
objs.  Should the sysrootized mingw-runtime itself just be packaged with
two copies of those .o's, so that a copy ends up in both
   /usr/i686-pc-mingw32/lib                 and
   /usr/i686-pc-mingw32/sys-root/mingw/lib   ?

--- i686-pc-cygwin/3.4.4/specs	2009-02-25 05:07:59.001000000 -0500
+++ i686-pc-mingw32/3.4.4/specs	2010-07-22 02:37:21.459924400 -0400
@@ -15,7 +15,7 @@
  as %(asm_options) %m.s %A }
-%(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}}
+%(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}} -I /usr/i686-pc-mingw32/sys-root/mingw/include
 %(cpp_unique_options) %1 %{m*} %{std*&ansi&trigraphs} %{W*&pedantic*} %{w} %{f*} %{g*:%{!g0:%{!fno-working-directory:-fworking-directory}}} %{O*} %{undef}
@@ -36,7 +36,7 @@
 %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}} %1 %{!Q:-quiet} -dumpbase %B %{d*} %{m*} %{a*} %{c|S:%{o*:-auxbase-strip %*}%{!o*:-auxbase %b}}%{!c:%{!S:-auxbase %b}} %{g*} %{O*} %{W*&pedantic*} %{w} %{std*&ansi&trigraphs} %{v:-version} %{pg:-p} %{p} %{f*} %{undef} %{Qn:-fno-ident} %{--help:--help} %{--target-help:--target-help} %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %b.s}}} %{fsyntax-only:-o %j} %{-param*}
+-I /usr/i686-pc-mingw32/sys-root/mingw/include
 %G %L %G
@@ -87,7 +87,7 @@
+%D -L /usr/i686-pc-mingw32/sys-root/mingw/lib
? .Tpo
Index: doconfigure
RCS file: /cvs/cygwin-apps/setup/doconfigure,v
retrieving revision 2.2
diff -u -p -r2.2 doconfigure
--- doconfigure	30 Mar 2010 23:55:15 -0000	2.2
+++ doconfigure	22 Jul 2010 07:19:12 -0000
@@ -14,7 +14,9 @@ fi
 # used.  Otherwise: assume cross-compiler users are
 # sophisticated enough to do this manually.
 case `uname -s` in
-*CYGWIN* ) export PATH="/usr/lib/mingw:${PATH}" ;;
+*CYGWIN* ) export PATH="/usr/i686-pc-mingw32/sys-root/mingw/bin:${PATH}"
+           cppflags=-I/usr/i686-pc-mingw32/sys-root/mingw/include
+	   ldflags=-L/usr/i686-pc-mingw32/sys-root/mingw/lib ;;
 # Configure
@@ -25,11 +27,14 @@ cmd=$cmd' CC="gcc-3 -mno-cygwin" CXX="g+
 for i in "$@"; do
   case $i in
-    maint) cmd=$cmd' CPPFLAGS=-DMAINTAINER_FEATURES' ;;
+    maint) cppflags=${cppflags}' -DMAINTAINER_FEATURES' ;;
     debug) cmd=$cmd' CFLAGS="-g -O0" CXXFLAGS="-g -O0"' ;;
     *) echo "Unexpected argument: '$i'" >&2; exit 1 ;;
+cmd=$cmd' LDFLAGS="${ldflags}"'
+cmd=$cmd' CPPFLAGS="${cppflags}"'
 echo -e "\033[32;1mRunning $DIR/configure\033[0m"
 eval "$cmd"

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]