Hacker News new | ask | show | jobs
by mikegirouard 2385 days ago
It's really frustrating seeing so many Makefiles that don't _make_ anything.

Make syntax is really odd. I see so many folks go out of their way to deal w/quirks of make when they really just need a shell script. You can see this anti-pattern very quickly when you see `.PHONY` targets for everything.

I think make is useful for some aspects of go. GOPATH is becoming less relevant now, but still helpful when you want to have build-time dependencies in $PATH

    $(GOPATH)/bin/some-dependency:
        go get -u ...
I still use make when building artifacts, especially in CI. But as a default, I almost always try to talk folks out of using make for this sort of stuff.
1 comments

Is there a way to easily have something like make targets in a shell script, without a ton of boilerplate?

> Make syntax is really odd

I don't find it particularly strange, except my biggest peeve - the insistence on tabs!

Here's a named task runner shellscript (as compared to a Makefile full of .PHONY being used as a named task runner).

    #!/bin/sh
    set -e

    case "$1" in
        build)
            ;;
        run)
            ;;
        clean)
            ;;
        *)
            echo "unknown: $1"; exit 2
            ;;
    esac
Someone else ITT hinted it could be done like the following. But the last line is dubious because it will happily run anything on PATH.

    #!/bin/sh
    set -e

    test $# -gt 0

    build() {
        :
    }

    run() {
        :
    }

    clean() {
        :
    }

    "$@"
> (as compared to a Makefile full of .PHONY being used as a named task runner)

Personally, I've never used PHONY, or had a need to.

That said, your bash examples are pretty simple - I especially like the 2nd example, as it would trivially allow having targets that ran other targets, e.g. an "all" target from a makefile:

``` all: build push

build: @docker build --tag ${IMG} --tag ${UNSTABLE} .

rebuild: @docker build --no-cache --tag ${IMG} --tag ${UNSTABLE} .

push: @docker push ${NAME} ```