-1

Is there a generic way to convert a shell script under MSYS/MinGW into a windows .exe file (which calls the shell script behind the scene)?

The specific problem I am facing is that I have a shell script lein from Leiningen (clojure tool chain). I installed it to the default path at /usr/local/bin (note: I used the shell script version for MSYS, and didn't want to install lein command outside the MinGW/MSys tree).

Now emacs cider cannot pick up the lein script although lein is on the windows path and exec-path. If I copy lein into a fake lein.exe

cd /usr/local/bin && cp lein lein.exe

then, cider recognizes lein.exe. But of course, cider couldn't load it because it's not a valid exe.

Hence, my question. Is there a generic way I can convert a shell script like lein into a windows executable, e.g. by writing a proxy c++ program?

Thanks.

-- EDIT ---

(Thoughts after seeing the downvotes).

I know this is a corner case and maybe not something you do everyday, and but this is the best solution I can identify so far for making a workable clojure tool chain in MinGW/MSYS.

thor
  • 21,418
  • 31
  • 87
  • 173
  • Like other questions asking "is there a way to do X" this one is too broad. – Captain Obvlious Jun 10 '15 at 23:03
  • 1
    As you originally posed it, I didn't think this question was too broad at all; quite the opposite, in fact, and I might have offered an answer to that question. Now you've changed its scope entirely, to something which I would have no interest whatsoever in addressing. – Keith Marshall Jun 11 '15 at 01:15
  • @KeithMarshall, if you can post or outline a potential answer, I will roll the question back. I don't really think my question was broad either or care that others think it's too broad. I've narrowed it down only because I am interested in seeking a solution. And a more general solution for MinGW/MSYS is certainly better in my book. – thor Jun 11 '15 at 01:41
  • @KeithMarshall Could you help edit my question to the original form you saw? I couldn't find a way to rollback my own edits. – thor Jun 11 '15 at 01:49
  • I don't have sufficient privilege to do any more than _suggest_ edits, so no, I can't really help you with that. If you click the [edited x hours ago](http://stackoverflow.com/posts/30768671/revisions) link below the question you should see the full editing history; your original question is [here](http://stackoverflow.com/revisions/30768671/1) – Keith Marshall Jun 11 '15 at 02:07
  • Your specific case isn't really a _corner_ case; more like just one specific example of a more generally useful technique, (and I've answered in that more general sense). I don't know why this is attracting down votes; IMO, they are unwarranted. – Keith Marshall Jun 11 '15 at 02:17
  • I don't know. Maybe my language is bad:) – thor Jun 11 '15 at 02:20

1 Answers1

1

You originally asked this under the heading "How [can I] convert an MSYS shell script to a Windows .exe?" In my opinion, that's a generally more useful (and quite specific) question to ask, than what you are now asking. On this basis, I will offer an answer to the original question.

I know of no way in which you can simply compile an MSYS shell script, (or indeed any Bourne shell script), into a Windows executable, such that it may be invoked as a child of another executable. However, what you may be able to do is invoke the MSYS shell itself, as the child process, to interpret the script; the syntax you need is:

sh.exe -c 'script [argument ...]'

so, if you can configure your emacs clojure process to invoke the command in this fashion, you may achieve your objective.

A word of caution, however: MSYS commands are intended to be run from within an already running, and properly initialized MSYS parent shell. If emacs is running as a child of such a shell, then this should work okay. However, if emacs is running as a purely native Windows process, outside of an MSYS environment, then you have to take care of initialization[*], when you invoke the child shell. If you see error messages such as "resource unavailable", "resource temporarily unavailable", or "cannot reserve space for cygwin's heap", (yes, MSYS is derived from an early cygwin release, and the text of this message was never changed), that's a fairly certain indicator that the shell environment is not properly initialized.

[*] Effectively, you need to reproduce the initialization steps which are performed by the msys.bat command script, which accompanies any MSYS installation.

Keith Marshall
  • 1,980
  • 15
  • 19