Skip to content

Instantly share code, notes, and snippets.

@tfwio
Last active August 29, 2015 14:10
Show Gist options
  • Save tfwio/dd484dd4e1e177ec1dd1 to your computer and use it in GitHub Desktop.
Save tfwio/dd484dd4e1e177ec1dd1 to your computer and use it in GitHub Desktop.
MSYS HELPER DRAFT

DRAFT

MSYS QUICK START GUIDE

Until some better instruction is elaborated, I hope this might lay some tasty bread-crumbs down to help one(s) getting started with MSYS. There are other ways (I do like msys2) and other manuals/tutorials however this would be a quick overview of my favorite, basic setup.


MSYS is a command-line environment that emulates a posix-like GNU/GCC AUTOTOOLS compatible (or 'like') system for windows to use MinGW (Minimalist GNU for Windows)---bringing GCC (Gnu Compiler Collection) and AUTOTOOLS (and friends) to Windows.


Following is a quick-start tutorial on getting MSYS up and running with some version of mingw-w64.

  • view/save github-gist version of the Multi-Markdown version of this document here
  1. DOWNLOAD MSYS the most recent: msys+7za+wget+svn+git+mercurial+cvs-rev13.7z from the following link
  2. ...and extract (you're going to need 7zip) to a MSYS directory — Extract it somewhere like c:/MSYS or c:/dev/bin/msys or some short path WITH NO SPACES so that it is 'posix-like' or compatible-ish. We'll call this DIR_MSYS.
  3. Now you pretty-much just need your flavor of MinGW... But before we get to that... we should grab a copy of MSYS-POST-INSTALL UTILS. I've copied the post-install utils from the older/original MinGW/MSYS (at least I think they're still the originals) to the following gist. There are three files. Two of them are originals or at least pi.sh should be. I created a little hack called
  4. DOWNLOAD MinGW.
    • eventually called DIR_MINGW herein...
    • (a little about mingw/mingw-w64) I prefer mignw-w64's builds and the most recent (to date) version 4.9.2 so that I can catch up on learning newer implementations of C++11 and C++14 standards when I find the time (among other reasons). If this is your first time downloading MinGW---go with 32bit/x86---and don't blame me if you blow up your computer!!!
    • http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/4.9.2
    • ^^ I would download a POSIX/DWARF configuration.
    • Posix is the threading model and DWARF is the type of error handling
    • It would help to look into differences between DWARF (DW2), SJLJ and SEH some day. That is, there are POSIX vs WIN32 threading models and SJLJ, DWARF (or DW2) and SEH (mostly in x64 releases) error handling mechanics to choose from.
    • in the 7zip file should be a mingw32 directory. If you went with x64, then you have within the archive mingw64.
    • The quick and easy thing to do would be to extract to DIR_MSYS, but since I've got bunches of different mingw-w64, TDM-MinGW and other MinGW-related stuff, I put them all in d:/dev/bin/mingw and rename the mingw32 directory to the name of the 7z-archive it came in.
    • It does not really matter where you put it so long as you follow a couple rules
      • try to keep the path as short as possible if you can.
      • DO NOT USE SPACES
      • You might also want to look into your windows ENVIRONMENT PATH to see if there are things that break the DON'T USE SPACES in your paths rule---or this might annoy you down the line.
      • you can use old dos-compatible names like c:/progra~1/program/... and test them in windows shell (cmd.exe) if you want to fix anything with spaces that's important.
      • on my 64bit version of Windows 7 c:\progra~2\Git\bin would point to c:\program files (x86)\Git\bin. c:\progra~1\Git\bin points to c:\program files\Git\bin.
    • WERE ALMOST THERE ;)
  5. LOAD UP MSYS
    • the MSYS download I linked to has DIR_MSYS/bin/mintty.exe in there. Either double-click on DIR_MSYS/msys.bat and skip through to step #6, or learn how to get Mintty going (you want mintty).
    • I create a DIR_MSYS/load-mintty.bat (or whatever you name it---actually I made a shortcut to my desktop come to think of it)---and type the following into the batch command in notepad or your favorite text editor (like Sublime-text).
    • msys.bat -mintty
    • better yet: %~dp0msys.bat -mintty if the above gives you problems.
    • FYI: %~dp0 would point to the [drive-letter]: + [path-to-script] or resolve something like c:\msys\ if the executing script is in your msys dir.
    • For example, %~dpnx0 in windows command-shell (batch-script) would resolve the full path of the executing batch-script: c:\msys\load-mintty.bat.
    • it better be loaded now ;)
    • if you want to add things to your ENVIRONMENT PATH (before the call loading msys.bat), the batch-file we just created would make a good place for that.
    • Say you want to add GIT/bin (I believe this version of MSYS may over-ride your version of git---which means you may not actually want to manually add GIT to your path unless it doesn't work for you for some reason unknown to me) to your path you would add something like the following to the beginning to your MSYS or MINTTY loader script:
    • SET PATH=c:\progra~2\Git\bin;%PATH%
    • If you intend to use GIT, Tortoise GIT is also good to have around.
  6. Run the POST-INSTALL --- this makes MSYS aware of your version of MinGW. I've provided two options here---there may be others elsewhere...

THE POSTINSTALL SCRIPT(s)

Either of these two options will do generally the same thing. It will ask you to type your mingw-path, and 'mount' it to your MSYS, and if you typed in a valid DIR_MINGW, then it should report success.

Once you run the postinstall your MSYS is good to go until you decide you would like to run it again and supply a different version of MINGW. I like my hack better because its quicker and ready to be called from a script (I'll get it (them?) up here some-day).

Before proceeding from this point you should have:

  1. a 'DIR_MSYS' directory: c:\MSYS c:\dev\bin\MSYS or wherever you extracted MSYS.
  2. you must have placed the postinstall script(s) into a "postinstall" directory you created after extracting MSYS: MSYS_DIR\postinstall.
  3. a 'DIR_MINGW' directory: something like c:\mingw32, c:\mingw64 or c:\dev\bin\mingw\my-version-of-mingw or perhaps even DIR_MSYS\mingw32.

after running postinstall check to see that everything is available... I think the (MSYS) distro up there has a working git in it so you might want to check if it works before downloading and adding to your path.

gcc --version
git --version

MINGW/MSYS's POSTINSTALL SCRIPT

Note how I completely ignored its instructions ;)

came with MinGW's MSYS (mingw.org).

Run the postinstall script in bash. Following its direction should land you a configured MSYS prepared todo some gcc, g++, make, etc...

when typing the mingw-directory path for these scripts, use a windows style path name with these slashes "/", not these: "\" (where-ever you put it).

EG: c:/dev/bin/mingw-dists/mingw32-vN.N.N-etc

# say your DIR_MSYS is '/c/dev/bin/msys'
# we 'could' set a variable for reference (not that we need to)
DIR_MSYS=/c/dev/bin/msys

or simply to do the same

#execute the post-install bash/shell script
/postinstall/pi.sh

MY POSTINSTALL HACK

This is merely my alternative script; a hack of the above script. If you're not sure which one to use (compared to the above), just use the above one and if you want to try this later then so be it.

  • The version I provided is a part of a larger script (its shy at the moment).
  • if you extracted mingw into your DIR_MSYS, then you can do something like:
# if msys is in c:msys
DIR_MSYS=/c/msys
# and mingw32 is in c:mingw-versionsmingw32
DIR_MINGW=/c/mingw-versions/mingw

# call my little post-install-script hack
# - use windows-style path when sending it to this
# post-install script with forward-slashes '/'.
$DIR_MSYS/postinstall/pi c:/mingw-versions/mingw32
# it should report success

ADDITIONAL RESOURCES

Next page has general bash usage tips...

This NOT a tutorial on using MSYS or BASH

Just some tips for getting started ;)

