Reputation: 4328
I have written a makefile in which the sequence of commands is as follows inside my makefile
.PHONY: all clean distclean run
run : $(program_NAME)
./$(program_NAME) > output.txt #runs my program and stotre output in output.txt
all: $(program_NAME)
$(program_NAME): $(program_OBJS)
$(LINK.cc) $(program_OBJS) -o $(program_NAME)
If i change the sequence of this to below one it doesnot work for me:-
.PHONY: all clean distclean run
$(program_NAME): $(program_OBJS)
$(LINK.cc) $(program_OBJS) -o $(program_NAME)
all: $(program_NAME)
run : $(program_NAME)
./$(program_NAME) > output.txt #runs my program and stotre output in output.txt
This doesnot generate any output.txt
for me .
What i feel is run :
is dependent on $(program_NAME) so $(program_NAME): $(program_OBJS)
$(LINK.cc) $(program_OBJS) -o $(program_NAME)s
should come before run :
in makefile. But its working fine other way round .
Can Someone throw some light here? (Thanks)
Upvotes: 0
Views: 64
Reputation: 29021
First of all, you have to observe indentation rules for makefiles. Commands to be executed by a rule should start with a tab character. Then, take into account that the first rule that appears in the makefile is executed automatically when you type make
. In the first case the program is run. To obtain the same in the second makefile in which the run
rule is not the first, you have to execute make run
.
Upvotes: 1