darcs

Issue 899 very difficult to build win32 darcs with ghc-6.8.2

Title very difficult to build win32 darcs with ghc-6.8.2
Priority feature Status duplicate
Milestone Resolved in
Superseder very difficult to build win32 darcs with ghc-6.8.2
View: 898
Nosy List darcs-devel, dmitry.kurochkin, kowey, newsham, newsham, thorkilnaur, tommy
Assigned To
Topics

Created on 2008-06-04.22:23:41 by newsham, last changed 2009-08-27.14:00:48 by admin.

Messages
msg4947 (view) Author: newsham Date: 2008-06-04.22:23:35
I built darcs for win32 recently and it was much more difficult than
it should be.  Probably most of the blame goes to ghc-6.8.2 binary
release for win32.  Half of the effort is getting the zlib prereq
working.

Previously to build zlib for win32 ghc I did the following:
http://www.haskell.org/pipermail/haskell-cafe/2007-March/023059.html

However, now, the gcc binary for ghc-6.8.2 does not work as well as
I would like which requires a bit more effort:

- It did not automatically add mingw headers during compilation, and
   to fix this I had to force some extra flags.  I built a shell script
   "xcc":

   #!/bin/sh
   GHC=/ghc/ghc-6.8.2
   PATH=/c$GHC/gcc-lib:$PATH
   export PATH
   /c$GHC/gcc -I $GHC/include -I $GHC/include/mingw \
              -I $GHC/gcc-lib/include -L $GHC/gcc-lib "$@"

- During linking it did not find crt2.o and adding it to PATH and
   -L did not help, so I just copied wholesale all of
   /c/ghc/ghc-6.8.2/gcc-lib into my zlib source directory.

- At this point I was able to build with:
   CC=./xcc ./configure --prefix=/c/ghc/ghc-6.8.2 \
                        --libdir=/c/ghc/ghc-6.8.2
   make
   make install

Why is the gcc in ghc's directory so non-functional?

Ok, so with zlib (the C library) installed, the zlib haskell package
installs properly.  Dependency resolved.

Next, to build darcs I had to configure it without libcurl support
(or alternately spend time chasing down that dep, pass for now). 
Using cygwin I ran "./configure" which falsely uses the cygwin gcc
for configuration checks, but since gcc is never used directly during
the compilation process, that doesn't matter that much.  I could have
tried the "xcc" trick here again, but didn't bother.  I ran into
two problems during the build:

- -Werror is specified in the GNUMakefile and there are many warnings.
   I just removed -Werror for now.

- During linking it was not able to resolve "SleepEx" from
   src/win32/System/Posix.hs.  I could not figure out what is going
   on here.  I tried adding "-lkernel32" and "-L /ghc/ghc-6.8.2/gcc-lib
   -Lkernel32" to the Makefile and it still did not work even though
   /ghc/ghc-6.8.2/gcc-lib/libkernel32.a has SleepEx@8 defined(!)
   Finally I bit the bullet and hacked around this by noticing that
   mingw headers have _sleep() defined.  I replaced the code in Posix.hs
   with:

   foreign import ccall "_sleep" c_sleep :: CULong -> IO ()

   sleep :: Integer -> IO CInt
   sleep n = c_sleep (fromIntegral n) >> return (toEnum $ fromIntegral n)

At this point darcs builds and the binary seems to work (so far).
I don't know the implication of my sleep hack (which doesn't return
the actual time slept).

Here's a small test program which uses FFI to SleepEx which I was
not able to get working with win32 ghc-6.8.2.

------
{-# OPTIONS -fglasgow-exts -fffi #-}
module Main where
import Foreign.C.Types

foreign import ccall "SleepEx" c_SleepEx :: CUInt -> CInt -> IO CInt

main = do
     putStrLn "start"
     n <- c_SleepEx (2*1000) 1
     print n
-------

So, what is going on with ghc-6.8.2?  Why is the gcc so hard to use
now?  Why can't I get FFI working with standard win32 functions?
Why aren't there prebuilt win32 darcs binaries anymore?

Tim Newsham
http://www.thenewsh.com/~newsham/
msg4986 (view) Author: newsham Date: 2008-06-05.23:30:03
I posted a follow up on haskell-cafe.  In summary:
   1) I didnt need to use haskell zlib package.  Darcs uses libz.a
      directly.
   2) the latest zlib package doesnt require libz.a to be built.
   2) building libz.a is still hard using ghc's cc, but it could
      also be built in other ways or retrieved in binary form
   3) the SleepEx FFI call works if it is changed from "ccall" to
      "stdcall".

> New submission from Tim Newsham <newsham@lava.net>:
>
> I built darcs for win32 recently and it was much more difficult than
> it should be.  Probably most of the blame goes to ghc-6.8.2 binary
> release for win32.  Half of the effort is getting the zlib prereq
> working.
>
> Previously to build zlib for win32 ghc I did the following:
> http://www.haskell.org/pipermail/haskell-cafe/2007-March/023059.html
>
> However, now, the gcc binary for ghc-6.8.2 does not work as well as
> I would like which requires a bit more effort:
>
> - It did not automatically add mingw headers during compilation, and
>   to fix this I had to force some extra flags.  I built a shell script
>   "xcc":
>
>   #!/bin/sh
>   GHC=/ghc/ghc-6.8.2
>   PATH=/c$GHC/gcc-lib:$PATH
>   export PATH
>   /c$GHC/gcc -I $GHC/include -I $GHC/include/mingw \
>              -I $GHC/gcc-lib/include -L $GHC/gcc-lib "$@"
>
> - During linking it did not find crt2.o and adding it to PATH and
>   -L did not help, so I just copied wholesale all of
>   /c/ghc/ghc-6.8.2/gcc-lib into my zlib source directory.
>
> - At this point I was able to build with:
>   CC=./xcc ./configure --prefix=/c/ghc/ghc-6.8.2 \
>                        --libdir=/c/ghc/ghc-6.8.2
>   make
>   make install
>
> Why is the gcc in ghc's directory so non-functional?
>
> Ok, so with zlib (the C library) installed, the zlib haskell package
> installs properly.  Dependency resolved.
>
> Next, to build darcs I had to configure it without libcurl support
> (or alternately spend time chasing down that dep, pass for now).
> Using cygwin I ran "./configure" which falsely uses the cygwin gcc
> for configuration checks, but since gcc is never used directly during
> the compilation process, that doesn't matter that much.  I could have
> tried the "xcc" trick here again, but didn't bother.  I ran into
> two problems during the build:
>
> - -Werror is specified in the GNUMakefile and there are many warnings.
>   I just removed -Werror for now.
>
> - During linking it was not able to resolve "SleepEx" from
>   src/win32/System/Posix.hs.  I could not figure out what is going
>   on here.  I tried adding "-lkernel32" and "-L /ghc/ghc-6.8.2/gcc-lib
>   -Lkernel32" to the Makefile and it still did not work even though
>   /ghc/ghc-6.8.2/gcc-lib/libkernel32.a has SleepEx@8 defined(!)
>   Finally I bit the bullet and hacked around this by noticing that
>   mingw headers have _sleep() defined.  I replaced the code in Posix.hs
>   with:
>
>   foreign import ccall "_sleep" c_sleep :: CULong -> IO ()
>
>   sleep :: Integer -> IO CInt
>   sleep n = c_sleep (fromIntegral n) >> return (toEnum $ fromIntegral n)
>
> At this point darcs builds and the binary seems to work (so far).
> I don't know the implication of my sleep hack (which doesn't return
> the actual time slept).
>
> Here's a small test program which uses FFI to SleepEx which I was
> not able to get working with win32 ghc-6.8.2.
>
> ------
> {-# OPTIONS -fglasgow-exts -fffi #-}
> module Main where
> import Foreign.C.Types
>
> foreign import ccall "SleepEx" c_SleepEx :: CUInt -> CInt -> IO CInt
>
> main = do
>     putStrLn "start"
>     n <- c_SleepEx (2*1000) 1
>     print n
> -------
>
> So, what is going on with ghc-6.8.2?  Why is the gcc so hard to use
> now?  Why can't I get FFI working with standard win32 functions?
> Why aren't there prebuilt win32 darcs binaries anymore?
>
> Tim Newsham
> http://www.thenewsh.com/~newsham/
>
> ----------
> messages: 4947
> nosy: beschmi, dagit, newsham, tommy
> status: unread
> title: very difficult to build win32 darcs with ghc-6.8.2
>
> __________________________________
> Darcs bug tracker <bugs@darcs.net>
> <http://bugs.darcs.net/issue899>
> __________________________________
>

Tim Newsham
http://www.thenewsh.com/~newsham/
History
Date User Action Args
2008-06-04 22:23:41newshamcreate
2008-06-05 07:03:12koweysetpriority: feature
status: unread -> duplicate
superseder: + very difficult to build win32 darcs with ghc-6.8.2
nosy: tommy, beschmi, dagit, newsham
2008-06-05 23:30:06newshamsetnosy: + newsham
messages: + msg4986
2009-08-06 21:06:57adminsetnosy: + dmitry.kurochkin, simon, kowey, thorkilnaur, - beschmi
2009-08-11 00:16:06adminsetnosy: - dagit
2009-08-25 18:11:58adminsetnosy: + darcs-devel, - simon
2009-08-27 14:00:48adminsetnosy: tommy, kowey, darcs-devel, thorkilnaur, dmitry.kurochkin, newsham, newsham