Why does make think the target is up to date?

Makefile

Makefile Problem Overview


This is my Makefile:

REBAR=./rebar
REBAR_COMPILE=$(REBAR) get-deps compile

all: compile

compile:
	$(REBAR_COMPILE)

test:
	$(REBAR_COMPILE) skip_deps=true eunit

clean:
	-rm -rf deps ebin priv doc/*

docs:
	$(REBAR_COMPILE) doc

ifeq ($(wildcard dialyzer/sqlite3.plt),)
static:
	$(REBAR_COMPILE) build_plt analyze
else
static:
	$(REBAR_COMPILE) analyze
endif

I can run make compile multiple times and get

aromanov@alexey-desktop:~/workspace/gm-controller/lib/erlang-sqlite$ make compile
./rebar get-deps compile
==> erlang-sqlite (get-deps)
==> erlang-sqlite (compile)

However, for some reason running make test always gives

aromanov@alexey-desktop:~/workspace/gm-controller/lib/erlang-sqlite$ make test
make: `test' is up to date.

even if the files are not compiled. The question is, why?

Running the same command directly works:

aromanov@alexey-desktop:~/workspace/gm-controller/lib/erlang-sqlite$ ./rebar get-deps compile skip_deps=true eunit
==> erlang-sqlite (get-deps)
==> erlang-sqlite (compile)
Compiled src/sqlite3_lib.erl
Compiled src/sqlite3.erl
==> erlang-sqlite (eunit)
...

Makefile Solutions


Solution 1 - Makefile

Maybe you have a file/directory named test in the directory. If this directory exists, and has no dependencies that are more recent, then this target is not rebuild.

To force rebuild on these kind of not-file-related targets, you should make them phony as follows:

.PHONY: all test clean

Note that you can declare all of your phony targets there.

A phony target is one that is not really the name of a file; rather it is just a name for a recipe to be executed when you make an explicit request.

Solution 2 - Makefile

It happens when you have a file with the same name as Makefile target name in the directory where the Makefile is present.

enter image description here

Solution 3 - Makefile

EDIT: This only applies to some versions of make - you should check your man page.

You can also pass the -B flag to make. As per the man page, this does:

> -B, --always-make Unconditionally make all targets.

So make -B test would solve your problem if you were in a situation where you don't want to edit the Makefile or change the name of your test folder.

Solution 4 - Makefile

my mistake was making the target name "filename.c:" instead of just "filename:"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlexey RomanovView Question on Stackoverflow
Solution 1 - MakefileDidier TrossetView Answer on Stackoverflow
Solution 2 - MakefilePiyush SonigraView Answer on Stackoverflow
Solution 3 - MakefilejamescView Answer on Stackoverflow
Solution 4 - MakefileThorSummonerView Answer on Stackoverflow