[MLton-commit] r6800
Wesley Terpstra
wesley at mlton.org
Sun Aug 24 16:46:38 PDT 2008
Initial scripts to build a MLton win32 installer.
----------------------------------------------------------------------
A mlton/trunk/package/mingw/Makefile
A mlton/trunk/package/mingw/dirs2wix-filesys.sml
A mlton/trunk/package/mingw/files2wix-feature.sml
A mlton/trunk/package/mingw/mlton.wxs
A mlton/trunk/package/mingw/msys.bat
----------------------------------------------------------------------
Added: mlton/trunk/package/mingw/Makefile
===================================================================
--- mlton/trunk/package/mingw/Makefile 2008-08-24 23:39:00 UTC (rev 6799)
+++ mlton/trunk/package/mingw/Makefile 2008-08-24 23:46:33 UTC (rev 6800)
@@ -0,0 +1,63 @@
+WIX="/c/Program Files/WiX"
+TARDIR=/c/DOCUME~1/terpstra/Desktop/downloads/mingw
+MLTON=mlton
+
+MINGW_RUNTIME=$(TARDIR)/mingw-runtime-3.14.tar.gz
+MINGW_W32API=$(TARDIR)/w32api-3.11.tar.gz
+MINGW_BINUTILS=$(TARDIR)/binutils-2.17.50-20060824-1.tar.gz
+MINGW_GCC=$(TARDIR)/gcc-core-3.4.5-20060117-1.tar.gz
+MINGW_MSYS=$(TARDIR)/msysCORE-1.0.11-2007.01.19-1.tar.bz2
+
+MINGW_WXS=mingw-runtime.wxs w32api.wxs binutils.wxs gcc.wxs msys.wxs
+MINGW_WIXOBJ=$(patsubst %.wxs,%.wixobj,$(MINGW_WXS))
+
+mlton.msi: mlton.wixobj self.wixobj filesys.wixobj $(MINGW_WIXOBJ)
+ $(WIX)/light -out $@ $^ $(WIX)/wixui.wixlib -loc $(WIX)/WixUI_en-us.wxl
+
+clean:
+ rm -rf staging mlton.msi *.wixobj *.exe $(MINGW_WXS) self.wxs filesys.wxs
+
+%.wixobj: %.wxs
+ $(WIX)/candle $<
+
+%.exe: %.sml
+ $(MLTON) $<
+
+# This has to happen after everything else is unpacked
+filesys.wxs: dirs2wix-filesys.exe $(MINGW_WIXOBJ) self.wixobj
+ cd staging; find * -type d | ../dirs2wix-filesys > ../$@.tmp
+ mv $@.tmp $@
+
+mingw-runtime.wxs: $(MINGW_RUNTIME) self.wxs
+ tar tzf $< | ./files2wix-feature "MinGW" "Runtime" "Runtime" "An assortment of thin wrappers that provide POSIX-like functionality on a windows platform." > $@.tmp
+ cd staging; tar xzf $(MINGW_RUNTIME)
+ mv $@.tmp $@
+
+w32api.wxs: $(MINGW_W32API) self.wxs
+ tar tzf $< | ./files2wix-feature "MinGW" "W32API" "W32API" "Headers and link stub libraries needed to access windows system DLLs." > $@.tmp
+ cd staging; tar xzf $(MINGW_W32API)
+ mv $@.tmp $@
+
+binutils.wxs: $(MINGW_BINUTILS) self.wxs
+ tar tzf $< | grep -v info/dir | ./files2wix-feature "MinGW" "Binutils" "Binutils" "Utilities for manipulating object files, such as the linker and assembler." > $@.tmp
+ cd staging; tar xzf $(MINGW_BINUTILS)
+ mv $@.tmp $@
+
+gcc.wxs: $(MINGW_GCC) self.wxs
+ tar tzf $< | ./files2wix-feature "MinGW" "GCC" "GCC" "The GNU C Compiler. Compiles C files to assembly." > $@.tmp
+ cd staging; tar xzf $(MINGW_GCC)
+ mv $@.tmp $@
+
+msys.wxs: $(MINGW_MSYS) self.wxs
+ (tar tjf $<; echo bin/bash.exe) | ./files2wix-feature "MinGW" "MSYS" "MSYS" "A system shell along with UNIX-style command-line utilities." > $@.tmp
+ cd staging; tar xjf $(MINGW_MSYS)
+ cp staging/bin/sh.exe staging/bin/bash.exe
+ cp msys.bat staging
+ mv $@.tmp $@
+
+self.wxs: files2wix-feature.exe
+ rm -rf staging
+ make -C ../.. PREFIX= install
+ mv ../../install staging
+ cd staging; find * -type f | ../files2wix-feature "Complete" "MLton" "MLton" "A whole-program optimizing Standard ML compiler." > ../$@.tmp
+ mv $@.tmp $@
Added: mlton/trunk/package/mingw/dirs2wix-filesys.sml
===================================================================
--- mlton/trunk/package/mingw/dirs2wix-filesys.sml 2008-08-24 23:39:00 UTC (rev 6799)
+++ mlton/trunk/package/mingw/dirs2wix-filesys.sml 2008-08-24 23:46:33 UTC (rev 6800)
@@ -0,0 +1,68 @@
+val prefix = "\
+ \<?xml version='1.0' encoding='windows-1252'?>\n\
+ \<Wix xmlns='http://schemas.microsoft.com/wix/2003/01/wi'>\n\
+ \ <Fragment Id='FragmentFileSys'>\n\
+ \ <DirectoryRef Id='INSTALLDIR'>\n"
+val suffix = "\
+ \ </DirectoryRef>\n\
+ \ </Fragment>\n\
+ \</Wix>\n"
+
+fun escape c = if Char.isAlphaNum c orelse c = #"." then c else #"_"
+val escape = CharVector.map escape
+
+val depth = ref 3
+fun pad () = CharVector.tabulate (!depth * 2, fn _ => #" ")
+fun indent (t, head) =
+ let
+ val path = head @ [t]
+ val paths = String.concatWith "/" path
+ val file83 = file83 t
+ val long = if file83 = t then "" else " LongName='" ^ t ^ "'"
+ val () =
+ print (pad () ^ "<Directory Id='dir." ^ escape paths ^ "' \
+ \Name='" ^ file83 ^ "'" ^ long ^ ">\n")
+ val () = depth := !depth + 1
+ in
+ head
+ end
+and file83 file =
+ let
+ val {base, ext} = OS.Path.splitBaseExt file
+ fun trunc x s = String.substring (s, 0, Int.min (x, String.size s))
+ val (base, ext) = (trunc 8 base, Option.map (trunc 3) ext)
+ fun crush c = if Char.contains "\\?|><:/*+,;=[] " c then #"_" else c
+ val crush = CharVector.map crush
+ val (base, ext) = (crush base, Option.map crush ext)
+ in
+ case ext of NONE => base | SOME ext => base ^ "." ^ ext
+ end
+
+fun unindent _ =
+ (depth := !depth - 1
+ ; print (pad () ^ "</Directory>\n"))
+
+fun makeDir (prevArcs, path) =
+ let
+ fun common ([], _) = 0
+ | common (_, []) = 0
+ | common (x :: r, y :: s) =
+ if x = y then 1 + common (r, s) else 0
+ val arcs = #arcs (OS.Path.fromString path)
+ val common = common (prevArcs, arcs)
+ val tailPrev = List.drop (prevArcs, common)
+ val tailPath = List.drop (arcs, common)
+ val () = List.app unindent tailPrev
+ val _ = List.foldl indent (List.take (arcs, common)) tailPath
+ in
+ arcs
+ end
+
+fun trim path = String.substring (path, 0, String.size path - 1)
+fun loop last =
+ case TextIO.inputLine TextIO.stdIn of NONE => last | SOME path =>
+ loop (makeDir (last, trim (path)))
+
+val () = print prefix
+val () = List.app unindent (loop [])
+val () = print suffix
Added: mlton/trunk/package/mingw/files2wix-feature.sml
===================================================================
--- mlton/trunk/package/mingw/files2wix-feature.sml 2008-08-24 23:39:00 UTC (rev 6799)
+++ mlton/trunk/package/mingw/files2wix-feature.sml 2008-08-24 23:46:33 UTC (rev 6800)
@@ -0,0 +1,94 @@
+fun useArgument ([], default) = ([], default)
+ | useArgument (x :: r, _) = (r, x)
+
+val args = CommandLine.arguments ()
+val (args, parentId) = useArgument (args, "Complete")
+val (args, selfId) = useArgument (args, "MainProgram")
+val (args, title) = useArgument (args, "Main Program")
+val (args, description)= useArgument (args, "")
+
+val () = if args = [] then () else
+ print "Warning: Too many arguments supplied.\n"
+
+val prefix = "\
+ \<?xml version='1.0' encoding='windows-1252'?>\n\
+ \<Wix xmlns='http://schemas.microsoft.com/wix/2003/01/wi'>\n\
+ \ <Fragment Id='Fragment" ^ selfId ^ "'>\n"
+val suffix = "\
+ \ </Fragment>\n\
+ \</Wix>\n"
+
+fun escape c = if Char.isAlphaNum c orelse c = #"." then c else #"_"
+val escape = CharVector.map escape
+
+fun feature paths =
+ let
+ val prefix = "\
+ \ <FeatureRef Id='" ^ parentId ^ "'>\n\
+ \ <Feature Id='" ^ selfId ^ "' Title='" ^ title ^ "' \
+ \Description='" ^ description ^ "' Level='1'>\n"
+ fun component path =
+ if #file (OS.Path.splitDirFile path) = "" then "" else "\
+ \ <ComponentRef Id='component." ^ escape path ^ "' />\n"
+ val suffix = "\
+ \ </Feature>\n\
+ \ </FeatureRef>\n"
+ in
+ print prefix
+ ; List.app (print o component) paths
+ ; print suffix
+ end
+
+fun dirEntry path =
+ let
+ val {dir, file} = OS.Path.splitDirFile path
+ val dir = if dir = "" then "INSTALLDIR" else "dir." ^ escape dir
+ val uglypath = escape path
+ val guid = guid path
+ val file83 = file83 file
+ in
+ if file = "" then "" else
+ " <DirectoryRef Id='" ^ dir ^ "'>\n\
+ \ <Component Id='component." ^ uglypath ^ "' \
+ \Guid='" ^ guid ^ "'>\n\
+ \ <File Id='file." ^ uglypath ^ "' \
+ \LongName='" ^ file ^ "' \
+ \Name='" ^ file83 ^ "' DiskId='1' Vital='yes' \
+ \Source='staging/" ^ path ^ "' />\n\
+ \ </Component>\n\
+ \ </DirectoryRef>\n"
+ end
+and guid path =
+ let
+ val w32 = Word32.fromLarge o Word.toLarge o MLton.Random.rand
+ val w16 = Word16.fromLarge o Word.toLarge o MLton.Random.rand
+ val zero = "00000000"
+ fun pad i s = String.substring (zero, 0, i - String.size s) ^ s
+ val w32 = pad 8 o Word32.toString o w32
+ val w16 = pad 4 o Word16.toString o w16
+ in
+ w32 () ^"-"^ w16 () ^"-"^ w16 () ^"-"^ w16 () ^"-"^ w16 () ^ w32 ()
+ end
+and file83 file =
+ let
+ val {base, ext} = OS.Path.splitBaseExt file
+ fun trunc x s = String.substring (s, 0, Int.min (x, String.size s))
+ val (base, ext) = (trunc 8 base, Option.map (trunc 3) ext)
+ fun crush c = if Char.contains "\\?|><:/*+,;=[] " c then #"_" else c
+ val crush = CharVector.map crush
+ val (base, ext) = (crush base, Option.map crush ext)
+ in
+ case ext of NONE => base | SOME ext => base ^ "." ^ ext
+ end
+
+fun trim path = String.substring (path, 0, String.size path - 1)
+fun loop files =
+ case TextIO.inputLine TextIO.stdIn of NONE => files | SOME path =>
+ (print (dirEntry (trim path)); loop ((trim path) :: files))
+
+val () = MLton.Random.srand (Word.fromLargeInt (Time.toNanoseconds (Time.now ())))
+val () = print prefix
+val files = loop []
+val () = feature (rev files)
+val () = print suffix
+
Added: mlton/trunk/package/mingw/mlton.wxs
===================================================================
--- mlton/trunk/package/mingw/mlton.wxs 2008-08-24 23:39:00 UTC (rev 6799)
+++ mlton/trunk/package/mingw/mlton.wxs 2008-08-24 23:46:33 UTC (rev 6800)
@@ -0,0 +1,42 @@
+<?xml version='1.0' encoding='windows-1252'?>
+<Wix xmlns='http://schemas.microsoft.com/wix/2003/01/wi'>
+ <Product Name='MLton' Id='E78E6DFD-5738-B137-DD2A-EA81A1A841EC'
+ UpgradeCode='C353A6D5-4A30-D7CF-62E2-04D98AF8A864'
+ Language='1033' Codepage='1252' Version='1.0' Manufacturer='MLton.org'>
+
+ <Package Id='????????-????-????-????-????????????' Keywords='Installer'
+ Description="MLton Installer"
+ Comments='MLton is an open-source, whole-program, optimizing Standard ML compiler.' Manufacturer='MLton.org'
+ InstallerVersion='100' Languages='1033' Compressed='yes' SummaryCodepage='1252' />
+
+ <Media Id='1' Cabinet='MLton.cab' EmbedCab='yes' DiskPrompt="CD-ROM #1" />
+ <Property Id='DiskPrompt' Value="MLton Installation CD [1]" />
+
+ <Directory Id='TARGETDIR' Name='SourceDir'>
+ <Directory Id='ProgramFilesFolder' Name='PFiles'>
+ <Directory Id='INSTALLDIR' Name='MLton'/>
+ </Directory>
+
+ <Directory Id="ProgramMenuFolder" Name="PMenu" LongName="Programs">
+ <Directory Id="ProgramMenuDir" Name='MLton'/>
+ </Directory>
+
+ <Directory Id="DesktopFolder" Name="Desktop" />
+ </Directory>
+
+ <Feature Id='Complete' Title='MLton' Description='A complete SML and C toolchain.'
+ Display='expand' Level='1' ConfigurableDirectory='INSTALLDIR'>
+ <Feature Id='MinGW' Title='MinGW' Description='The minimalist GNU for Windows C compiler toolchain.' Level='1'>
+ <FeatureRef Id='Runtime'/>
+ <FeatureRef Id='W32API'/>
+ <FeatureRef Id='Binutils'/>
+ <FeatureRef Id='GCC'/>
+ <FeatureRef Id='MSYS'/>
+ </Feature>
+ <FeatureRef Id='MLton'/>
+ </Feature>
+
+ <UIRef Id="WixUI_Mondo" />
+ <UIRef Id="WixUI_ErrorProgressText" />
+ </Product>
+</Wix>
Added: mlton/trunk/package/mingw/msys.bat
===================================================================
--- mlton/trunk/package/mingw/msys.bat 2008-08-24 23:39:00 UTC (rev 6799)
+++ mlton/trunk/package/mingw/msys.bat 2008-08-24 23:46:33 UTC (rev 6800)
@@ -0,0 +1,185 @@
+ at echo off
+rem Copyright (C): 2001, 2002, 2003, 2004, 2005 Earnie Boyd
+rem mailto:earnie at users.sf.net
+rem This file is part of Minimal SYStem
+rem http://www.mingw.org/msys.shtml
+rem
+rem File: msys.bat
+rem Revision: 2.4
+rem Revision Date: December 8th, 2005
+
+rem ember to set the "Start in:" field of the shortcut.
+rem A value similar to C:\msys\1.0\bin is what the "Start in:" field needs
+rem to represent.
+
+rem ember value of GOTO: is used to know recursion has happened.
+if "%1" == "GOTO:" goto %2
+
+if NOT "x%WD%" == "x" set WD=
+
+rem ember command.com only uses the first eight characters of the label.
+goto _WindowsNT
+
+rem ember that we only execute here if we are in command.com.
+:_Windows
+
+if "x%COMSPEC%" == "x" set COMSPEC=command.com
+start /min %COMSPEC% /e:4096 /c %0 GOTO: _Resume %0 %1 %2 %3 %4 %5 %6 %7 %8 %9
+goto EOF
+
+rem ember that we execute here if we recursed.
+:_Resume
+for %%F in (1 2 3) do shift
+if NOT EXIST "%WD%msys-1.0.dll" set WD=.\bin\
+
+rem ember that we get here even in command.com.
+:_WindowsNT
+
+rem Hopefully a temporary workaround for getting MSYS shell to run on x64
+rem (WoW64 cmd prompt sets PROCESSOR_ARCHITECTURE to x86)
+if not "x%PROCESSOR_ARCHITECTURE%" == "xAMD64" goto _NotX64
+set COMSPEC=%WINDIR%\SysWOW64\cmd.exe
+%COMSPEC% /c %0 %1 %2 %3 %4 %5 %6 %7 %8 %9
+goto EOF
+:_NotX64
+
+if NOT EXIST "%WD%msys-1.0.dll" set WD=%~dp0\bin\
+
+rem ember Set up option to use rxvt based on value of %1
+if "x%MSYSCON%" == "x" set MSYSCON=rxvt.exe
+if "x%1" == "x-norxvt" set MSYSCON=sh.exe
+if "x%1" == "x--norxvt" set MSYSCON=sh.exe
+if "x%MSYSCON%" == "xsh.exe" shift
+
+if "x%MSYSTEM%" == "x" set MSYSTEM=MINGW32
+if "%1" == "MINGW32" set MSYSTEM=MINGW32
+if "%1" == "MSYS" set MSYSTEM=MSYS
+
+if NOT "x%DISPLAY%" == "x" set DISPLAY=
+if "x%MSYSCON%" == "xrxvt.exe" goto startrxvt
+if "x%MSYSCON%" == "xsh.exe" goto startsh
+
+:unknowncon
+echo %MSYSCON% is an unknown option for msys.bat.
+pause
+exit 1
+
+:notfound
+echo Cannot find the rxvt.exe or sh.exe binary -- aborting.
+pause
+exit 1
+
+rem If you don't want to use rxvt then rename the file rxvt.exe to something
+rem else. Then sh.exe will be used instead.
+:startrxvt
+if NOT EXIST "%WD%rxvt.exe" goto startsh
+
+rem Setup the default colors for rxvt.
+if "x%MSYSBGCOLOR%" == "x" set MSYSBGCOLOR=White
+if "x%MSYSFGCOLOR%" == "x" set MSYSFGCOLOR=Black
+if "x%MINGW32BGCOLOR%" == "x" set MINGW32BGCOLOR=LightYellow
+if "x%MINGW32FGCOLOR%" == "x" set MINGW32FGCOLOR=Navy
+if "%MSYSTEM%" == "MSYS" set BGCOLOR=%MSYSBGCOLOR%
+if "%MSYSTEM%" == "MSYS" set FGCOLOR=%MSYSFGCOLOR%
+if "%MSYSTEM%" == "MINGW32" set BGCOLOR=%MINGW32BGCOLOR%
+if "%MSYSTEM%" == "MINGW32" set FGCOLOR=%MINGW32FGCOLOR%
+
+start "rxvt" "%WD%rxvt" -backspacekey -sl 2500 -fg %FGCOLOR% -bg %BGCOLOR% -sr -fn Courier-12 -tn msys -geometry 80x25 -e /bin/sh --login -i
+exit
+
+:startsh
+if NOT EXIST "%WD%sh.exe" goto notfound
+start "SH" "%WD%sh" --login -i
+exit
+
+:EOF
+
+rem ChangeLog:
+rem 2002.03.07 Earnie Boyd mailto:earnie at users.sf.net
+rem * Move the @echo off to the top.
+rem * Change the binmode setting to nobinmode.
+rem * Remove the angle brackets around email address to workaround MS
+rem buggy command processor.
+rem
+rem 2002.03.12 Earnie Boyd mailto:earnie at users.sf.net
+rem * Add filter logic to find rxvt.exe
+rem
+rem 2002.03.13 Earnie Boyd mailto:earnie at users.sf.net
+rem * Revert the nobinmode change.
+rem
+rem 2002.03.20 Earnie Boyd mailto:earnie at users.sf.net
+rem * Add logic for stating bash.
+rem
+rem 2002.04.11 Earnie Boyd mailto;earnie at users.sf.net
+rem * Add logic for setting MSYSTEM value based on parameter.
+rem
+rem 2002.04.15 Olivier Gautherot mailto:olivier_gautherot at mentorg.com
+rem * Reduce number test conditions for finding an executable.
+rem
+rem 2002.04.15 Earnie Boyd mailto:earnie at users.sf.net
+rem * Unset DISPLAY if set before starting shell.
+rem
+rem 2002.04.16 Earnie Boyd mailto:earnie at users.sf.net
+rem * Remove use of DEFINED in conditional statments for variables for
+rem command.com support.
+rem * Add check for nonexistance of USERNAME variable for Win9x support.
+rem
+rem 2002.04.17 Earnie Boyd mailto:earnie at users.sf.net
+rem * Add foreground and background color defaults based on MSYSTEM value.
+rem
+rem 2002.04.22 Earnie Boyd mailto:earnie at users.sf.net
+rem * More Win 9x changes.
+rem
+rem 2002.05.04 Earnie Boyd mailto:earnie at users.sf.net
+rem * Remove the SET of USERNAME and HOME.
+rem
+rem 2002.11.18 Earnie Boyd mailto:earnie at users.sf.net
+rem * Add command.com detection and restart with a larger environment to
+rem avoid errors on w9x.
+rem Many thanks to Randy W. Sims mailto:RandyS at ThePierianSpring.org.
+rem See Randy's response to "RE: [Mingw-msys] Installation on WindowsME"
+rem from 11/06/2002 in the archives of mingw-msys at lists.sf.net.
+rem
+rem 2002.11.19 Paul Garceau mailto:pgarceau at attbi.com
+rem * Fix a typo: Change COMPSPEC to COMSPEC.
+rem
+rem 2002.11.25 Earnie Boyd mailto:earnie at users.sf.net
+rem * Remove the SET CYGWIN since it doesn't matter any longer.
+rem
+rem 2003.02.03 Earnie Boyd mailto:earnie at users.sf.net
+rem * Win9x doesn't like ``EXISTS dir'' so change it to ``EXISTS dir\nul''.
+rem Thanks to Nicolas Weber mailto:nicolasweber at gmx.de.
+rem
+rem 2003.03.06 Earnie Boyd mailto:earnie at users.sf.net
+rem * Add -backspacekey switch to rxvt startup.
+rem * Move RXVT color setup to startrxvt label
+rem
+rem 2004.01.30 Earnie Boyd mailto:earnie at users.sf.net
+rem * Add -geometry parameter to work around an off by one issue with
+rem the default values.
+rem Thanks to Dave Schuyler mailto:parameter at users.sf.net
+rem
+rem 2004.03.28 Earnie Boyd mailto:earnie at users.sf.net
+rem * Add -norxvt or --norxvt switch argument.
+rem Thanks to Keith Marshall mailto:Keith.Marshall at total.com.
+rem * Add method to determine absolute path of msys.bat so that we no
+rem longer need to change to the bin directory. This allows msys.bat to be
+rem called from any working directory.
+rem Thanks to Kevin Mack mailto:kevin.mack at us.cd-adapco.com
+rem
+rem 2005.07.06 Max TE Woodbury mailto:mtew at users.sf.net
+rem * Fixed WD check for command.com systems.
+rem * Minimized intermediate CMD window to reduce startup flashyness.
+rem * If rxvt.exe cannot be found, try sh.exe.
+rem
+rem 2005.12.06 Tuomo Latto mailto:nonperson at users.sf.net
+rem * Added a temporary workaround for getting MSYS shell to run on x64.
+rem
+rem 2005.12.07 Keith Marshall mailto:keithmarshall at users.sf.net
+rem * ``EXISTS %WD%\sh.exe'' should be ``EXISTS %WD%sh.exe''; corrected.
+rem * Modified Tuomo's patch, to avoid trashing Window settings in Win32.
+rem
+rem 2005.12.08 Tuomo Latto mailto:nonperson at users.sf.net
+rem * Keith's modified patch fails on x64; start did funny things.
+rem Reworked, for correct behaviour on both platforms.
+rem
More information about the MLton-commit
mailing list