12

I'm trying to build my project by simple executing make in the top directory. However, when I do, I get the following error:

[Errno 2] No such file or directory
[cmd:  [u'make']]
[dir:  /Users/jonathanong/Workspace/template]
[path: /usr/local/bin]
[Finished]

This is after setting the build configuration to Make.

I'm on Sublime Text 2.0.1, OS X 10.8.2. My Makefile consists of executing globally installed node.js binaries. What do I have to do?

Jonathan Ong
  • 19,927
  • 17
  • 79
  • 118
  • 1
    Just in case Linux users were searching this: [Ctrl+M to run Makefile with Sublime+Linux](http://stackoverflow.com/q/21709896/562769) – Martin Thoma Feb 12 '14 at 06:11

3 Answers3

15

This is because make is not in your PATH. If you can build in the terminal, use which make to figure out the path to make, and then add that to the path for build. You can edit the makefile build system to add your path.

Your new makefile rule should look like:

{
   "cmd": ["make"],
   "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
   "working_dir": "${project_path:${folder:${file_path}}}",
   "selector": "source.makefile",
   "path": "/usr/local/bin:/Applications/Xcode.app/Contents/Developer/usr/bin",
   "variants":
    [
      {
        "name": "Clean",
        "cmd": ["make", "clean"]
      },
      {
        "name": "Test",
        "cmd": ["make", "test"]
      }
    ]
}

This is basically the default make target, but I added to the PATH, and (of course) a test target. You may have to extend the PATH to find gcc, ifort, or whatever you are using to compile. Use : to separate directories on Linux and Mac, and ; on Windows. You can also change other environment variables, I had to set DYLD_LIBRARY_PATH and CPATH so that my libraries and include directories would be available.

It should be saved as Make (OSX).sublime-build in the User directory of your Sublime preferences. The (OSX) will ensure that this file is only used on Mac, so when you copy your preferences to a non-mac computer, you won't gunk up the path.

dbn
  • 13,144
  • 3
  • 60
  • 86
  • does that mean i would have to make a build file for every single project? – Jonathan Ong Dec 11 '12 at 20:13
  • You can have both user setting build files and project level build files. – dbn Dec 11 '12 at 20:21
  • alright so my path is `/usr/bin/make`, so I made `/usr/bin` my path. Now I'm getting `make: component: No such file or directory`. I guess I need to let sublime text know about `/usr/local/bin/component` and/or `/usr/local/bin`. How do I do that? – Jonathan Ong Dec 11 '12 at 21:42
  • well `/user/bin:/user/local/bin` works. not sure why `:` is a separator. thanks! – Jonathan Ong Dec 11 '12 at 21:46
  • `:` is the separator for `PATH` and `PATH`-like environment variables (on Linux and Mac - Windows uses ;). – dbn Dec 11 '12 at 22:45
  • I take it this means that Sublime Text 2 isn't looking at the $PATH environment variable when it runs Build? make is also in /usr/bin on my system. –  Apr 13 '13 at 21:08
  • @dpk a better question is probably "what does $PATH look like when sublime is launched?" If you're launching it from the window manager, I don't think that PATH will have the local modifications that you have made in your .bashrc, for instance. – dbn Apr 15 '13 at 23:37
  • @dbw In my case I have a program in /usr/bin that sublime could not find. I was making the assumption that $PATH included /usr/bin at the time sublime was launched, but I guess it might not have. That'd be exceedingly strange, though, eh? –  Apr 17 '13 at 22:26
  • I don't know if that's strange. I'd check on the defaults for your distribution. – dbn Apr 17 '13 at 22:44
  • 1
    Just type `import os; os.environ['PATH']` in the ST console and you use which PATH is used... – schlamar May 06 '13 at 14:03
1

A much preferable solution is IMO to adjust the PATH in a plugin, so you have to set it just once for all build systems and all plugins calling external commands.

You can just do

import os
os.environ['PATH'] += os.pathsep + '/my/extra/path'

Real world example lives at https://github.com/schlamar/ST3User/blob/master/preferences.py

schlamar
  • 9,238
  • 3
  • 38
  • 76
0

If your makefile works by going to the directory its in and typing make, then this custom sublime-build file works:

 {  
      "working_dir": "${file_path}",  
      "cmd": ["make"],  
      "variants":  
 [  
   {  
        "working_dir": "${file_path}",  
     "name": "Run",  
     "cmd": ["./a.out"]  
   }  
 ]  
 }  
got here
  • 203
  • 1
  • 7