Msys + makefiles + your editor

How to marry an editor like Crimson Editor (or the Emerald Community version) with msys/mingw and makefiles?. For long time I simply switched back and forth between the msys window and CEDT, I don’t know why I waited so long to make this integration but it has been a great time saver for me. I hope it will be for you as well.

By the way, this methods works with other editors as well. If you use PSPad you can easily adapt this explanations to it.

Create a batch file (cedt_mk.bat) with this one line:

C:/msys/1.0/bin/sh –login -c “cd ‘%1’ ; cd `pwd`; make %2”

and store it in the msys /usr/bin directory (C:/msys/1.0/bin in my installation).

This batch file starts the msys shell and sets up all the environment variables as if you had login, so if your makefile depends on variables you set on your .profile, it will work.
It then goes to the directory specified by the first argument, where it expects to find a makefile, and makes the target specified by the second parameter.
Note that the first cd will receive a path in MSDOS format (e.g. ‘D:\projects’) that the shell will convert to ‘/d/projects’. However there is a bug in msys when the UNIX path ends with ‘/’. To fix it a cd to the current directory (cd `pwd`) is needed

Now add a couple of “tools” to CEDT through the “Tools/Conf. User Tools…”:

Crimson Editor Tools menu

Crimson Editor Tools menu

I defined two. The first one as “Make …” that will prompt for the name of the target (second argument set to $(UserInput).

Will ask for the target name

Will ask for the target name

and the second one as “Make Selected” that will use the selected word as the name of the target (second argument set to $(CurWord).

Target will be the current/selected word

Target will be the current/selected word

I mapped them to F9 and Ctrl+F9 respectively.

Having set the first “Argument” and the “Initial Dir” to $(FileDir), the makefile used will be the one stored in the same directory of the current file. This may work or not for you depending on the structure of the directories in your project.
I usually have a makefile for each directory in the project (src, test, docs, …) but sometimes I use a single makefile in the root directory of the project. In that case setting the first argument of cedt_mk.bat to “$(FileDir)\..”  would have worked.  Of course one could play with the cedt_mk.bat script to add more intelligence to it. I will be happy to hear any improvement.

Having set to option “Capture Output”, I will get all the error messages directly in the output pane of CEDT. If I only could jump directly the file/line when an error occurs …

Advertisements

Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: