Commit 2002bc3d authored by Ian Lynagh's avatar Ian Lynagh
Browse files

Get rid of compat/

Compat.Unicode is not utils/Unicode in the compiler.
We build the hpc package with the stage1 compiler.
Nothing else in the compat package was still used.
parent 69adcec2
......@@ -67,12 +67,12 @@ include $(TOP)/mk/
# We can't 'make boot' in libraries until stage1 is built
ifeq "$(BootingFromHc)" "YES"
SUBDIRS_BUILD = includes rts compat compiler docs utils driver
SUBDIRS_BUILD = includes rts compiler docs utils driver
SUBDIRS_BUILD = includes compat utils driver docs compiler rts libraries/Cabal/doc
SUBDIRS_BUILD = includes utils driver docs compiler rts libraries/Cabal/doc
SUBDIRS = gmp libffi includes compat utils driver docs rts libraries compiler libraries/Cabal/doc
SUBDIRS = gmp libffi includes utils driver docs rts libraries compiler libraries/Cabal/doc
# Sanity check that all the boot libraries are in the tree, to catch
# failure to run darcs-all.
......@@ -312,7 +312,6 @@ binary-dist-pre::
echo 'include $$(TOP)/mk/' > $(BIN_DIST_DIR)/mk/
echo 'include $$(TOP)/mk/' >> $(BIN_DIST_DIR)/mk/
echo 'include $$(TOP)/mk/' >> $(BIN_DIST_DIR)/mk/
echo '' > $(BIN_DIST_DIR)/mk/
cp mk/ $(BIN_DIST_DIR)/mk/
cp mk/ $(BIN_DIST_DIR)/mk/
cp mk/ $(BIN_DIST_DIR)/mk/
......@@ -533,7 +532,6 @@ hc-file-bundle :
$(LN_S) . ghc-$(ProjectVersion)
$(FIND) ghc-$(ProjectVersion)/compiler \
ghc-$(ProjectVersion)/utils \
ghc-$(ProjectVersion)/compat \
ghc-$(ProjectVersion)/libraries -follow \
\( -name "*.hc" -o -name "*_hsc.[ch]" -o -name "*_stub.[ch]" \) -print > hc-files-to-go
for f in `$(FIND) ghc-$(ProjectVersion)/compiler ghc-$(ProjectVersion)/utils ghc-$(ProjectVersion)/libraries -name "*.hsc" -follow -print` ""; do \
include $(TOP)/mk/
Data \
Compat \
Trace/Hpc \
LIBRARY = libghccompat.a
# We don't want this installed
# Avoid building the GHCi lib, since we don't need it
GhcWithInterpreter = NO
# There are lots of warnings in here due to things like modules being
# imported that, in some versions of GHC, aren't used. Thus we don't
# give any warnings in here, and therefore validating with -Werror won't
# make the build fail.
# Needed so that the libraries can #include relative to this directory.
INCLUDE_DIRS=-I. -Iinclude
# Just to silence warnings
UseGhcForCc = YES
# This library is linked to the compiler, at least in stage1, so we
# better make sure it is built the same "way".
# BUT, if GhcHcOpts includes -DDEBUG we *don't* want to compile
# lib/compat with -DDEBUG, because the preprocessor symbols used
# by the compiler may be understood differently by library code.
# In this particular case, it turned out that -DDEBUG made Cabal
# import HUnit, which might not be installed for the compiler we are
# compiling with (e.g. 6.2.1). Hence the filter-out.
SRC_HC_OPTS += $(filter-out -D%, $(GhcHcOpts) $(GhcStage1HcOpts))
# GHC 6.4 didn't have WCsubst.c, but 6.4.1 did, and we need to know
# this in cbits/unicode.c The patchlevel isn't normally exposed as a
# CPP symbol, so we have to do it by hand:
SRC_CC_OPTS += -D__GHC_PATCHLEVEL__=$(GhcPatchLevel)
# This module shouldn't be compiled itself, only #included into other files
EXCLUDED_SRCS += System/FilePath/Internal.hs
ifeq "$(ghc_ge_607)" "YES"
SRC_HC_OPTS += -package directory
SRC_HC_OPTS += -package pretty
# Some explicit dependencies, needed because ghc -M can't discover the
# true dependencies of these stub files.
System/Directory/Internals.$(way_)o : $(FPTOOLS_TOP)/libraries/directory/System/Directory/Internals.hs
Trace/Hpc/Mix.$(way_)o : $(FPTOOLS_TOP)/libraries/hpc/Trace/Hpc/Mix.hs
Trace/Hpc/Util.$(way_)o : $(FPTOOLS_TOP)/libraries/hpc/Trace/Hpc/Util.hs
Trace/Hpc/Tix.$(way_)o : $(FPTOOLS_TOP)/libraries/hpc/Trace/Hpc/Tix.hs
cbits/unicode.o : $(FPTOOLS_TOP)/libraries/base/cbits/WCsubst.c $(FPTOOLS_TOP)/libraries/base/include/WCsubst.h
SRC_CC_OPTS += -I$(FPTOOLS_TOP)/libraries/base/cbits -I$(FPTOOLS_TOP)/libraries/base/include
# Make the #includes in the stubs independent of the current location
SRC_HC_OPTS += -I$(FPTOOLS_TOP)/libraries
SRC_HC_OPTS += -fglasgow-exts
ifeq "$(ghc_ge_609)" "YES"
SRC_HC_OPTS += -fforce-recomp
SRC_HC_OPTS += -no-recomp
ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
Compat/Directory_HC_OPTS += -\#include shlobj.h
# libghccompat is needed to build ghc-pkg, which is built during 'make boot',
# so we must build this library during 'make boot' too.
# Do a recursive 'make all' after generating dependencies, because this
# will work with 'make -j'.
ifneq "$(BootingFromHc)" "YES"
boot :: depend
$(MAKE) all
# We don't ever want to build libghccompat as a shared library.
include $(TOP)/mk/
GHC compatibiliy library: libghccompat.a
This library contains interfaces that are available in recent versions
of GHC, but may or may not be available in older versions. The idea
is to provide an abstraction layer and reduce the amount of #ifdefery
and code duplication in GHC and its tools. Furthermore, we can add
modules to the main library and start using them right away in GHC, by
adding a stub to this compat library.
There are two types of modules in here:
(a) a module with the same name as a module in the main library
(eg. Distribution.Package). If the module is available in
the main library, then we don't include it in libghccompat.
Otherwise, we have a stub module here that just #includes
the source from the real location under libraries/. Go look
at Distribution/Package.hs for example.
(b) a module that doesn't exist in another library. For example,
Compat.RawSystem. These modules are used to provide functions
that are available in newer versions of the main libraries.
BIG NOTE: when building stage 2 of GHC, libghccompat is not used,
because we would have to build another version of it. Instead, we
just use the appropriate libraries directly. For (a)-type modules,
just import the module directly. For (b)-type modules, a single
#ifdef will be required to choose between the Compat version and
the real version.
In stage 1 of GHC, and tools (eg. ghc-pkg, runghc), libghccompat.a
is linked in, so all its libraries will be accessible.
{-# OPTIONS -cpp #-}
#include "hpc/Trace/Hpc/Mix.hs"
-- dummy comment
{-# OPTIONS -cpp #-}
#include "hpc/Trace/Hpc/Tix.hs"
-- dummy comment
{-# OPTIONS -cpp #-}
#include "hpc/Trace/Hpc/Util.hs"
-- dummy comment
#include "HsFFI.h"
#include "../../../includes/ghcconfig.h"
#include <limits.h>
#include <windows.h>
#include "directory.h"
#define INLINE /* nothing */
* Following code copied from libraries/base/includes/HsBase.h
#ifdef PATH_MAX
/* A size that will contain many path names, but not necessarily all
* (PATH_MAX is not defined on systems with unlimited path length,
* e.g. the Hurd).
INLINE int __compat_long_path_size() { return PATH_MAX; }
INLINE int __compat_long_path_size() { return 4096; }
#if defined(mingw32_HOST_OS)
#if __GLASGOW_HASKELL__ < 604
/* Make sure we've got the reqd CSIDL_ constants in scope;
* w32api header files are lagging a bit in defining the full set.
#if !defined(CSIDL_APPDATA)
#define CSIDL_APPDATA 0x001a
#if !defined(CSIDL_PERSONAL)
#define CSIDL_PERSONAL 0x0005
#if !defined(CSIDL_PROFILE)
#define CSIDL_PROFILE 0x0028
#if !defined(CSIDL_WINDOWS)
#define CSIDL_WINDOWS 0x0024
INLINE int __hscore_CSIDL_PROFILE() { return CSIDL_PROFILE; }
INLINE int __hscore_CSIDL_APPDATA() { return CSIDL_APPDATA; }
INLINE int __hscore_CSIDL_WINDOWS() { return CSIDL_WINDOWS; }
* Function: __hscore_getFolderPath()
* Late-bound version of SHGetFolderPath(), coping with OS versions
* that have shell32's lacking that particular API.
__hscore_getFolderPath(HWND hwndOwner,
int nFolder,
HANDLE hToken,
DWORD dwFlags,
char* pszPath)
static int loaded_dll = 0;
/* The DLLs to try loading entry point from */
char* dlls[] = { "shell32.dll", "shfolder.dll" };
if (loaded_dll < 0) {
return (-1);
} else if (loaded_dll == 0) {
int i;
for(i=0;i < sizeof(dlls); i++) {
hMod = LoadLibrary(dlls[i]);
if ( hMod != NULL &&
(funcPtr = (HSCORE_GETAPPFOLDERFUNTY)GetProcAddress(hMod, "SHGetFolderPathA")) ) {
loaded_dll = 1;
if (loaded_dll == 0) {
loaded_dll = (-1);
return (-1);
/* OK, if we got this far the function has been bound */
return (int)funcPtr(hwndOwner,nFolder,hToken,dwFlags,pszPath);
/* ToDo: unload the DLL on shutdown? */
#endif /* __GLASGOW_HASKELL__ < 604 */
#endif /* mingw32_HOST_OS */
* (c) The University of Glasgow 1994-2004
* WARNING: this file is here for backwards compatibility only. It is
* not included as part of the base package, but is #included into the
* compiler and the runghc utility when building either of these with
* an old version of GHC.
* shell-less system Runtime Support (see System.Cmd.rawSystem).
/* The itimer stuff in this module is non-posix */
/* #include "PosixSource.h" */
#include "../../../includes/ghcconfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/wait.h>
# include <sys/time.h>
# include <time.h>
# else
# include <sys/time.h>
# else
# include <time.h>
# endif
# endif
#include "HsFFI.h"
#if defined(mingw32_HOST_OS)
#include <windows.h>
#include <vfork.h>
#define fork vfork
#if defined(mingw32_HOST_OS)
/* -------------------- WINDOWS VERSION --------------------- */
rawSystem(char *cmd)
DWORD retCode;
ZeroMemory(&sInfo, sizeof(sInfo));
sInfo.cb = sizeof(sInfo);
if (!CreateProcess(NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &sInfo, &pInfo)) {
/* The 'TRUE' says that the created process should share
handles with the current process. This is vital to ensure
that error messages sent to stderr actually appear on the screen.
Since we are going to wait for the process to terminate anyway,
there is no problem with such sharing. */
errno = EINVAL; // ToDo: wrong, caller should use GetLastError()
return -1;
WaitForSingleObject(pInfo.hProcess, INFINITE);
if (GetExitCodeProcess(pInfo.hProcess, &retCode) == 0) {
errno = EINVAL; // ToDo: wrong, caller should use GetLastError()
return -1;
return retCode;
/* -------------------- UNIX VERSION --------------------- */
rawSystem(char *cmd, char **args)
int pid;
int wstat;
switch(pid = fork()) {
case -1:
return -1;
case 0:
/* Reset the itimers in the child, so it doesn't get plagued
* by SIGVTALRM interrupts.
struct timeval tv_null = { 0, 0 };
struct itimerval itv;
itv.it_interval = tv_null;
itv.it_value = tv_null;
setitimer(ITIMER_REAL, &itv, NULL);
setitimer(ITIMER_VIRTUAL, &itv, NULL);
setitimer(ITIMER_PROF, &itv, NULL);
/* the child */
execvp(cmd, args);
while (waitpid(pid, &wstat, 0) < 0) {
if (errno != EINTR) {
return -1;
if (WIFEXITED(wstat))
return WEXITSTATUS(wstat);
else if (WIFSIGNALED(wstat)) {
errno = EINTR;
else {
/* This should never happen */
return -1;
# Settings for using the libghccompat.a library elsewhere in the build
# tree: this file is just included into Makefiles, see
# utils/ghc-pkg/Makefile for example.
# This is a poor-mans package, but simpler because we don't
# have to deal with variations in the package support of different
# versions of GHC.
ifneq "$(UseStage1)" "YES"
# Use libghccompat.a:
SRC_LD_OPTS += -L$(GHC_COMPAT_DIR) -lghccompat
ifeq "$(ghc_ge_607)" "YES"
SRC_HC_OPTS += -package directory
SRC_HC_OPTS += -package pretty
SRC_HC_OPTS += -package containers
# And similarly for when booting from .hc files:
HC_BOOT_LIBS += -lghccompat
ifeq "$(Windows)" "YES"
# not very nice, but required for -lghccompat on Windows
SRC_LD_OPTS += -lshell32
HC_BOOT_LIBS += -lshell32
# This is horrible. We ought to be able to omit the entire directory
# from mkDependHS.
-optdep--exclude-module=Compat.Unicode \
-optdep--exclude-module=Trace.Hpc.Mix \
-optdep--exclude-module=Trace.Hpc.Tix \
PACKAGE_CABAL = -package Cabal
PACKAGE_HPC = -package hpc
#ifndef __DIRECTORY_H__
#define __DIRECTORY_H__
#if defined(mingw32_HOST_OS)
extern int __compat_long_path_size();
extern int __hscore_CSIDL_APPDATA();
extern int __hscore_getFolderPath(HWND hwndOwner,
int nFolder,
HANDLE hToken,
DWORD dwFlags,
char* pszPath);
......@@ -483,10 +483,13 @@ endif
# the interpreter is supported on this platform.
ifeq "$(bootstrapped)" "YES"
SRC_HC_OPTS += -package hpc -package bytestring
PKG_DEPENDS += hpc bytestring
SRC_HC_OPTS += -package bytestring
PKG_DEPENDS += bytestring
SRC_HC_OPTS += -package hpc
ifeq "$(GhcWithInterpreter) $(bootstrapped)" "YES YES"
# Yes, include the interepreter and Template Haskell extensions
......@@ -756,13 +759,6 @@ primop-usage.hs-incl: prelude/primops.txt
# Linking
# Include libghccompat in stage1 only. In stage2 onwards, all these
# libraries will be available from the main libraries.
ifeq "$(stage)" "1"
include $(GHC_COMPAT_DIR)/
ifeq "$(GhcUnregisterised)" "NO"
ifeq "$(HOSTPLATFORM)" "ia64-unknown-linux"
# needed for generating proper relocation in large binaries: trac #856
......@@ -1089,12 +1085,8 @@ ifneq "$(BootingFromHc)" "YES"
$(MKDEPENDHS) -M -optdep-f -optdep.depend-BASE $(foreach way,$(WAYS),-optdep-s -optdep$(way)) $(foreach obj,$(MKDEPENDHS_OBJ_SUFFICES),-osuf $(obj)) $(MKDEPENDHS_OPTS) $(filter-out -split-objs, $(MKDEPENDHS_HC_OPTS)) $(HS_SRCS)
$(MKDEPENDC) -f .depend-BASE $(MKDEPENDC_OPTS) $(foreach way,$(WAYS),-s $(way)) -- $(CC_OPTS) -- $(C_SRCS)
$(PERL) -pe 'binmode(stdin); binmode(stdout); s@(\S*[._]o)@stage$(stage)/$$1@g; s@(\S*[._]hi)@stage$(stage)/$$1@g; s@^.*/compat.*$$@@g;' <.depend-BASE >.depend-$(stage)
$(PERL) -pe 'binmode(stdin); binmode(stdout); s@(\S*[._]o)@stage$(stage)/$$1@g; s@(\S*[._]hi)@stage$(stage)/$$1@g;' <.depend-BASE >.depend-$(stage)
# The binmode stuff tells perl not to add stupid ^M's to the output
# The /lib/compat replacement is to workaround a bug in the
# -optdep--exclude-module flag in GHC 6.4. It is not required for any
# other version of GHC, but doesn't do any harm.
ifeq "$(MakefileDeps)" "YES"
$(CONFIG_HS) : Makefile
......@@ -60,11 +60,7 @@ import Data.Char ( chr, ord, isSpace )
import Data.Ratio
import Debug.Trace
#if __GLASGOW_HASKELL__ >= 605
import Data.Char ( GeneralCategory(..), generalCategory, isPrint, isUpper )
import Compat.Unicode ( GeneralCategory(..), generalCategory, isPrint, isUpper )
import Unicode ( GeneralCategory(..), generalCategory, isPrint, isUpper )
$unispace = \x05 -- Trick Alex into handling Unicode. See alexGetChar.
{-# OPTIONS -cpp #-}
module Compat.Unicode (
module Unicode (
GeneralCategory(..), generalCategory, isPrint, isUpper
) where
......@@ -55,7 +55,10 @@ generalCategory c = toEnum $ fromIntegral $ wgencat $ fromIntegral $ ord c
foreign import ccall unsafe "u_gencat"
wgencat :: CInt -> CInt
isPrint :: Char -> Bool
isPrint c = iswprint (fromIntegral (ord c)) /= 0
isUpper :: Char -> Bool
isUpper c = iswupper (fromIntegral (ord c)) /= 0
foreign import ccall unsafe "u_iswprint"
......@@ -164,7 +164,7 @@ ifeq "$(ghc_ge_605)" "NO"
BOOTSTRAPPING_FLAGS = $(CABAL_GHC_FLAGS) -DCABAL_VERSION=1,3 -odir $(HERE_ABS)/bootstrapping -hidir $(HERE_ABS)/bootstrapping -i$(HERE_ABS)/Cabal -i$(HERE_ABS)/filepath
BOOTSTRAPPING_FLAGS = $(CABAL_GHC_FLAGS) -DCABAL_VERSION=1,3 -odir $(HERE_ABS)/bootstrapping -hidir $(HERE_ABS)/bootstrapping -i$(HERE_ABS)/Cabal -i$(HERE_ABS)/filepath -i$(HERE_ABS)/hpc
.PHONY: boot
......@@ -183,6 +183,10 @@ bootstrapping.conf: cabal-bin
cd Cabal && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
cd Cabal && $(CABAL) build --distpref=dist-bootstrapping
cd Cabal && $(CABAL) install --distpref=dist-bootstrapping --inplace
-cd hpc && $(CABAL) clean --distpref=dist-bootstrapping
cd hpc && $(CABAL) configure --distpref=dist-bootstrapping --with-compiler=$(GHC) --with-hc-pkg=$(GHC_PKG) --package-db=$(HERE_ABS)/$@.tmp
cd hpc && $(CABAL) build --distpref=dist-bootstrapping
cd hpc && $(CABAL) install --distpref=dist-bootstrapping --inplace
mv $@.tmp $@
installPackage/installPackage: installPackage.hs
......@@ -327,6 +331,7 @@ distclean: clean
clean: $(foreach SUBDIR,$(SUBDIRS),clean.library.$(SUBDIR))
-cd filepath && $(CABAL) clean --distpref=dist-bootstrapping
-cd Cabal && $(CABAL) clean --distpref=dist-bootstrapping
-cd hpc && $(CABAL) clean --distpref=dist-bootstrapping
$(RM) -rf bootstrapping/*
$(RM) -f bootstrapping.conf bootstrapping.conf.old
$(RM) -f bootstrapping.conf.tmp bootstrapping.conf.tmp.old
......@@ -15,16 +15,8 @@ endif
SRC_HC_OPTS += -cpp -Wall -fno-warn-name-shadowing -fno-warn-unused-matches
# This causes libghccompat.a to be used:
include $(GHC_COMPAT_DIR)/
# This is required because libghccompat.a must be built with
# $(GhcHcOpts) because it is linked to the compiler, and hence
# we must also build with $(GhcHcOpts) here:
SRC_HC_OPTS += $(GhcHcOpts) $(GhcStage1HcOpts)
ifeq "$(Windows)" "NO"
SRC_HC_OPTS += -package unix
......@@ -20,8 +20,7 @@ endif
HPC_LIB = $(TOP)/libraries/hpc
include $(GHC_COMPAT_DIR)/
SRC_HC_OPTS += -package hpc -cpp
ifeq "$(ghc_ge_607)" "YES"
SRC_HC_OPTS += -package containers
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment