Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
== Build with Nix Add all the build dependencies to CI with Nix. Nix is not a requirement to build direnv but you need to do specify the dependencies yourself otherwise. == Allow to checkout direnv everywhere Handle our own GOPATH in the Makefile. direnv is still buildable with `go get github.com/direnv/direnv` but should also work if go is just installed in the system and the user checks out direnv anywhere and runs `make` == Better Travis-CI testing Test for more shells by default and also for formatting by default. Avoid unnecessary regressions. Some shells like tcsh are broken and will need to be fixed in the future. Test on Darwin == Format all the things stdlib.sh is formatted with shfmt == Misc Makefile: use lower-case variables. When a variable is not exported and not meant to be changed by the user, use lower-case variables Rename Makefile to GNUmakefile as it wasn't tested with the other make implementations. Ensure that bash is being used with make Replace usage of `which` with shell builtins when possible. add BINDIR and MANDIR to the Makefile
- Loading branch information
Showing
12 changed files
with
339 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
*.sw? | ||
.direnv | ||
.gopath | ||
/direnv | ||
/direnv.test | ||
/dist | ||
/site | ||
/test/allow | ||
/test/direnv | ||
/test/config/direnv/allow | ||
*.sw? | ||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
############################################################################ | ||
# Variables | ||
############################################################################ | ||
|
||
# Set this to change the target installation path | ||
DESTDIR ?= /usr/local | ||
BINDIR = ${DESTDIR}/bin | ||
MANDIR = ${DESTDIR}/share/man | ||
|
||
# Override the go executable | ||
GO = go | ||
|
||
# Change if you want to fork direnv | ||
PACKAGE = github.com/direnv/direnv | ||
|
||
# BASH_PATH can also be passed to hard-code the path to bash at build time | ||
|
||
SHELL = bash | ||
|
||
############################################################################ | ||
# Common | ||
############################################################################ | ||
|
||
.PHONY: all | ||
all: fmt build man | ||
|
||
export GOPATH = $(CURDIR)/.gopath | ||
export GO15VENDOREXPERIMENT=1 | ||
|
||
# Creates the GOPATH for us | ||
base = $(GOPATH)/src/$(PACKAGE) | ||
$(base): | ||
@mkdir -p "$(dir $@)" | ||
@ln -sf "$(CURDIR)" "$@" | ||
|
||
############################################################################ | ||
# Build | ||
############################################################################ | ||
|
||
.PHONY: build | ||
build: direnv | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf \ | ||
.gopath \ | ||
direnv | ||
|
||
GO_LDFLAGS = | ||
|
||
ifeq ($(shell uname), Darwin) | ||
# Fixes DYLD_INSERT_LIBRARIES issues | ||
# See https://github.com/direnv/direnv/issues/194 | ||
GO_LDFLAGS += -linkmode=external | ||
endif | ||
|
||
ifdef BASH_PATH | ||
GO_LDFLAGS += -X main.bashPath=$(BASH_PATH) | ||
endif | ||
|
||
ifdef GO_LDFLAGS | ||
GO_FLAGS += -ldflags '$(GO_LDFLAGS)' | ||
endif | ||
|
||
direnv: stdlib.go *.go | $(base) | ||
$(GO) fmt | ||
cd "$(base)" && $(GO) build $(GO_FLAGS) -o direnv | ||
|
||
stdlib.go: stdlib.sh | ||
cat $< | ./script/str2go main STDLIB $< > $@ | ||
|
||
version.go: version.txt | ||
echo package main > $@ | ||
echo 'const VERSION = "$(shell cat $<)";' >> $@ | ||
|
||
############################################################################ | ||
# Format all the things | ||
############################################################################ | ||
.PHONY: fmt fmt-go fmt-sh | ||
fmt: fmt-go fmt-sh | ||
|
||
fmt-go: | ||
go fmt | ||
|
||
fmt-sh: | ||
shfmt -i 2 -w stdlib.sh | ||
|
||
############################################################################ | ||
# Documentation | ||
############################################################################ | ||
|
||
man_md = $(wildcard man/*.md) | ||
roffs = $(man_md:.md=) | ||
|
||
.PHONY: man | ||
man: $(roffs) | ||
|
||
%.1: %.1.md | ||
@command -v go-md2man >/dev/null || (echo "Could not generate man page because go-md2man is missing. Run: go get -u github.com/cpuguy83/go-md2man"; false) | ||
go-md2man -in $< -out $@ | ||
|
||
############################################################################ | ||
# Testing | ||
############################################################################ | ||
|
||
tests = \ | ||
test-shellcheck \ | ||
test-go \ | ||
test-go-fmt \ | ||
test-bash \ | ||
test-elvish \ | ||
test-fish \ | ||
test-tcsh \ | ||
test-zsh | ||
|
||
.PHONY: $(tests) | ||
test: build $(tests) | ||
@echo | ||
@echo SUCCESS! | ||
|
||
test-go: | $(base) | ||
cd "$(base)" && $(GO) test -v ./... | ||
|
||
test-go-fmt: | ||
[ $$(go fmt | tee /dev/stderr | wc -l) = 0 ] | ||
|
||
test-shellcheck: | ||
shellcheck stdlib.sh | ||
|
||
test-bash: | ||
bash ./test/direnv-test.bash | ||
|
||
# Needs elvish 0.12+ | ||
test-elvish: | ||
elvish ./test/direnv-test.elv | ||
|
||
test-fish: | ||
fish ./test/direnv-test.fish | ||
|
||
test-tcsh: | ||
# Currently broken | ||
#tcsh -e ./test/direnv-test.tcsh | ||
|
||
test-zsh: | ||
# Currently missing | ||
#zsh ./test/direnv-test.zsh | ||
|
||
############################################################################ | ||
# Installation | ||
############################################################################ | ||
|
||
.PHONY: install | ||
install: all | ||
install -d $(BINDIR) | ||
install direnv $(BINDIR) | ||
install -d $(MANDIR)/man1 | ||
cp -R man/*.1 $(MANDIR)/man1 | ||
|
||
.PHONY: dist | ||
dist: | $(base) | ||
@command -v gox >/dev/null || (echo "Could not generate dist because gox is missing. Run: go get -u github.com/mitchellh/gox"; false) | ||
cd "$(base)" && gox -output "dist/direnv.{{.OS}}-{{.Arch}}" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,34 @@ | ||
{ pkgs ? import <nixpkgs> {} }: | ||
with pkgs; | ||
let | ||
elvish012 = elvish.overrideDerivation (self: { | ||
name = "elvis-0.12-rc2"; | ||
|
||
src = fetchFromGitHub { | ||
owner = "elves"; | ||
repo = "elvish"; | ||
rev = "0.12-rc2"; | ||
sha256 = "1nxijphdbqbv032s9mw7miypy92xdyzkql1bcqh0s1d0ghi66hvm"; | ||
}; | ||
|
||
excludedPackages = [ "github.com/elves/elvish/website" ]; | ||
}); | ||
in | ||
mkShell { | ||
buildInputs = [ | ||
gnumake | ||
go | ||
go-md2man | ||
gox | ||
shellcheck | ||
shfmt | ||
which | ||
|
||
# Shells | ||
bashInteractive | ||
elvish | ||
elvish012 | ||
fish | ||
go | ||
tcsh | ||
zsh | ||
]; | ||
|
||
shellHook = '' | ||
unset GOPATH | ||
''; | ||
} |
Oops, something went wrong.