0

I tried to run an execuatble after refering to some link on SO Run Executable from makefile. Everything works fine only that I need to type "make run" to execute all commands. I want to know how can I run it without having to type run and simply make should run everything. As of now make command only executes the rule all and to run the other part I have to use make run. I am new to Make. Could you also help me refine the code a little. Any help is appreciated.

all:    rdata.c
    -sudo rm a.out
    -gcc rdata.c -o a.out

exec:   run

run:    all
    -sudo ./a.out
    sudo javac -classpath /home/hduser/12115_Select_Query/hadoop-core-1.1.2.jar -d mysort MySort.java 
    sudo jar -cvf mysort.jar -C mysort/ .
    -hadoop fs -rmr MySort/output
    -hadoop fs -rmr MySort/input
    hadoop fs -mkdir MySort/input
    hadoop fs -put Data/data.txt MySort/input       
    hadoop jar mysort.jar org.myorg.MySort MySort/input MySort/output
    -sudo rm /home/hduser/Out/sort.txt
    hadoop fs -copyToLocal MySort/output/part-r-00000 /home/hduser/Out/sort.txt
    sudo gedit /home/hduser/Out/sort.txt

.PHONY: exec run
Community
  • 1
  • 1
Akshay Hazari
  • 3,186
  • 4
  • 48
  • 84

1 Answers1

1

Just put the run rule first, before all.

You can also rewrite the all rule and rename it, to reduce redundancy and handle the dependencies correctly:

run: a.out
    blah blah blah

a.out: rdata.c
    -sudo rm $@
    -gcc $< -o $@

(I don't know enough about java and hadoop to judge the run rule.)

Beta
  • 96,650
  • 16
  • 149
  • 150
  • Hey. Thanks. It works. I want to know more about the redundancies occurring here. Also is it that make only runs the first rule defined in the Makefile? – Akshay Hazari Jun 10 '14 at 08:08
  • 1
    @RED When run without arguments make uses the default target. Without being told anything special the default target is the first target make finds in the makefile. – Etan Reisner Jun 10 '14 at 12:32
  • 1
    @RED: You could also leave the `run` rule where it was and put `.DEFAULT_GOAL := run` somewhere in the makefile, but I wanted to give the simplest answer that works. – Beta Jun 10 '14 at 13:27