From 2719d1e57ba9524b3acdb2b270508704f6306137 Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Tue, 17 Feb 2009 21:50:48 +0000 Subject: [PATCH] Make versioned ghc and ghci programs on Windows; fixes trac #2827 --- driver/ghc/Makefile | 5 +- driver/ghc/ghc.c | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++ driver/ghci/Makefile | 10 +++- 3 files changed, 167 insertions(+), 2 deletions(-) create mode 100644 driver/ghc/ghc.c diff --git a/driver/ghc/Makefile b/driver/ghc/Makefile index 4eeb3f9..55167ec 100644 --- a/driver/ghc/Makefile +++ b/driver/ghc/Makefile @@ -1,7 +1,10 @@ TOP=../.. include $(TOP)/mk/boilerplate.mk -ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32" +ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32" +C_PROG = ghc-$(ProjectVersion) +INSTALL_PROGS += $(C_PROG) +else SCRIPT_DIR = $(DESTDIR)$(bindir) SCRIPT_BASE = ghc SCRIPT_VERSIONED_BASE = $(SCRIPT_BASE)-$(ProjectVersion) diff --git a/driver/ghc/ghc.c b/driver/ghc/ghc.c new file mode 100644 index 0000000..3f4a4a5 --- /dev/null +++ b/driver/ghc/ghc.c @@ -0,0 +1,154 @@ +/* + * + * ghc wrapper for Win32 only + * + * This wrapper simply invokes ghc.exe + * + * (c) The GHC Team 2001 + * + * ghc.exe is searched for using the 'normal' search rules + * for DLLs / EXEs (i.e., first in the same dir as this wrapper, + * then system dirs, then PATH). + * + * To compile: + * + * MSVC: cl /o ghc.exe /c ghc.c + * mingw: gcc -o ghc.exe ghc.c + * + * If you want to associate your own icon with the wrapper, + * here's how to do it: + * + * * Create a one-line .rc file, ghc.rc (say), containing + * 0 ICON "hsicon.ico" + * (subst the string literal for the name of your icon file). + * * Compile it up (assuming the .ico file is in the same dir + * as the .rc file): + * + * MSVC: rc /i. /fo ghc.res ghc.rc + * mingw: windres -o ghc.res -i ghc.rc -O coff + * + * * Add the resulting .res file to the link line of the wrapper: + * + * MSVC: cl /o ghc.exe /c ghc.c ghc.res + * mingw: gcc -o ghc.exe ghc.c ghc.res + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#define BINARY_NAME "ghc.exe" + +#define errmsg(msg) fprintf(stderr, msg "\n"); fflush(stderr) +#define errmsg1(msg,val) fprintf(stderr, msg "\n",val); fflush(stderr) + +int +main(int argc, char** argv) +{ + TCHAR binPath[FILENAME_MAX+1]; + TCHAR binPathShort[MAX_PATH+1]; + DWORD dwSize = FILENAME_MAX; + TCHAR* szEnd; + int i; + char* new_cmdline; + char *ptr, *src; + unsigned int cmdline_len = 0; + char **pp; + LPTSTR pp1; + + STARTUPINFO si; + PROCESS_INFORMATION pi; + + ZeroMemory(&pi, sizeof(PROCESS_INFORMATION)); + ZeroMemory(&si, sizeof(STARTUPINFO)); + si.cb = sizeof(STARTUPINFO); + + /* Locate the binary we want to start up */ + if ( !SearchPath(NULL, + BINARY_NAME, + NULL, + dwSize, + (char*)binPath, + &szEnd) ) { + errmsg1("%s: Unable to locate ghc.exe", argv[0]); + return 1; + } + + dwSize = MAX_PATH; + /* Turn the path into short form - LFN form causes problems + when passed in argv[0]. */ + if ( !(GetShortPathName(binPath, binPathShort, dwSize)) ) { + errmsg1("%s: Unable to locate ghc.exe", argv[0]); + return 1; + } + + /* Compute length of the flattened 'argv' */ + for(i=1;i> $(GHCII_SCRIPT) echo 'exec "$$0"/../ghc --interactive $${1+"$$@"}' >> $(GHCII_SCRIPT) chmod +x $(GHCII_SCRIPT) + cp $(GHCII_SCRIPT) $(GHCII_SCRIPT_VERSIONED) + chmod +x $(GHCII_SCRIPT_VERSIONED) else LINK = ghci LINK_TARGET = $(LINK)-$(ProjectVersion) -- 1.7.10.4