kubo/Rules.mk
Jakub Sztandera f630222580
make: rework makefiles for non-recursive make and add sharness coverage
This commit introduces non-recursive Makefile infrastructure that replaces current Makefile infrastructure.
It also generally cleanups the Makefiles, separates them into nicer sub-modules and centralizes common operations into single definitions.

It allows to depend on any target that is defined in the makefile, this means that for example `gx install` is called once when `make build test_expensive_sharness` is called instead of 4 or 5 times.

It also makes the dependencies much cleaner and allows for reuse of modules. For example sharness coverage collection (WIP) uses sharness target with amended PATH, previously it might have been possible but not without wiring in the coverage collection into sharness make runner code.

Yes, it is more complex but not much more. There are few rules that have to be followed and few complexities added but IMHO it is worth it.

How to NR-make:
1. If make is to generate some file via a target, it MUST be defined in Rules.mk file in the directory of the target.
2. `Rules.mk` file MUST have `include mk/header.mk` statement as the first line and `include mk/footer.mk` statement as the last line (apart from project root `Rules.mk`).
3. It then MUST be included by the closest `Rules.mk` file up the directory tree.
4. Inside a `Rules.mk` special variable accessed as `$(d)` is defined. Its value is current directory, use it so if the `Rules.mk` file is moved in the tree it still works without a problem. Caution: this variable is not available in the recipe part and MUST NOT be used. Use name of the target or prerequisite to extract it if you need it.
5. Make has only one global scope, this means that name conflicts are a thing. Names SHOULD  follow `VAR_NAME_$(d)` convention. There are exceptions from this rule in form of well defined global variables. Examples: General lists `TGT_BIN`, `CLEAN`; General targets: `TEST`, `COVERAGE`; General variables: `GOFLAGS`, `DEPS_GO`.
3. Any rules, definitions or variables that fit some family SHOULD be defined in `mk/$family.mk` file and included from project root `Rules.mk`

License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
2017-02-12 01:18:40 +01:00

138 lines
2.7 KiB
Makefile

TGT_BIN :=
CLEAN :=
COVERAGE :=
DISTCLEAN :=
TEST :=
TEST_SHORT :=
all: help # all has to be first defined target
.PHONY: all
include mk/util.mk
include mk/golang.mk
include mk/gx.mk
# -------------------- #
# sub-files #
# -------------------- #
dir := bin
include $(dir)/Rules.mk
dir := test
include $(dir)/Rules.mk
dir := cmd/ipfs
include $(dir)/Rules.mk
# has to be after cmd/ipfs due to PATH
dir := coverage
include $(dir)/Rules.mk
dir := namesys/pb
include $(dir)/Rules.mk
dir := unixfs/pb
include $(dir)/Rules.mk
dir := merkledag/pb
include $(dir)/Rules.mk
dir := exchange/bitswap/message/pb
include $(dir)/Rules.mk
dir := diagnostics/pb
include $(dir)/Rules.mk
dir := pin/internal/pb
include $(dir)/Rules.mk
# -------------------- #
# universal rules #
# -------------------- #
%.pb.go: %.proto
$(PROTOC)
# -------------------- #
# extra properties #
# -------------------- #
ifeq ($(TEST_NO_FUSE),1)
GOTAGS += nofuse
endif
export IPFS_REUSEPORT=false
# -------------------- #
# core targets #
# -------------------- #
build: $(TGT_BIN)
.PHONY: build
clean:
rm -f $(CLEAN)
.PHONY: clean
coverage: $(COVERAGE)
.PHONY: coverage
distclean: clean
rm -f $(DISTCLEAN)
.PHONY: distclean
test: $(TEST)
.PHONY: test
test_short: $(TEST_SHORT)
.PHONY: test_short
deps: gx-deps
.PHONY: deps
nofuse: GOTAGS += nofuse
nofuse: build
.PHONY: nofuse
install: $$(DEPS_GO)
go install $(go-flags-with-tags) ./cmd/ipfs
.PHONY: install
uninstall:
go clean -i ./cmd/ipfs
.PHONY: uninstall
help:
@echo 'DEPENDENCY TARGETS:'
@echo ''
@echo ' deps - Download dependencies using bundled gx'
@echo ' test_sharness_deps - Download and build dependencies for sharness'
@echo ''
@echo 'BUILD TARGETS:'
@echo ''
@echo ' all - print this help message'
@echo ' build - Build binary at ./cmd/ipfs/ipfs'
@echo ' nofuse - Build binary with no fuse support'
@echo ' install - Build binary and install into $$GOPATH/bin'
# @echo ' dist_install - TODO: c.f. ./cmd/ipfs/dist/README.md'
@echo ''
@echo 'CLEANING TARGETS:'
@echo ''
@echo ' clean - Remove files generated by build'
@echo ' distclean - Remove files that are no part of a repository'
@echo ' uninstall - Remove binary from $$GOPATH/bin'
@echo ''
@echo 'TESTING TARGETS:'
@echo ''
@echo ' test - Run expensive tests'
@echo ' test_short - Run short tests and short sharness tests'
@echo ' test_go_short'
@echo ' test_go_expensive'
@echo ' test_go_race'
@echo ' test_sharness_short'
@echo ' test_sharness_expensive'
@echo ' test_sharness_race'
@echo ' coverage - Collects coverage info from unit tests and sharness'
@echo
.PHONY: help