4 ms·
Hard disagree. GO_SRCS=$(shell find src -name '*.go' -not -name '*_test.go) GO_TESTS=$(shell find src -name '*_test.go') .PHONY: run docker-ru
by paulddraper 4y ago
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".......)
- rgoulter 4y agoMost (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 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).
- paulddraper 4y ago> 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).
- deleted 4y ago[deleted]
- therein 4y agoI 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.
- lenkite 4y agoWhy do we need to add `.PHONY` for every target ? This is one of the things I utterly despise about make.
- jbverschoor 4y agoBecause 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”
- jbverschoor 4y agoIf 'make' was called makefile, I don't think it'd be so popular. Naming is important
- paulddraper 4y ago.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.
- tpoacher 4y agoYou 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.
- zie 4y agoIt's a GNU thing :P
- teo_zero 4y ago> What is your better thing? A shell script?