配置MSYS make-in-a-shell on Windows

Original From:http://www.redantigua.com/msys-win.html

 

MSYS - make-in-a-shell on Windows
MSYS (Minimal SYStem) is an shell environment where you can run configure scripts and use the make tool.
A make tool is included in both MinGW (mingw32-make) and UnxUtils (make), but they cannot be executed correctly within a DOS prompt, but needs a proper environment.
This is where MSYS comes to help.
Running MSYS is similar to open a UNIX xterm window.
MSYS also includes its own make tool.

Homepage: http://www.mingw.org/msys.shtml
Download: http://www.mingw.org/download.shtml

Install
First, install MinGW.
Then, start the MSYS Installer as for any other Windows program.
Choose the default option whenever you asked to.
In the post-install session (a DOS prompt), you will be asked if MinGW is installed.
Type 'y' on all questions.
To run a MSYS shell, just click the MSYS desktop icon (created by default).

Configure (optional)
To run MSYS there is really no configuration needed.
MSYS is installed by default in the folder C:/MSYS/1.0, and binaries will be found in C:/MSYS/1.0/bin.
There is no need to add this path to the PATH Environment variable.
Let's assume you are logged in on Windows as user me:
$ pwd
/home/me
Just like in a UNIX shell session, the default directory is your home directory.

Using make and gcc
Check out the paths to the tools:
$ which gcc
/mingw/bin/gcc
MSYS uses its own make by default:
$ which make
/bin/make
If you want to use MinGW's make instead, you have to use its special name:
$ which mingw32-make
/mingw/bin/mingw32-make
And if you want want to use UnxUtils's make, you have to use its full path:
$ /c/unxutils/usr/local/wbin/make
Comparing make versions (additional info omitted):
$ /bin/make --version
GNU Make version 3.79.1
$ /mingw/bin/mingw32-make --version
GNU Make 3.81
$ /c/unxutils/usr/local/wbin/make --version
GNU Make version 3.78.1

We see that MinWG's make is the most recent version (this may not always be true).
It may be tempting to use the most recent version of make, but the MSYS version is the recommended version in this case.
Here is an example that shows where MSYS make works, while MinGW make and UnxUtils make will fail:

(这一小点说得很在理,我就曾经遇到过这样的问题,MSYS的make确实表现比MinGW的好) 

# Very simple Makefile
list:
        /c/unxutils/usr/local/wbin/ls Makefile
Works:
$ /bin/make list
Makefile
Fails:
$ /mingw/bin/mingw32-make list
# process_begin: CreateProcess(NULL, /c/unxutils/usr/local/wbin/ls Makefile, ...) failed.
# make (e=3): The system cannot find the path specified.
# mingw32-make: *** [list] Error 3
Fails:
$ /c/unxutils/usr/local/wbin/make list
# process_begin: CreateProcess((null), /c/unxutils/usr/local/wbin/ls Makefile, ...) failed.
# make (e=3): The system cannot find the path specified.
# c:/unxutils/usr/local/wbin/make.exe: *** [list] Error 3
So if you get an error similar to the one above, be sure that you use MSYS make:
$ which make
/bin/make

Directory mapping and mount points
MSYS uses the following automatic mounts (that is, not configurable) in its directory layout:
Read all the details about how automatic points works in /doc/msys/README.rtf (that is, C:/msys/1.0/doc/msys/README.rtf outside MSYS), included in the MSYS distribution.

How to configure mount points manually
If we access C:/MSYS/1.0/mingw outside MSYS, we that this directory is (and should be) empty.
But when accessing /mingw in a MSYS shell, we see the following (assuming MinGW was installed before MSYS):
$ ls /mingw
COPYING      MinGW-5.1.3.exe  bin  include  installed.ini  libexec  mingw32
COPYING.LIB  MinGW.url        doc  info     lib            man      uninst.exe
This is because it is configured (automatically, during the MSYS installation) in /etc/fstab (that is, C:/msys/1.0/etc/fstab outside MSYS) as a user defined file system binding.
As the file name /etc/fstab indicates, this can be seen as a mount point.
(Or, if you prefer, as creating a "directory symlink".)

If you want to access other directories without using the full path, you can configure your own mount points.
Assume we have some source code in c:/Documents and Settings/Administrator/src that we want to access easily from within MSYS, without using the full path every time.
Create an empty directory C:/msys/1.0/home/me/src outside MSYS, or /home/me/src inside MSYS:
$ mkdir /home/me/src
Edit C:/msys/1.0/etc/fstab (use for example WordPad outside MSYS, or vi inside MSYS):
# Mount point created automatically during install
c:/MinGW /mingw

# Create a mount point for c:/Documents and Settings/Administrator/src on /home/me/src
c:/DOCUME~1/ADMINI~1/src /home/me/src
If you have any problems with configuring similar to the ones I experienced, read these notes:
# NOTE: 
# Different from UNIX, in MS Windows both source and destination directories have to exist.
# Source directory (c:/Documents and Settings/Administrator/src) will contain the files,
# destination directory (/home/me/src) must exist and be empty.
# /home/me/ is already mapped to c:/msys/1.0/home/me
# That means that C:/msys/1.0/home/me/src has to be created manually.
# This can be done either with Windows Explorer, or with the "mkdir src" command
# in a MSYS shell (in the /home/me directory).

