views:

111

answers:

2

The idea is that a project has a single file with __DATE__ and __TIME__ in it. It might be cool to have it recompiled without explicitly changing its modification date.

edit: $(shell touch -c ..) might be a good solution if only clumsy.

+1  A: 

One way to do this is to delete the corresponding object file (.o or .obj) before running make. This will trigger a recompile (and relink) without changing the source file modification date.

Greg Hewgill
+8  A: 

The standard idiom is to have the object file (not the source file!) depend on a target which doesn't exist and has no rules or dependencies (this target is conventionally called FORCE), like this

always-recompile.o: FORCE
FORCE:

This will break if a file named "FORCE" gets created somehow, though. With GNU make you can instead use the special target .PHONY, which doesn't have this limitation, but does require you to have an explicit rule to rebuild that file:

always-recompile.o:
        $(CC) $(CFLAGS) -c -o always-recompile.o always-recompile.c

.PHONY: always-recompile.o

See http://www.gnu.org/software/make/manual/html_node/Phony-Targets.html for more details.

Zack
You should do ".PHONY: FORCE" because always-recompile.o is not a phony target. With ".PHONY: FORCE" it should not matter if a file called FORCE gets created.
camh
Does that actually work? The GNU make manual sounds like phony targets don't work as dependencies of real targets.
Zack