Skip to content

Instantly share code, notes, and snippets.

@tfwio
Last active December 23, 2015 18:49
Show Gist options
  • Save tfwio/6678113 to your computer and use it in GitHub Desktop.
Save tfwio/6678113 to your computer and use it in GitHub Desktop.
MSYS postinstall configuration for using or switching between many different MinGW configurations. Eventually I hope to automate this guy among other things.

Switch between different mingw distributions using a single msys-bin—as opposed to storing various copies of msys for each mingw distro.

Is a work in progress. If something is broken or you have any questions or suggestions, please let me know by way of a comment.

This is a personal configuration for hacking. I do recommend recreating this environment on your system if you haven't one already, however there are a few more advanced tool-chains out there (which I'm working on figuring out in my spare time).

Suggested elements for such a configuration (marked with 'configure') demonstrated. The rest are automatically a part of the msys+ download.

  • Atom (configure)
  • Git
  • Go (configure)
  • Java-JDK/Ant (configure)
  • Mercurial
  • MiKeTeX (configure)
  • MinGW-64 & Mingw-Builds (configure)
  • NodeJS
  • Python (configure)
  • Ruby/Rails (configure)

HOW

INSTALL

  • Create postinstall directory in your msys path if it doesn't exist
  • Copy the two scripts into this directory
  • Update/hack and test out the windows command script

EDIT

Currently this is something that you should do manually, becuase it is the fastest way to get what you want when you want it.

There are two things that you would need to do in order to use this...

  1. SET UP YOUR PATH
  2. SET UP YOUR MINGW DISTROS

1.) SETTING UP YOUR PATH (ENVIRONMENT)

I provided my configuration because it would be a good thing for a programming enthusiast to have such a wonderful set of tools at their finger-tips. I wish I had a configuration like this ten years ago. So all of my configuration is in there and it will grow as my configuration grows.

All of the PATH settings are injected into a batch file ridiculously named mingw.bat. See the script part named :ADDTOPATH.

:ADDTOPATH
	ECHO SET PATH=.;%MRT%
	ECHO SET PYTHONHOME=%PY%>>mingw.bat
	ECHO SET PYTHONPATH=%PY%\lib>>mingw.bat
	ECHO SET JAVA_HOME=%JH%>>mingw.bat
	ECHO SET GOROOT=%GOROOT%>>mingw.bat
	ECHO SET GOPATH=%GOPATH%>>mingw.bat
	ECHO SET PATH=%PATH%>>mingw.bat
	GOTO:EOF

2.) ADDING A MINGW DISTRO TO THE SCRIPT

It is important to understand the ENVIRONMENT %PATH% you are dealing with, so the semantics of this script entirely re-build the %PATH% to simplify build related configurations (bringing them to one place)—that way all environment related issues are in one place.

In the batch-command-script pi-set.bat, there are three parts we would add to or remove from.

All the following three edits take place in the :BEGIN section.

  1. This is numbered 1 to whatever.
  2. Assign the %choice% in a conditional if command.
  3. Next you update the if %choice% GEQ [a-number-goes-here] GOTO:BEGIN to an appropriate numeric. If you have choices one throuh twelve, you would use 13 for this value.

Why?

I downloaded msys+7za+wget+svn+git+mercurial+cvs-rev12.7z and was trying to figure out how to configure that particular MSYS bin to any of the few versions of MinGW I have laying around my PC.

Running pi-set.cmd will reconfigure your msys 'mount' of whatever mingw version intended (or specified).

WHEN IN DOUBT

I've run into a few scenarios when switching between different MinGW configurations. These are rare scenarios when build building large projects such as FFmpeg.

BE SURE NO MSYS SCRIPTS ARE HANGING WHEN YOU EXECUTE THIS SCRIPT—This is particularly useful if you have attempted to compile something HUGE like ffmpeg or something like, or if you break out of a build that is hanging for some reason. This is not by any means a typical or common problem. You can identify them in process manager under a running conhost.exe in windows 7 or more likely in a running sh.exe executing any script that might be locked.

Also (if in doubt), be sure that if you change the mingw-bin while another console-window is open, the compiler you're targeting checks out (is working properly) by executing the mingw executable you're targeting for version-information. (EG: gcc.exe -version)

MERCURIAL ISSUE

THE ERROR is caused when you don't have a python environment in the same location as it is configured for mercurial. If you intend to use Golang, you are going to need Hg.exe functional.

To solve this issue, rename your ./bin/hg.exe to something like hg.exe.bak or something, unless you would like to delete it, install tortoise mercurial, and add it to your batch-script's PATH.

$ hg --version
Traceback (most recent call last):
  File "c:\Python26\lib\site-packages\py2exe\boot_common.py", line 92, in <module>
ImportError: No module named linecache
Traceback (most recent call last):
  File "&lt;install zipextimporter>", line 1, in &lt;module>
ImportError: No module named zipextimporter
Traceback (most recent call last):
  File "hg", line 10, in &lt;module>
ImportError: No module named os

GIST

https://gist.github.com/tfwio/6678113

:: This can be used as a command script where you can run a single command to bash
:: For example:
:: %pathtothisscript% "cd ~/dev/myproject/ && ./runmyscript.sh "
:: set the current drive to that of mdo.bat
@%~d0
:: set the current path to that of mdo.bat
@cd %~dp0
:: overwrite the path
@call mingw.bat
:: go back to MSYS-directory
@cd ..
:: Execute
@bin\bash -ilc %1
:: pathcfg.bat
:: ==================================
:: use this file to overwrite your path
:: Keep in mind that MSYS inherits most of your environment settings
:: so here, I'm customizing for a complete override of the PATH.
:: Special note on %MINGWBASE%
:: ----------------------------
:: This is the base location where several
:: "%MINGWBASE%/%mingw-v.n.n/" directories reside
:: for each version of mingw taylored in to this script.
SET REMEMBER=%*
SET OUTPUT=mingw.bat
:: EMPTY THE PATH
SET PATH=.;
SET PANDOC=d:\dev\bin\pandoc
:: BASE DEVELOPMENT PATH CONFIGUTATION
:: - c:\dev, c:\dev\bin
SET DEVBIN=d:\dev\bin
SET MINGWBASE=%DEVBIN%\mingw
:: FIX MERCURIAL
:: BE SURE TO REMOVE MERCURIAL FROM THE BIN IF YOU SO CHOOSE.
SET MC_HOME=C:\progra~1\Mercurial
:: JAVA_HOME, ANT --- integrates into 'dev' section
SET JH=%DEVBIN%\jdk1.7.0_02
SET ANTP=%DEVBIN%\apache-ant-1.8.2\bin
:: DEV UTILS
SET CMAKE_HOME=%DEVBIN%\CMake 2.8
SET MRJ=%JH%\bin
:: PERL
SET PERL_HOME=%DEVBIN%\strawberry-perl-5.20.0.1
:: note: this is x86_64-w64-gcc
:: %PERL_C%
:: where is this used within perl?
:: is there a package-manager like ruby?
:: will it be the source of ruby conflicts?
:: SET PERL_C=%PERL_HOME%\c\bin
SET PERL_S=%PERL_HOME%\perl\site\bin
SET PERL_B=%PERL_HOME%\perl\bin
SET PERL_BIN=%PERL_S%;%PERL_B%
:: CPYTHON
SET PY=%DEVBIN%\python278
SET PYS=%PY%\SCRIPTS
:: 'python --help' for more info on the following.
:: PYTHONSTARTUP:PYTHONPATH:PYTHONHOME
:: PYTHONCASEOK:PYTHONIOENCODING:PYTHONHASHSEED
:: DEF
:: FRINGE
SET MIKTEX_HOME=%DEVBIN%\MiKeTeX\miktex
:: DEF
SET FRINGE=%MIKTEX_HOME%\bin
:: RED
::https://github.com/slogsdon/b
SET GOROOT=%DEVBIN%\GO
SET GOPATH=D:\DEV\WWW\LIB\GO
::
SET ATOM=%DEVBIN%\ATOM
SET NODE_HOME=C:\PROGRA~2\NODEJS
SET NPM_HOME=%APPDATA%\NPM;%APPDATA%\NPM-CACHE
SET RUBY200_HOME=%DEVBIN%\ruby-2.0.0-P481-I386-mingw32
:: DEF
SET RED=%NODE_HOME%;%NPM_HOME%;%RUBY200_HOME%\bin;%ATOM%;%GOROOT%\bin
SET DEV=%CMAKE_HOME%\bin;%MRJ%;%ANTP%;%PY%;%PYS%;%MC_HOME%;%PERL_BIN%
:: PATH (FULL REPLACEMENT)
:: - Note: No MSVC here.
SET MRT=%FRINGE%;%RED%;%DEV%;%PANDOC%
::;c:\progra~1\calibre2
SET PATH=%MRT%
@echo off
CALL pathcfg.bat
SET UPDATE=0
CALL:BEGIN
:: IF ENTER IS PRESSED WITHIN BEGIN
:: THE FOLLOWING ISNOT EXECUTED
CALL:RIP %*
GOTO:EOF
:ADDTOPATH
ECHO @SET PATH=.;%MRT%
ECHO @SET PYTHONHOME=%PY%>>%OUTPUT%
ECHO @SET PYTHONIOENCODING=utf-8>>%OUTPUT%
ECHO @SET PYTHONPATH=%PY%\lib>>%OUTPUT%
ECHO @SET JAVA_HOME=%JH%>>%OUTPUT%
ECHO @SET GOROOT=%GOROOT%>>%OUTPUT%
ECHO @SET GOPATH=%GOPATH%>>%OUTPUT%
ECHO @SET PATH=%PATH%>>%OUTPUT%
GOTO:EOF
:BEGIN
CLS
TITLE MSYS Configurator
ECHO.
ECHO MSYS Configuration Selector
ECHO =====================================
ECHO Select MinGW Distribution
ECHO -------------------------------------
ECHO 1 x86t-x64h-rubenvb
ECHO 2 i686-w64-mingw32-4.7.4-rubenv-win64
ECHO 3 i686-w64-mingw32-4.8.0-dwarf-twin32
ECHO 4 i686-w64-mingw32-gcc-dw2-4.8.0-win32_rubenvb
ECHO 5 i686-w64-mingw32-win32-gcc-4.6.3-2
ECHO 6 mingw32tdm-4.7.1-twin32
ECHO 7 mingw32-x86t-dwarf-tposix
ECHO 8 x86_64-w64-mingw32-4.8.1-release-posix-seh-rev5.7
ECHO 9 x86_64-w64-mingw32-tdm-4.7.1-twin32
ECHO 10 x86t-x32h-rubenvb
ECHO 11 x86t-x64h-rubenvb
ECHO 12 win-builds-i686-w64-mingw32-4.8.2
ECHO 13 win-builds-x86_64-w64-mingw32-4.8.2
ECHO 14 i686-4.9.1-release-posix-dwarf-rt_v3-rev1
ECHO 15: RUBY: i686-w64-mingw32-4.7.6-win32threads
ECHO.
IF EXIST %OUTPUT% (
ECHO -------------------------------------
ECHO.
ECHO r: to clear mingw variable
ECHO ^<ENTER^> skip and load MSYS using the following MinGW path
ECHO.
ECHO -------------------------------------
ECHO.
call TYPE "..\etc\fstab"
ECHO.
)
ECHO =====================================
ECHO.
ECHO * This MSYS distro has GIT in its path.
ECHO * Future versions of this script will incorporate
ECHO more $PATH variables as we have need for them.
ECHO.
SET /p choice=
:: alphabeta
if "%choice%" == "r" GOTO:RSET
if "%choice%" == "R" GOTO:RSET
if "%choice%" == "" GOTO:RIP %*
:: numerics
if %choice% LEQ 0 GOTO:BEGIN
if %choice% GEQ 15 GOTO:BEGIN
if %choice% == 1 CALL:WriteUpdate i686-w64-mingw32-4.7.2-rubenv-twin32 i686-w64-mingw32
if %choice% == 2 CALL:WriteUpdate i686-w64-mingw32-4.7.4-rubenv-win64 i686-w64-mingw32
if %choice% == 3 CALL:WriteUpdate i686-w64-mingw32-4.8.0-dwarf-twin32 i686-w64-mingw32
if %choice% == 4 CALL:WriteUpdate i686-w64-mingw32-gcc-dw2-4.8.0-win32_rubenvb i686-w64-mingw32
if %choice% == 5 CALL:WriteUpdate i686-w64-mingw32-win32-gcc-4.6.3-2 i686-w64-mingw32
if %choice% == 6 CALL:WriteUpdate mingw32tdm-4.7.1-twin32 mingw32
if %choice% == 7 CALL:WriteUpdate mingw32-x86t-dwarf-tposix i686-w64-mingw32
if %choice% == 8 CALL:WriteUpdate x86_64-w64-mingw32-4.8.1-release-posix-seh-rev5.7 x86_64-w64-mingw32
if %choice% == 9 CALL:WriteUpdate x86_64-w64-mingw32-tdm-4.7.1-twin32 x86_64-w64-mingw32
if %choice% == 10 CALL:WriteUpdate x86t-x32h-rubenvb i686-w64-mingw32
if %choice% == 11 CALL:WriteUpdate x86t-x64h-rubenvb i686-w64-mingw32
if %choice% == 12 CALL:WriteUpdate win-builds-32 x86_64-w64-mingw32
if %choice% == 13 CALL:WriteUpdate win-builds-64 x86_64-w64-mingw32
if %choice% == 14 CALL:WriteUpdate i686-4.9.1-release-posix-dwarf-rt_v3-rev1 i686-w64-mingw32
if %choice% == 15 CALL:WriteUpdate railsdevkit-rubenv-i686-w64-mingw32-4.7.6
CALL:ADDTOPATH
GOTO:EOF
:RIP
if NOT EXIST %OUTPUT% GOTO:BEGIN
CALL:CHECK
CALL:LOADMINGW
CALL:FIN
SET PATH=%MRT%
CALL ..\msys.bat %REMEMBER%
EXIT
:RSET
DEL %OUTPUT%
GOTO:BEGIN
:CHECK
IF NOT ERRORLEVEL 0 GOTO:BEGIN ELSE SET ERRORLEVEL=0
ECHO NO MORE ERROR
GOTO:EOF
:WriteUpdate
CLS
ECHO @SET MUCK=%MINGWBASE%\%1>%OUTPUT%
ECHO @SET INCLUDE=%MINGWBASE%\%1\include;%MINGWBASE%\%1\include>>%OUTPUT%
ECHO @SET LIB=%MINGWBASE%\%1\include;%MINGWBASE%\%1\lib>>%OUTPUT%
IF "%2" NEQ "" ECHO @SET PFIX=%2>>%OUTPUT%
SET UPDATE=1
GOTO:EOF
:LOADMINGW
CALL %OUTPUT%
GOTO:EOF
:FIN
set PATH=
IF "%UPDATE%" == "1" ..\bin\sh.exe pi-set.sh
:: LOG 20140908
:: - Consolidation in the addition of :ADDTOPATH
:: param1: MinGW Folder-Name (based on %MINGWBASE%)
:: param2: (optional) PFIX
:: LOG 20140902 --- ADDED
:: - Added ATOM
:: - PATH section-groups: DEV, FRINGE, RED
::
:: LOG 20140827 --- ADDING RUBY
:: ----------------------------------------------------------------
:: - large abstraction/consolidation
:: ^ Now we are using SET `MRT` VARIABLE to override the path.
:: ^ All PATH modifiaction (with exception to MinGW/%MUCK% has been
:: abstracted to these first lines here where we build up variables
:: to merge them in SET MRT=...
:: ^ Note that the PATH variable is completely re-written.
:: - Took special care to rename any 'Program Files (x86)`
:: or any variables with spaces to friendly "C:/PROGRA~1" (names)
:: ----------------------------------------------------------------
# Copyright (C) Earnie Boyd <[email protected]>
# This file is a part of msysDVLPR.
# http://www.mingw.org/msysdvlpr.shmtl
#
echo
echo "This is a post install process that will try to normalize between"
echo "your MinGW install if any as well as your previous MSYS installs "
echo "if any. I don't have any traps as aborts will not hurt anything."
echo -n "Do you wish to continue with the post install? [yn ] "; read ans
if [ $ans == 'n' ]; then exit 1; fi
. /etc/profile
echo
echo -n "Do you have MinGW installed? [yn ] "; read ans
if [ $ans == y ]
then
echo
echo "Please answer the following in the form of c:/foo/bar."
echo -n "Where is your MinGW installation? "; read ans
if [ -f $ans/bin/gcc.exe ]
then
mingwpath=$ans
else
mingwpath=
fi
if [ -z "$mingwpath" ]
then
echo
echo I could not find $ans/bin/gcc.exe. You must have given an invalid
echo path to your MinGW environment. I am reversing to no MinGW
echo installation. If you do have MinGW installed then you can manually
echo bind the mount point /mingw to C:/mingw '('replace C: with the
echo drive of your choice')' by creating an /etc/fstab file with a line
echo that has a value similar to:
echo C:/mingw /mingw
echo -n Press ENTER to continue; read ans
fi
else
mingwpath=
echo
echo "When you install MinGW I suggest you install it to C:/mingw"
echo '(replace C: with the drive of your choice). Then create an'
echo '/etc/fstab file with a line that has a value similar to:'
echo 'C:/mingw /mingw'
echo -n 'Press ENTER to continue '; read ans
fi
if [ ! -z "$mingwpath" ]
then
if [ -f /etc/fstab ]
then
echo
echo "I see that you already have an /etc/fstab file. Do you wish for me"
echo -n "to add mount bindings for $mingwpath to /mingw? [yn ]"; read ans
if [ $ans == 'y' ]
then
cat <<EOF>>/etc/fstab
$mingwpath /mingw
EOF
fi
else
echo
echo -n "Creating /etc/fstab with mingw mount bindings."
cat <<EOF>/etc/fstab
$mingwpath /mingw
EOF
fi
fi
echo
echo " Normalizing your MSYS environment."
echo
for I in cmd rvi vi
do
if [ -f /bin/$I. ]
then
echo You have script /bin/$I
if [ -f /bin/$I.exe ]
then
echo Removing /bin/$I.exe
rm -f /bin/$I.exe
fi
fi
done
for I in ftp ln make awk echo egrep fgrep printf pwd ex rview rvim view
do
if [ -f /bin/$I.exe ] && [ -f /bin/$I. ]
then
echo You have both /bin/$I.exe and /bin/$I.
echo Removing /bin/$I.
rm -f /bin/$I.
fi
done
if [ -z "$mingwpath" ]
then
echo
echo MinGW-1.1 has a version of make.exe within it\'s bin/ directory.
echo Please be sure to rename this file to mingw32-make.exe once you've
echo installed MinGW-1.1 because it\'s very deficient in function.
echo -n Press ENTER to continue. ; read ans
else
if [ -f $mingwpath/bin/make.exe ]
then
echo
echo Renaming $mingwpath/bin/make.exe to mingw32-make.exe.
mv $mingwpath/bin/make.exe $mingwpath/bin/mingw32-make.exe
else
echo
echo Oh joy, you do not have $mingwpath/bin/make.exe. Keep it that way.
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment