Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Executable from makefile

Hey I just have a quick question about makefile's. Is there some way to auto run the executable generated from a makefile?

Like if I just type "make" it will compile and build and automatically execute so I can skip the extra step of ./myExecutable

I have down in my notes:

run: prog1
        ./prog1

But it doesn't seem to work.

Thanks

like image 294
ModdedLife Avatar asked Mar 22 '13 09:03

ModdedLife


People also ask

Is a makefile an executable?

Makefile Rules. The target in a makefile rule is usually the name of a file that is to be made as part of the project. This is most commonly an executable file or an object code file.

What is $@ in makefile?

The file name of the target of the rule. If the target is an archive member, then ' $@ ' is the name of the archive file. In a pattern rule that has multiple targets (see Introduction to Pattern Rules), ' $@ ' is the name of whichever target caused the rule's recipe to be run.

How do I run a makefile in Windows?

An easy way is to start a command prompt from Visual Studio ( Tools->Visual Studio Command Prompt ), so that all the necessary environment variables are set. Change directory to where the Makefile exists and run NMake. D:\tmp\Simple-Makefile>nmake Microsoft (R) Program Maintenance Utility Version 10.00.


1 Answers

If you run make without specifying any targets, it would execute the first target it finds within the Makefile. By convention all is the name of such a target.

If you make run a pre-requisite for all and mark both all and run as PHONY targets, you should be good to go.

all: run

run: prog1
    ./prog1

.PHONY: all run

BTW, I presume you already have some rules for building prog1 in your Makefile, and hence have not included it in the above shown Makefile.

An alternative would be to just invoke make explicitly with the run target, i.e. execute the following command:

make run
like image 153
Tuxdude Avatar answered Sep 20 '22 17:09

Tuxdude