There are lists and documents worth of caveats I'm skipping here but in MSYS, many things are different compared to a Windows shell that you can find on official GNU texts and documentations --let alone the various tools and libraries out there. The first thing you will probably learn is that paths in 'bash', or posix-like shells like MSYS and CYGWIN are like...

A LITTLE ADVISE (some useful help/commands)

  • As hard as it may be, stick to reading and re-reading if necessary: official source-documentation and source code to learn---and check the dates and VERSIONS of EVERYTHING you read to learn.
  • Get intimate with your SYSTEM ENVIRONMENT VARIABLES if you are not.
  • I used to add a environment variable to my batch scripts that loaded MSYS setting PFIX to correspond to the version (x86_64-w64-mingw32 vs i686-w64-mingw32) but that may not be necessary depending on what you choose to prefer: SET PFIX=x86_64-w64-mingw32 for a x64 compiler and SET PFIX=i686-w64-mingw32 for the x86/32bit---generally I've dropped doing this lately as I'm more comfortable with AUTOTOOLS AUTOCONFIG files and Makefiles.

GCC and G++ (many things to learn from)

  • gcc --help or the various help categories gcc --help=common, gcc --help=common
  • gcc --version
  • gcc -v (is different result then --version)
  • gcc -dumpversion
  • gcc -dumpspecs
  • gcc -dumpmachine

BASH or SH scripting

  • typing HELP will list available commands that is your native shell toolbox in MSYS.
  • ls /bin/*.exe --- shows you all the exe files in the bin directory.
  • ls --help
  • help sh --- sh is a way like windows command.exe
  • the best way to learn shell scripting is to read shell scripts.
  • check out /etc/inputrc in your text-editor.
  • this will load explorer from the etc directory: cd /etc ; explorer .

BASH scripting is powerful

  • echo $(( 1 + 2 ))
  • arrays are interesting once you know how to leverage them.
  • you will find plenty of tutorials on-line for this to poke around in your spare time if you're inclined ;)
  • sublime-text has packages to make batch-scripting easier (if not built in)---just sayin.
  • AUTOTOOLS and PACKAGECONFIG are your friends---but you have to make friends with them. I'll either post some more helpers or perhaps just on the package-config tool (one might argue against package-config but not me)---or at least some snippets when I find the time... Especially if you like taking advantage of (compiling) FFmpeg, or understanding things under the hood of other popular GNU things like Gimp and lots of other things.
  • How I learned AUTOTOOLS quickly was by writing my first AUTOTOOLS/PACKAGECONFIG compatible sources (and linking to a source-built libFLAC, libsndfile and others). It took for ever to figure out PACKAGECONFIG because I was reading out of date materials and didn't realize it until grinding the plentiful GNU documentation.

From here, you might become interested in the vast number of libraries compatible with GCC (ported to MinGW and/or mingw-w64) tool-chains.

MSYS BASH vs WINDOWS CMD

DIRECTORY PATHS IN MSYS/SH/BASH vs WINDOOWS/COMMAND/CMD SHELL

  • BASH: /c/dev/msys/
  • WIN: c:\dev\msys\

Clear screen

  • BASH: KeyboardKeys (combo) CTRL+L
  • typing cls+ENTER (like in windows shell) works in the MSYS package listed above.
  • WIN: type cls+ENTER

CANCEL/EXIT RUNNING OPERATION

  • KeyboardKeys: CTRL+C

WINDOWS ENVIRONMENT PATH vs BASH ENVIRONMENT PATH

SHOW ALL ENVIRONMENT VARIABLES IN WINDOWS

SET

SHOW ALL ENVIRONMENT VARIABLES IN BASH

export

In Windows shell, multiple paths are separated by a semicolon, ';'.

:: show windows path
SET PATH

Will output something like:

Path=C:\Program Files (x86)\Git\bin;.;C:\PROGRA~2\nodejs\;C:\Windows\system32\inetsrv;C:\PROGRA~2\Common Files\Intel\Shared Files\cpp\bin\Intel64;C:\PROGRA~2\cvsnt;c:\windows;c:\windows\syswow64;C:\PROGRA~2\Microsoft SQL Server\90\Tools\binn\;C:\PROGRA~1\Microsoft SQL Server\110\Tools\Binn\;C:\PROGRA~2\QuickTime\QTSystem\;C:\PROGRA~1\TortoiseGit\bin;C:\PROGRA~1\TortoiseSVN\bin;C:\Program Files\Calibre2\;D:\dev\bin\Vagrant\bin;C:\Program Files\TortoiseGit\bin;

^ Notice that windows has adopted (or can use) paths with spaces in them.

In bash shell, multiple paths — a colon ':'.

echo $PATH

Will output something like:

.:/usr/local/bin:/mingw/bin:/bin:/d/dev/bin/MiKeTeX/miktex/bin:/c/PROGRA~2/NODEJS:/c/Users/oio/AppData/Roaming/NPM:/c/Users/oio/AppData/Roaming/NPM-CACHE:/d/dev/bin/ATOM:/d/dev/bin/GO/bin:/d/dev/bin/cmake-3.0.2-win32-x86/bin:/d/dev/bin/jdk1.7.0_02/bin:/d/dev/bin/apache-ant-1.8.2/bin:/d/dev/bin/python278:/d/dev/bin/python278/SCRIPTS:/d/dev/bin/pandoc

^note that there I didn't allow any spaces to invade my MSYS path.

Do as you prefer, however I have chosen to manually replace/rewrite the PATH variable depending on what I expect to be doing in a particular MSYS configuration. Many of the tools (both in Windows as well as GNU) act on various environment variables such as GCC compilers, Python, the list goes on...

TO SET/MODIFY SHELL VARIABLES

In both bash and windows-shell, there are global and local environments, and environment variables depending on a context defined by/with the level of scripting.

  • In Windows, once a variable is defined, you reference a variable with surrounding it in percent-symbols: %MYVAR%
  • In bash, once a variable is defined, it would be referenced with a dollar-symbol: $MYVAR

In Windows, you use the SET command.

SET MYVAR=myvalue

:: to modify the PATH for the command-session
SET PATH=C:/stuff/added/bin;%PATH%

In Bash

MYVAR=myvalue

# to modify the PATH for the bash-session
PATH=/c/stuff/added/bin:$PATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment