Makefile: update #689 to use dep in Makefile

This commit continues the work started by @sp4ke, in createing
a simple Makefile for lnd. The following commands are included:

 * make - builds everything (deps, lnd, and lncli) from scratch
 * make deps - installs dep if needed, then runs dep ensure
 * make install - builds lnd and lncli

 * make check - runs unit and itests
 * make unit - runs the unit tests for all packages
 * make itest - installs lnd and runs integration tests

 * make fmt - go fmt's all files
This commit is contained in:
Conner Fromknecht 2018-03-28 04:22:52 -07:00
parent 2f84d8ee2b
commit e549a79eb3
No known key found for this signature in database
GPG Key ID: 39DE78FBE6ACB0EF

View File

@ -1,20 +1,92 @@
.PHONY: all glidebin glide deps install fmt test
PKG := github.com/lightningnetwork/lnd
HAVE_DEP := $(shell command -v dep 2> /dev/null)
COMMIT := $(shell git rev-parse HEAD)
LDFLAGS := -ldflags "-X main.Commit=$(COMMIT)"
RM := rm
all: install
all: scratch
glidebin:
go get -u github.com/Masterminds/glide
glide: glidebin
glide install
# ==============================================================================
# INSTALLATION
# ==============================================================================
deps: glide
deps:
ifndef HAVE_DEP
@echo "Fetching dep."
go get -u github.com/golang/dep/cmd/dep
endif
@echo "Building dependencies."
dep ensure -v
install: deps
go install . ./cmd/...
build:
@echo "Building lnd and lncli."
go build -v -o lnd $(LDFLAGS) $(PKG)
go build -v -o lncli $(LDFLAGS) $(PKG)/cmd/lncli
install:
@echo "Installing lnd and lncli."
go install -v $(LDFLAGS) $(PKG)
go install -v $(LDFLAGS) $(PKG)/cmd/lncli
scratch: deps build
# ==============================================================================
# TESTING
# ==============================================================================
# Define the integration test.run filter if the icase argument was provided.
ifneq ($(icase),)
ITESTCASE := -test.run=TestLightningNetworkDaemon/$(icase)
endif
# UNIT_TARGTED is defined iff a specific package and/or unit test case is being
# targeted.
UNIT_TARGETED =
# If specific package is being unit tested, construct the full name of the
# subpackage.
ifneq ($(pkg),)
UNITPKG := $(PKG)/$(pkg)
UNIT_TARGETED = yes
endif
# If a specific unit test case is being target, construct test.run filter.
ifneq ($(case),)
UNITCASE := -test.run=$(case)
UNIT_TARGETED = yes
endif
# If no unit targeting was input, default to running all tests. Otherwise,
# construct the command to run the specific package/test case.
ifndef UNIT_TARGETED
UNIT := go list $(PKG)/... | grep -v '/vendor/' | xargs go test
else
UNIT := go test -test.v $(UNITPKG) $(UNITCASE)
endif
check: unit itest
itest: install
@echo "Running integration tests."
go test -v -tags rpctest -logoutput $(ITESTCASE)
unit:
@echo "Running unit tests."
$(UNIT)
# ==============================================================================
# UTILITIES
# ==============================================================================
fmt:
go fmt ./... $$(go list ./... | grep -v '/vendor/')
go list $(PKG)/... | grep -v '/vendor/' | xargs go fmt -x
test:
go test -v -p 1 $$(go list ./... | grep -v '/vendor/')
clean:
$(RM) ./lnd ./lncli
$(RM) -rf vendor
.PHONY: all deps build install scratch check itest unit fmt clean