ghc/cygwin filename resolution issue.

George Russell ger@tzi.de
Wed, 29 Jan 2003 12:22:43 +0100


This is a multi-part message in MIME format.
--------------C450625CF1716839FE71D354
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Alex wrote
[snip]
> Using ghc-5.04.2 under cygwin, and cygwin (v. 1.3.10-1), I'm having some
> horrible problems with inconistent treatment of filenames, especially
> when using (gnu, cygwin) make.  In a nutshell, make seems to be passing
> paths such as "/usr/local/hmake" (etc) to ghc, which is, as I understand
> it, interpretting these in a manner consistent with windows, but not with
> cygwin.  (i.e., it'd expect the above to be something like:
> /cygwin/usr/local/hmake, where the root of the cygwin installation is in
> c:\cygwin.  Experimenting with similar arguments to ghc by hand seems to
> confirm this.
[snip]

The UniForM/HTk distribution includes the attached very simple Haskell98 program,
which is compiled and run during the ./configure stage.  This program transforms
stdin to stdout, globally replacing the string "#PWD" with whatever GHC thinks the
current directory is called.  This program is used in various ways; in particular
./configure uses it to set a variable GHCTOP corresponding to GHC's name for the
top of the source distribution, which is then what gets passed to GHC.  The program
is also used for various unholy tricks involving package config files, which also
of course need the Windows name.

Fortunately GHC doesn't mind if some slashes are the wrong way; thus if GHCTOP is
"C:\foo\bar\uni", then I can refer to "C:\foo\bar\uni\baz" as $GHCTOP/baz, as
it would be on Unix.
--------------C450625CF1716839FE71D354
Content-Type: text/plain; charset=us-ascii;
 name="MainFixFileNames.hs"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="MainFixFileNames.hs"

{- This program converts stdin to stdout.  It replaces all occurrences of
   the string "#PWD" in stdin with the current directory in which it is
   executed, C escaped.  The string "#pwd" is similarly replaced, except that
   it is not escaped.   Everything else is left unchanged.

   If an argument is supplied, this is used instead of the current
   directory.  


   The program occupies an unusual place in the UniForM sources; it is not
   part of the main sources, but is only used during building (see suffix.mk)
   and is compiled during configuration.  Since it only uses completely
   standard Haskell 98, this ought to be pretty easy.

   We do things this way rather than with some sort of script so that this
   will work even in the extremely hostile environment of Windows (with no
   cygwin).  Also, using GHC's getCurrentDirectory means we get at what
   GHC thinks the current directory is (IE the Windows file name) rather than
   what it is in cygwin's Unix world.
   -}
module Main (main) where

import Directory
import System

main :: IO ()
main = 
   do
      input <- getContents
      args <- getArgs
      toInsert <- case args of
        [arg] -> return arg
        [] -> getCurrentDirectory   
      let
         escapeString s = 
            let
               withQuotes @ ('\"':rest) = show s
            in
               take (length rest - 1) rest

         quoted = escapeString toInsert
            
         transform [] = []
         transform ('#':'P':'W':'D':rest) = quoted ++ transform rest
         transform ('#':'p':'w':'d':rest) = toInsert ++ transform rest
         transform (c:rest) = c:transform rest
      putStr . transform  $ input




--------------C450625CF1716839FE71D354--