10

Phony targets in Makefiles

 4 years ago
source link: https://ericmjl.github.io/blog/2021/3/4/phony-targets-in-makefiles/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Phony targets in Makefiles

written by Eric J. Ma on 2021-03-04

| tags: automation computation reproducibility

Makefiles can be used to create a lightweight CLI entry point for your project. By writing a Makefile, you can automate repetitive shell commands, such as building a Dockerfile (which might require you to remember certain incantations):

.PHONY: container

container:
    docker build -t mycontainer -f Dockerfile .

Doing so allows us to build a Docker container using the command make container when at the command line.

Now, you'll probably notice the .PHONY line at the top. What's that all about?

By convention, the command container would have referred to a file target on disk. (This is how Makefiles were originally designed.) However, if we want the command to be independent of any files on disk, we declare it to be a phony target that doesn't actually exist on disk.

I send out a monthly newsletter with tips and tools for data scientists. Come check it out at TinyLetter.

If you would like to receive deeper, in-depth content as an early subscriber, come support me on Patreon!


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK