User Tools

Site Tools


programming:make:fake_target

Programming - Make - Fake Target

By default, make only tries to build the first thing it finds.

Makefile
hello: hello.c

NOTE: Here:

  • hello: The target.
  • hello.c. The source.

Fake Target

A fake target can be provided:

Makefile
all : hello hello2 hello3

NOTE: This shows the target as all, probably not what is really wanted:

This actually works as long as there is never a file named all in the working directory.

This assumes that there are other rules elsewhere in the Makefile for the 3 hello programs so they can be built.


Prevent problems using all

To prevent this usage of all being a problem, you can declare that target as phony by using this statement in the makefile:

Makefile
.PHONY: all

NOTE: Actions can be attached to phony targets as well. For example:

Makefile
.PHONY: clean
clean: 
  rm *.o

NOTE: You can issue make clean from the command line to remove all the object files.

programming/make/fake_target.txt · Last modified: 2021/02/04 16:56 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki