make always rebuilds all targets

122 Views Asked by At

On

make

both the compile and run targets are rebuilt, even though no changes are made to the file One.c

all: compile run

compile: One.c
    gcc One.c -o One

run: One
    ./One

.PHONY: run

I am using Ubuntu-15.04 as OS, and Geany as editor.

One.c contains only one print statement, "hello world".

1

There are 1 best solutions below

0
On BEST ANSWER

When you run make it will try to build first rule in makefile (all), which depends on targets compile and run.

run is phony and will be run anyway. compile is non-phony, but there is no file named compile, so make will try to build this target (expecting it to produce compile file, but it wouldn't).

You need to add One non-phony target and build your binary here, e.g.:

all: compile run

compile: One

One: One.c
    gcc One.c -o One

run: One
    ./One

.PHONY: run compile