Table of Contents:
To the main page.
Msys stands for Minimal SYStem. It provides an environment to compile and build programs similar to Posix machines (Unix/Linux/BSD). It includes a shell and common Unix utilities such as make, ls, rm, grep, sed, diff and others. Syntax is very similar to a Unix environment. Moving around directories in msys requires commands like cd. Slashes are used in filepaths instead of backslashes (which are used in the DOS/Windows environment).
There are various programs and applications available that require you to build executables and libraries from source code. If you're just running make on a standard makefile in order to create a program, it really doesn't matter much which operating system its done on. However, most makefiles are customized to a particular operating system and compiler. In an attempt to avoid maintaining several makefiles for each platform (operating system and compiler), some projects use the GNU configure system. In order to run programs that are built with the GNU configure system, certain Unix style commands are assumed available on your machine. Msys gives an environment that provides many of these commands. Thus, with msys, you can run
./configure to produce the appropriate makefiles to build your program. The next steps are typically
make and then
You can also use msys to run applications, such as an ssh server or version control tools like msysgit. Since msys provides a Unix like environment, it's sometimes easier to create applications that will work specifically in that environment only rather than try to port them to run stand-alone in Windows.
If you prefer an environment similar to Unix/Linux/BSD, you can use msys for your normal operations. Instead of opening a Command Prompt, Dos Box, etc., just run msys.
You can find msys in the MinGW project at Sourceforge among their files to download along with the rest of the MinGW distribution. For easy installation, look for a file with the name msys, possibly a version number and an extension of .exe. Unfortunately, this may not be the latest version of msys. So, to get latest features, install the executable file, then check for later versions of some of the files with names similar to msysCORE-z.z.z-msys-z.z.z-bin.tar.lzma. (The z values should be replaced with a later msys version number.) You may even be able to skip the executable installation step and just decompress and unarchive the msysCore file. Use utilities such as p7zip, 7za (command line version of p7zip) or MinGW's bsdtar to extract files. This is the minimum you need to update msys, but you'll probably want to update the tools that are used with it as well, such as your bash shell. You'll find latest versions at the MinGW archive at Sourceforge. The file starting with the name msysDTK contains other supplementary tools such as Perl. You may not want to install it if you have your own tools such as Activestate Perl already installed.
I've put together a shell script to automate some of the download process. If anyone's interested, ask on the CppDesign mailing list and I can make a copy available if anyone else needs them. The MinGW developers have created a new installation program mingw-get to simplify the installation process. It doesn't work for me due to issues like firewalls and blocked web sites, but it may work well enough for the average user with a fast Internet connection.
Msys provides its own version of the GNU make program specially compiled for the msys environment and with different functionality than a standard Win32 make port. It's preferred that you use the msys version of make when you need a GNU compatible make program within the msys shell environment. That means you need to keep the standard version of make (named make.exe) out of the directory where the compiler executables are stored and out of the directories in the environment path you set up for msys.
You'll want to run the latest version of msys if at all possible. Msys versions 1.0.10 and earlier had issues which are resolved with later incarnations. Earlier versions assumed all executables in /usr and /usr/bin were linked to the msys dll and that these programs expected paths in the Unix format (with slashes instead of backslashes). Thus, if you put a program like pkg-config in the /usr/bin directory, it wouldn't work properly unless you called it with an alternate path name such as /mingw/msys/usr/bin. Later versions check if the file is linked with msys libraries and if not, try to convert command line parameters from slashes to backslashes. If you need an actual slash on the command line within msys, you'll need to use two slashes in place of one, one as an escape character. Later versions of programs like tar and find are linked with msys and ignore certain actual directories like /usr/bin that they assume should be virtual directories. If you want to use these as real and not virtual directories, you'll need a different version of these programs, such as the gnuwin32 version of findutils or the stand-alone mingw version of bsdtar. The older versions of msys also automatically run rxvt (a terminal emulator) unless you rename the rxvt file so the msys.bat file can't find it. The rxvt program has some issues with input and output that still haven't been resolved. So, if you're running a curses program using rxvt, the screen may not display anything. You can avoid this issue by customizing your msys installation.
You can customize your msys installation in many different ways. You can use different combinations of consoles, terminal emulators or shells. The three most common combinations were using rxvt (the default), using the Command Prompt as a console (without rxvt) and using a third party program such as Console 2 at Sourceforge. You can customize your fstab file to find other directories outside of the msys directory structure on your machine and to use actual subdirectories under /usr not just default to those same virtual directories physically located mabove the /usr directory location. You can also edit your profile and .profile files to set up defaults and customizations for your bash shell.
When calling msys.bat for versions after 1.0.10, you can use the --norxvt option. This avoids certain input/output issues users have had with the rxvt terminal emulator. If you've used the msys executable to install msys, it will create a shortcut for you. You can copy your msys shortcut and add that switch to the properties when invoking msys.bat with the new shortcut. With --norxvt active, you're now using the Windows Command Prompt. By right clicking on the rightmost corner of the window, you can change the properties for it. Customizations include size of window, color scheme, fonts and be sure to check the Edit Options if you want easier cutting and pasting between the Command Prompt and your other programs.
You can add more font options to the Font tab in properties for Windows 2000, Windows NT, Windows XP and certain other versions. The fonts you're adding must meet specific criteria such as being fixed-pitch, not italic, etc. More details are available at the Microsoft support web site. Fonts such as Consolas and DejaVu Sans Mono are useable if you have them installed on your system. To add them, bring up the registry using regedit. Find HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Console\TrueTypeFont. Right click and select New and String Value. Double click new entry and in Edit String dialog, add the name of the font as Value data. The Value name is a string of one or more 0 characters. Whatever the maximum number of 0 characters under the Name column currently is, add another zero to it. In other words, if you already have an entry 0 in the registry and you're adding a new entry for Consolas, the Value name would be 00. To add DejaVu Sans Mono after that, the Value name would be 000. The name of the font (Value data) needs to match a font in the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Fonts section. You'll need to reboot the machine before the change can take full affect. Then, you should be able to see any new font choices in the properties on the Font tab.
You can avoid using the Windows Command Prompt and use an Open Source alternative such as Console 2. This can be done by editing the commands in msys.bat to recognize Console 2 as an option or by running Console 2 directly. If you're setting up Console 2 for MinGW and want to run it directly, you'll need to customize some settings. In Console 2 under Settings dialog, add a Tab name and set the shell for it to C:\mingw\msys\bin\sh.exe --login -i. (Update the directory location to point to your msys\bin directory.) Future versions of msys.bat may add the ability to recognize Console 2 automatically.
If you're using Open Watcom and want to customize Console 2 to run with it, create a Tab name and set the shell for it to C:\watcom\msys\bin\sh.exe -c 'MSYSTEM=WATCOM exec /bin/sh --login -i'. (Update the directory location to point to your msys\bin directory.) You can have two or more installations of msys and use msys for different compilers. Note that MSYSTEM is set to WATCOM in the second example which specifically targets the Open Watcom compiler. This is important.
Whichever method you use to bring up a console and shell to work in, you'll want to make sure that the MSYSTEM environment variable is set properly. The default is MINGW32 (see the profile file), but msys was designed to provide an environment for different systems. So, valid MSYSTEM entries include MINGW32 and MSYS along with whatever custom environment or compiler you wish to create. Open Watcom users can set their MSYSTEM environment variable to WATCOM in order it to target it specifically for their compiler. I've read that MSYSTEM is used by and needed by msys. However, as a user, the only real place I've noticed it make a difference is with the uname command. The command returns the contents of the MSYSTEM variable concatenated with a platform and version (for example _NT-5.1). Some build scripts make use of uname, so you'll want to make sure MSYSTEM is set properly for your environment.
Other files you may want to custom configure when working with msys are fstab, profile and .profile. Files in the etc directory or your local settings files in your home directory need to be in POSIX file format. That means end of line characters should be linefeeds only, not carriage return - linefeed combinations like on Windows and DOS. Be sure your editor can handle files that need to be in this format before editing the files. SciTE, a programming editor, will let you check or change Line End Characters from the Options menu.
Customize the fstab file in the directory where you installed msys under the etc subdirectory. By default msys assumes / and /usr are the same directories. So, when msys looks for files in /usr/bin, it's actually looking in the bin subdirectory underneath the directory where msys was installed. If you want to use the Linux Filesystem Hierarchy Standard or want access to the real directories instead of just the virtual ones, you'll need to remap these drives so that /bin and /usr/bin are not assumed to be the same directory. If you don't care about the standard or don't know what it is, you're better off not remapping the directories under /usr. There can be complications such as programs created for msys (tar, find) not working as expected and not seeing the actual directories. Either way, mind your paths when installing software into these directories. Since msys doesn't naturally follow the Linux FHS standard by default, it can cause issues when using a directory structure from one system and installing packages meant for another. You can install your compiler (MinGW, Watcom, etc.) and msys wherever you'd like on your system. I install the MinGW compiler suite to the \mingw directory, Open Watcom to the \watcom directory and msys to the \mingw\msys directory. If I'm using msys with Open Watcom, I install it to \watcom\msys too. I also remap /usr to follow the FHS standard since I'm doing a lot of cross-platform work. I use an older version of tar such as the one that comes with msys 1.0.10 or MinGW bsdtar and the gnuwin32 version of find so they'll treat the directory system as I expect a program to do on Windows. Here's my current fstab file as an example:
c:/mingw /mingw c:/ActiveState/perl /opt/perl /mingw/msys/usr/bin /usr/bin /mingw/msys/usr/lib /usr/lib /mingw/msys/usr/include /usr/include /mingw/msys/usr/local /usr/local /mingw/msys/usr/sbin /usr/sbin /mingw/msys/usr/share /usr/share /mingw/msys/usr/src /usr/src c:/ /c
If you're using a different compiler you'll want to replace the mingw mapping with one for your compiler. For example, with Open Watcom I use:
After months of trying to get cmake to build in bootstrap mode within msys, one of the things I learned was that certain POSIX based Open Source projects weren't finding resources with names similar to /C/mingw/. It appears not to be an issue if you're cross-compiling or building with Wine. However, for those who are using msys on Windows, it can prevent a program from building. The same technique worked fine when dealing with the compiler (/C/mingw/bin/gcc). I realized you need to explicitly name the path in your /etc/fstab if you want to use it this way. I wish someone else had taken the time to document this as it would have saved me a lot of time and effort with a few of the Open Source projects I've looked at. So, when cmake wanted to find the make program in /C/mingw/msys/bin/make, I needed to add the following to my etc/fstab:
Customize the profile file in the directory where you installed msys under the etc subdirectory. For MinGW, I leave the default settings. However, if you want to add defaults that all users will have, this is the place. For Watcom users, change the MSYSTEM default to WATCOM instead of MINGW32. Change your path so it does not reference the /mingw directories. You may want to point it to the appropriate /watcom directories instead. This is important. If you keep /mingw out of your directory paths with your msys installation for Open Watcom, MinGW and Open Watcom can happily coexist on the same machine. Open Watcom users will not want their scripts to accidentally run gcc instead of owcc.
The .profile file lets you customize bash to a specific user's needs. Create a .profile file in your home directory (same location as the .bash_history file). If for some reason msys does not create a home directory structure, add a home directory within your msys directory. Within the home directory add directories based on your Windows user names for each user who wants to work with msys.My .profile for msys with MinGW contains:
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/pkgconfig:/usr/local/lib/pkgconfig export PATH=$PATH:/usr/bin:/usr/local/bin:/mingw/bin export CFLAGS="-I/include -I/usr/include -I/usr/local/include" export CXXFLAGS="-I/include -I/usr/include -I/usr/local/include" export CPPFLAGS="-I/include -I/usr/include -I/usr/local/include" export LDFLAGS="-L/lib -L/usr/lib -L/usr/local/lib" export PKG_CONFIG="/mingw/msys/usr/bin/pkg-config.exe" export ROOT="/mingw/msys"
You can also add customizations to the bash prompt in this file. Some other flags that might be useful
as CFLAGS, CXXFLAGS and/or CPPFLAGS settings are
-O3 (or another optimization
-mms-bitfields (makes bit storage more compatible with Microsoft
-s (strips a file),
-march=`uname -m` (architecture
-mtune=`uname -m` (machine type to tune for). The ROOT environment variable is used by spkg if you want a package manager program to install, update and uninstall programs and their related files for you. I've also been using it with other applications to make them more portable and not hard-coded to work only in one directory location. I no longer use the LD_RUN_PATH options. This hard-codes the rpath for libraries. It may not be a big issue on Windows, but Debian developers have a long list of reasons to avoid it. I'm exclusively using Nenolod's pkgconf program as a drop-in replacement for pkg-config. It avoids the circular GTK+ library dependencies and the GTK+ libraries.
My .profile for msys with Open Watcom contains:
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/pkgconfig:/usr/local/lib/pkgconfig export PATH=/usr/bin:/usr/local/bin:/watcom/binnt:/watcom/binw:$PATH export INCLUDE=/watcom/h:/watcom/h/nt:/watcom/h/nt:/watcom/h/nt/directx:/watcom/h/nt/ddk export CFLAGS="-I/include -I/usr/include -I/usr/local/include -I/watcom/h -I/watcom/h/nt -I/watcom/h/nt" export CXXFLAGS="-I/include -I/usr/include -I/usr/local/include -I/watcom/h -I/watcom/h/nt -I/watcom/h/nt" export CPPFLAGS="-I/include -I/usr/include -I/usr/local/include -I/watcom/h -I/watcom/h/nt -I/watcom/h/nt" export LDFLAGS="-L/lib -L/usr/lib -L/usr/local/lib -L/watcom/lib386 -L/watcom/lib386/nt" export PKG_CONFIG="/watcom/msys/usr/bin/pkg-config.exe" export ROOT="/watcom/msys" export WATCOM="c:/WATCOM" export CC=owcc export CXX=owcc export LD=owcc export CL=cl export AR=wlib export STRIP=wstrip export LIB="/watcom/lib386:/watcom/lib386/nt" export RC=wrc
All the environment information typically added by owsetenv.bat can be added to your .profile file (or to the profile file in etc for everyone's use). I've also added a lot of environment variables to help configure and make find the right compiler tools (such as owcc instead of gcc).
To the main page.