0

I'm making a script to compile and run an entire project on Notepad++ using NppExec.

I keep each project on a folder and each folder has a makefile to compile the entire project, the compiler will produce a single .exe file so in each folder there is just one executable that has the same name of the folder (with the .exe extension).

I made the first part of the script (compiling with the makefile) but I don't know how to make the second part (running the executable). I know how to run an executable in NppExec but I'm trying to do something different: I want to compile the exe without specifying its name in the commands so that I can use the script to compile and run every project organized as I explained above (each folder with only one .exe that has the same name of the folder).

How can I do it? If you don't know how to do that in NppExec, how can I do the same thing in cmd? (I can then write that in NppExec by adding cmd \c at the and of the command)

dvd2000
  • 103
  • 3
  • You could add a "run" target to the makefiles and have the nppexec script say something like "make run". "run", "all" and "clean" are used frequently in makefiles. If the run target is chained properly with all and the specific compile commands, it will do the necessary recompilations and stop when errors are detected. – Lars Fischer Nov 07 '15 at 13:40
  • @LarsFischer Thank you for your help. I started recently to use the make "tool" so I didn't know this target. – dvd2000 Nov 07 '15 at 14:03
  • @LarsFischer I've added the run target to the makefile like that: `run : $(ESEGUIBILE)
    '(ESEGUIBILE)` and &(ESEGUIBILE) is obviously my executable. But when I execute the make Makefile run the program (a console program) starts in NppExec console. How can I do to run it on a separate window? (as if I runned it from windows explorer)
    – dvd2000 Nov 07 '15 at 14:23
  • I am not sure, since I have not tried make with windows. I would try the start command: use "start $(ESEGUIBILE)" inside the run rule or something like "start cmd /k $(ESEGUIBILE)" to pull in a command window. Another possible way is to keep the makefile as it is and use a different command inside nppexec: "npp_run cmd /k make run". – Lars Fischer Nov 07 '15 at 15:02
  • Sorry, I've forget to say that I'm using mingw32-make and not the (gnu) make. I've tried both your options and they don't work, it says that the system cannot find the file specified but if i open cmd and type just "start" and the name of the executable it work without any problem – dvd2000 Nov 07 '15 at 15:57
  • Sorry, I have no idea what is going on. There is thread on [stackoverflow](http://stackoverflow.com/questions/2463037/calling-windows-commands-e-g-del-from-a-gnu-makefile) discussing some possibilities like escaping /k with a backslash, using quotes, using /K (capital K)
    I think you need a way to run your program from the makefile, since the makefile knows the name of the executable.
    For the other option (npp_run): does it help to provide the full path to make? "npp_run cmd/k FULLPATH_TO_MAKE run".
    – Lars Fischer Nov 07 '15 at 16:50
  • What is the full path to make? – dvd2000 Nov 07 '15 at 17:08
  • Now it works, I've added the cmd /C at the beginning of the line in the makefile as suggested in the post you linked me and now it runs without any problem, thank you – dvd2000 Nov 07 '15 at 17:16
  • I have compiled the comments into an answer, feel free to accept the answer if it is correct and helpful. – Lars Fischer Nov 07 '15 at 18:29

1 Answers1

0

There are some special targets make knows about:

  • all: to compile everything
  • run: to run the program, if this depends on all, then the program is recompiled if necessary
  • clean: for necessary clean ups

So what you need are two npp_exec scripts which you can bind to different keyboard shortcuts (save the scripts under some names, in the menu use Plugins, Nppexec, Advanced options: add the scripts to the menu using the controls on the left; give the menu items different menu_names; restart notepad++; goto Settings, Shortcut mapper, Plugins commands: you will find the menu_names somewhere in this list, you can assign keyboard shortcuts to them).

The second ingredient are the targets in the makefile:

  • all: depends on your binary
  • run: depends on all, the command would normally be something like
    ./$(ProgName)
    
    but in your case (windows with mingw32-make, as explained in the comments, and you need a command window) your run target would look like
    run: all
         cmd /C $(ESEGUIBILE)
    

This way you have one setup in Notepad++ that works for all your folders, the interface is

  • make all
  • make run

The makefiles in each folder know the name of the folder specific binary, you only need to add the run section to each makefile.

Lars Fischer
  • 9,135
  • 3
  • 26
  • 35