News for hackers. Stuff that matters.
Re:Learn Makefiles with the Tastiest Examples by paulddraper on Monday May 15, 2023 @10:24PM (#35957140)
Hard disagree.

    GO_SRCS=$(shell find src -name '*.go' -not -name '*_test.go)
    GO_TESTS=$(shell find src -name '*_test.go')

    .PHONY: run
    docker-run: target/image.target
        docker run example

    .PHONY: integration-test
    integration-test: target/integration-test.target

    .PHONY: test
    test: target/test.target

    target/bin: $(GO_SRCS)
        mkdir -p $(@D)
        GOOS=linux-amd64 go build -ldflags='-s -w' -o $@

    target/context.target: Dockerfile target/bin
        rm -fr $(@:.target=)
        mkdir -p $(@:.target=)
        cp Dockerfile target/bin $(@:.target=)
    
    target/image.target: target/context.target
        docker build -t example $(<:.target=)

    target/integration-test.target: target/image.target
        # TODO: test the docker image

    target/test.target: $(GO_SRCS) $(GO_TESTS)
        go test
What is your better thing?

(The answer is Bazel, but if you think Make is a "supercar".......)

Re:Learn Makefiles with the Tastiest Examples by rgoulter on Monday May 15, 2023 @11:19PM (#35957405)
Most (all?) of your Makefile targets don't represent actual files to 'make'.

You're using make to run a bunch of tasks, including where tasks may depend on other tasks having been run before.

A task-runner tool like `just` is better suited to this task. https://github.com/casey/just

`just` has some nice UX improvements over `make`. (e.g. doesn't require soft tabs, can list recipes out of the box, recipes can take command line arguments, supports .env files, can be run from any subdirectory).

Re:Learn Makefiles with the Tastiest Examples by paulddraper on Monday May 15, 2023 @11:58PM (#35957604)
> Most (all?) of your Makefile targets don't represent actual files to 'make'.

> You're using make to run a bunch of tasks, including where tasks may depend on other tasks having been run before.

And the cool thing is....it works for both!

It can represent an actual file (e.g. a compiled binary) or abstract result (e.g., a successful test).

Re:Learn Makefiles with the Tastiest Examples by therein on Tuesday May 16, 2023 @01:44AM (#35958100)
I wish `just` had a way to capture the output of functions and act on them. Without that, it is only a slightly more straight-forward Make that's way less likely to be installed on the system plus you have to take additional steps if you want shell completion for tasks.
Re:Learn Makefiles with the Tastiest Examples by lenkite on Tuesday May 16, 2023 @02:31AM (#35958344)
Why do we need to add `.PHONY` for every target ? This is one of the things I utterly despise about make.
Re:Learn Makefiles with the Tastiest Examples by jbverschoor on Tuesday May 16, 2023 @02:42AM (#35958407)
Because make is misused

Make is a tool to make files based on dependencies

It was not created as a scripting language. It understands trees.

It is not to “make” your project. It “makes” “files”

Re:Learn Makefiles with the Tastiest Examples by jbverschoor on Wednesday May 17, 2023 @04:02AM (#35972464)
If 'make' was called makefile, I don't think it'd be so popular. Naming is important
Re:Learn Makefiles with the Tastiest Examples by paulddraper on Tuesday May 16, 2023 @04:34AM (#35959075)
.PHONY is how you distinguish between targets that are actual files vs targets that are virtual.

Seems like useful information to me....

It's best practice, though the only time you need it is when a virtual target happens to have the same name as an actual file.

Re:Learn Makefiles with the Tastiest Examples by tpoacher on Tuesday May 16, 2023 @08:29AM (#35960919)
You don't. You can specify this in a single line.

Unless the question was, why do I have to mark targets as PHONY more generally.

In which case the answer is, you don't. You only do this when you want the recipe to always run when invoked, as opposed to the standard mode where invocation is conditional on the file being out-of-date.

Re:Learn Makefiles with the Tastiest Examples by zie on Thursday May 18, 2023 @04:53PM (#35993906)
It's a GNU thing :P
Re:Learn Makefiles with the Tastiest Examples by teo_zero on Wednesday May 17, 2023 @01:26AM (#35971568)
> What is your better thing?

A shell script?