Browse Source

Add Makefile.

Provides targets for building, auto-formatting and testing (with and
without coverage).
Ian Adam Naval 5 years ago
parent
commit
4639a8c011
2 changed files with 58 additions and 2 deletions
  1. 1
    2
      .gitignore
  2. 57
    0
      Makefile

+ 1
- 2
.gitignore View File

@@ -1,3 +1,2 @@
1
-bin/
2
-pkg/
1
+cover/
3 2
 

+ 57
- 0
Makefile View File

@@ -0,0 +1,57 @@
1
+# Go parameters
2
+GOCMD=go
3
+GOBUILD=$(GOCMD) build
4
+GOCLEAN=$(GOCMD) clean
5
+GOINSTALL=$(GOCMD) install
6
+GOTEST=$(GOCMD) test
7
+GODEP=$(GOTEST) -i
8
+GOFMT=gofmt -w
9
+GOCOVER=$(GOCMD) tool cover
10
+COVER_DIR=cover
11
+
12
+# Package lists
13
+TOPLEVEL_PKG := jsh
14
+CMD_LIST := jsh/ps
15
+
16
+# List building
17
+ALL_LIST = $(TOPLEVEL_PKG) $(CMD_LIST)
18
+
19
+BUILD_LIST = $(foreach int, $(ALL_LIST), $(int)_build)
20
+CLEAN_LIST = $(foreach int, $(ALL_LIST), $(int)_clean)
21
+INSTALL_LIST = $(foreach int, $(ALL_LIST), $(int)_install)
22
+IREF_LIST = $(foreach int, $(ALL_LIST), $(int)_iref)
23
+TEST_LIST = $(foreach int, $(ALL_LIST), $(int)_test)
24
+COVER_LIST = $(foreach int, $(ALL_LIST), $(int)_cover)
25
+FMT_TEST = $(foreach int, $(ALL_LIST), $(int)_fmt)
26
+
27
+# All are .PHONY for now because dependencyness is hard
28
+.PHONY: $(CLEAN_LIST) $(TEST_LIST) $(FMT_LIST) $(INSTALL_LIST) $(BUILD_LIST) $(IREF_LIST)
29
+
30
+all: install
31
+build: $(BUILD_LIST)
32
+clean: $(CLEAN_LIST)
33
+	rm -rf $(COVER_DIR)
34
+install: $(INSTALL_LIST)
35
+test: $(TEST_LIST)
36
+cover: $(COVER_LIST)
37
+	echo "Output in directory: $(COVER_DIR)"
38
+iref: $(IREF_LIST)
39
+fmt: $(FMT_TEST)
40
+
41
+$(BUILD_LIST): %_build: %_fmt %_iref
42
+	$(GOBUILD) $*
43
+$(CLEAN_LIST): %_clean:
44
+	$(GOCLEAN) $*
45
+$(INSTALL_LIST): %_install: %_fmt %_iref
46
+	$(GOINSTALL) $*
47
+$(IREF_LIST): %_iref:
48
+	$(GODEP) $*
49
+$(TEST_LIST): %_test:
50
+	$(GOTEST) $*
51
+$(COVER_LIST): %_cover:
52
+	mkdir -p $(COVER_DIR)/$*
53
+	$(GOTEST) -coverprofile=$(COVER_DIR)/$*/c.out $*
54
+	$(GOCOVER) -html=$(COVER_DIR)/$*/c.out -o $(COVER_DIR)/$*/index.html
55
+	rm -f $*_c.out
56
+$(FMT_TEST): %_fmt:
57
+	[ -d ./$* ] && $(GOFMT) ./$* || $(GOFMT) .

Loading…
Cancel
Save