# NOTE 2:
# When I just finished installing MSYS, I had problems to reflect changes in this file,
# even when closing a MSYS session and opening a new one.
# The solution was to restart Windows.
# Anyhow, this seems to be a one-time problem.
# From there and on, restart Windows is no longer needed, just close the MSYS session and open a new one.

# NOTE 3:
# I had problems using long names (with spaces) in path names.
# c:/Documents and Settings/Administrator/src /home/me/src    #DOES NOT WORK!
# c:/Documents/ and/ Settings/Administrator/src /home/me/src  #DOES NOT WORK!
# c:/DOCUME~1/ADMINI~1/src /home/me/src                       #WORKS!

# The solution was to find out the short name for the path.
# To do this, open a DOS prompt and type "dir /-N". 

Using third-party programs through wrapper scripts
There is no way to create a "file symlink" in MSYS in a way similar to a "directory symlink" (that is, a mount point).
The command ln for creating links works, but it actually makes a copy of the original file, not a symlink to it.
This is not what we want.
The solution is to create a wrapper script in /usr/local/bin.
The PATH environment variable in MSYS reflects the one configured in Window's Control Panel, with the MSYS and MinGW paths prepended:
$ echo $PATH
.:/usr/local/bin:/mingw/bin:/bin:/windows/configured/paths/go/here
As we see, first the current directory is searched, then /usr/local/bin/, then the MinGW path (/mingw/bin), then the MSYS path (/bin).
You can take advantage of the path /usr/local/bin being prepended to $PATH, to create your own shell script wrappers.
This way, you can call any Windows program without using the full path.

Create the /usr/local/bin directory if it doesn't exist:
mkdir -p /usr/local/bin
Example 1:
Create /usr/local/bin/wp, a wrapper for WordPad.exe:
#!/bin/sh
/c/Program/ Files/Windows/ NT/Accessories/wordpad.exe "$@"
Example 2:
Create /usr/local/bin/emacs, a wrapper for EmacsW32.exe (obviusly requires EmacsW32, how to install EmacsW32):
#!/bin/sh
/c/Program/ Files/Emacs/emacs/bin/emacsclientw.exe -n "$@"
Example 3:
Create /usr/local/bin/emacs-redantigua, a wrapper for EmacsW32.exe accessing a remote file/directory through plink (requires PuTTY, here is how to install PuTTY):
#!/bin/sh
/c/Program/ Files/Emacs/emacs/bin/emacsclientw.exe -n /plink:redantig@redantigua.com:/home/redantig/www/
Now you can edit any file from inside MSYS either with the command
wp <filename>
or
emacs <filename>
depending on your preferencies.

More info about mount points and scripts can be found in C:/msys/1.0/doc/msys/README.rtf, included in the MSYS distribution.

Note:
From C:/msys/1.0/doc/msys/README.rtf:
"If you wish to map a path with spaces you must use the DOS style name."
This also holds true for paths with spaces (a.k.a. 8dot3 file names) in script variables.
While the script /usr/local/bin/wp in Example 1 above works, the following script /usr/local/bin/wp_8dot3 will NOT work:
#!/bin/sh
# NON-WORKING SCRIPT!
# Running this script will fail with the following error:
#    /usr/local/bin/wp_8dot3: /c/Program/: No such file or directory
WP_EXE="/c/Program/ Files/Windows/ NT/Accessories/wordpad.exe"
$WP_EXE $@

Here is how to find the path manually:
#!/bin/sh
# CD C:/
# DIR /X|FINDSTR PROG
# Displays:
# 19/11/2007  10:16    <DIR>          PROGRA~1     Program Files
# CD "Program Files"
# DIR /X|FINDSTR WIN
# Displays:
# 04/04/2005  19:06    <DIR>          WINDOW~4     Windows Journal Viewer
# 22/02/2006  21:45    <DIR>          WINDOW~2     Windows Media Player
# 04/04/2005  18:40    <DIR>          WINDOW~1     Windows NT
# CD "Windows NT"
# DIR /X|FINDSTR ACC
# Displays:
# 04/04/2005  19:08    <DIR>          ACCESS~1     Accessories
# CD Accessories
# DIR /X|FINDSTR wordpad
# Displays:
# 04/08/2004  06:00           214.528              wordpad.exe
WP_EXE="/c/PROGRA~1/WINDOW~1/ACCESS~1/wordpad.exe"
$WP_EXE $@

Finding the path manually may be a bit tedious.
You can download the script non8dot3, which converts 8dot3 paths to non-8dot3 ones.

Additional tools
As mentioned before, MSYS requires MinGW to be installed.
You may also install Emacs and/or UnxUtils to get a more UNIX-like environment on your Windows box.
If you want other development tools than make, you should consider installing msysDTK, which basically includes autoconf, automake, libtool, autogen, openssl, openssh, cvs, guile, and inetutils.
You may also install GDB for MinGW.

Read more
http://www.mingw.org/msys.shtml - Home Page
http://www.mingw.org/docs.shtml - Documentation
http://www.mingw.org/MinGWiki/index.php/GettingStarted - Getting Started
http://allies.freezope.org/MsysMingw - Msys Mingw tutorial

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值