forked from rexray/rexray
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
746 lines (590 loc) · 24.6 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
all:
$(MAKE) deps
$(MAKE) build
################################################################################
## CONSTANTS ##
################################################################################
# the name of the program being compiled. this word is in place of file names,
# directory paths, etc. changing the value of PROG is no guarantee everything
# continues to function.
PROG := rexray
EMPTY :=
SPACE := $(EMPTY) $(EMPTY)
ASTERIK := *
LPAREN := (
RPAREN := )
COMMA := ,
5S := $(SPACE)$(SPACE)$(SPACE)$(SPACE)$(SPACE)
# a list of the go 1.6 stdlib pacakges as grepped from https://golang.org/pkg/
GO_STDLIB := archive archive/tar archive/zip bufio builtin bytes compress \
compress/bzip2 compress/flate compress/gzip compress/lzw \
compress/zlib container container/heap container/list \
container/ring crypto crypto/aes crypto/cipher crypto/des \
crypto/dsa crypto/ecdsa crypto/elliptic crypto/hmac crypto/md5 \
crypto/rand crypto/rc4 crypto/rsa crypto/sha1 crypto/sha256 \
crypto/sha512 crypto/subtle crypto/tls crypto/x509 \
crypto/x509/pkix database database/sql database/sql/driver debug \
debug/dwarf debug/elf debug/gosym debug/macho debug/pe \
debug/plan9obj encoding encoding/ascii85 encoding/asn1 \
encoding/base32 encoding/base64 encoding/binary encoding/csv \
encoding/gob encoding/hex encoding/json encoding/pem encoding/xml \
errors expvar flag fmt go go/ast go/build go/constant go/doc \
go/format go/importer go/parser go/printer go/scanner go/token \
go/types hash hash/adler32 hash/crc32 hash/crc64 hash/fnv html \
html/template image image/color image/color/palette image/draw \
image/gif image/jpeg image/png index index/suffixarray io \
io/ioutil log log/syslog math math/big math/cmplx math/rand mime \
mime/multipart mime/quotedprintable net net/http net/http/cgi \
net/http/cookiejar net/http/fcgi net/http/httptest \
net/http/httputil net/http/pprof net/mail net/rpc net/rpc/jsonrpc \
net/smtp net/textproto net/url os os/exec os/signal os/user path \
path/filepath reflect regexp regexp/syntax runtime runtime/cgo \
runtime/debug runtime/msan runtime/pprof runtime/race \
runtime/trace sort strconv strings sync sync/atomic syscall \
testing testing/iotest testing/quick text text/scanner \
text/tabwriter text/template text/template/parse time unicode \
unicode/utf16 unicode/utf8 unsafe
################################################################################
## PROJECT INFO ##
################################################################################
GO_LIST_BUILD_INFO_CMD := go list -f '{{with $$ip:=.}}{{with $$ctx:=context}}{{printf "%s %s %s %s %s 0,%s" $$ip.ImportPath $$ip.Name $$ip.Dir $$ctx.GOOS $$ctx.GOARCH (join $$ctx.BuildTags ",")}}{{end}}{{end}}'
BUILD_INFO := $(shell $(GO_LIST_BUILD_INFO_CMD))
ROOT_IMPORT_PATH := $(word 1,$(BUILD_INFO))
ROOT_IMPORT_NAME := $(word 2,$(BUILD_INFO))
ROOT_DIR := $(word 3,$(BUILD_INFO))
GOOS ?= $(word 4,$(BUILD_INFO))
GOARCH ?= $(word 5,$(BUILD_INFO))
BUILD_TAGS := $(word 6,$(BUILD_INFO))
BUILD_TAGS := $(subst $(COMMA), ,$(BUILD_TAGS))
BUILD_TAGS := $(wordlist 2,$(words $(BUILD_TAGS)),$(BUILD_TAGS))
VENDORED := 0
ifneq (,$(strip $(findstring vendor,$(ROOT_IMPORT_PATH))))
VENDORED := 1
endif
################################################################################
## OS/ARCH INFO ##
################################################################################
ifeq ($(GOOS),windows)
OS ?= Windows_NT
endif
ifeq ($(GOOS),linux)
OS ?= Linux
endif
ifeq ($(GOOS),darwin)
OS ?= Darwin
endif
ifeq ($(GOARCH),386)
ARCH ?= i386
endif
ifeq ($(GOARCH),amd64)
ARCH ?= x86_64
endif
export OS
export ARCH
################################################################################
## MAKE FLAGS ##
################################################################################
ifeq (,$(MAKEFLAGS))
MAKEFLAGS := --no-print-directory
export $(MAKEFLAGS)
endif
################################################################################
## PROJECT DETAIL ##
################################################################################
GO_LIST_IMPORT_PATHS_INFO_CMD := go list -f '{{with $$ip:=.}}{{if $$ip.ImportPath | le "$(ROOT_IMPORT_PATH)"}}{{if $$ip.ImportPath | gt "$(ROOT_IMPORT_PATH)/vendor" }}{{printf "%s;%s;%s;%s;%v;0,%s,%s,%s,%s;0,%s;0,%s;0,%s" $$ip.ImportPath $$ip.Name $$ip.Dir $$ip.Target $$ip.Stale (join $$ip.GoFiles ",") (join $$ip.CgoFiles ",") (join $$ip.CFiles ",") (join $$ip.HFiles ",") (join $$ip.TestGoFiles ",") (join $$ip.Imports ",") (join $$ip.TestImports ",")}};{{end}}{{end}}{{end}}' ./...
IMPORT_PATH_INFO := $(shell $(GO_LIST_IMPORT_PATHS_INFO_CMD))
# this runtime ruleset acts as a pre-processor, processing the import path
# information completely before creating the build targets for the project
define IMPORT_PATH_PREPROCS_DEF
IMPORT_PATH_INFO_$1 := $$(subst ;, ,$2)
DIR_$1 := $1
IMPORT_PATH_$1 := $$(word 1,$$(IMPORT_PATH_INFO_$1))
NAME_$1 := $$(word 2,$$(IMPORT_PATH_INFO_$1))
TARGET_$1 := $$(word 4,$$(IMPORT_PATH_INFO_$1))
STALE_$1 := $$(word 5,$$(IMPORT_PATH_INFO_$1))
ifeq (1,$$(DEBUG))
$$(info name=$$(NAME_$1), target=$$(TARGET_$1), stale=$$(STALE_$1), dir=$$(DIR_$1))
endif
SRCS_$1 := $$(subst $$(COMMA), ,$$(word 6,$$(IMPORT_PATH_INFO_$1)))
SRCS_$1 := $$(wordlist 2,$$(words $$(SRCS_$1)),$$(SRCS_$1))
SRCS_$1 := $$(addprefix $$(DIR_$1)/,$$(SRCS_$1))
SRCS += $$(SRCS_$1)
ifneq (,$$(strip $$(SRCS_$1)))
PKG_A_$1 := $$(TARGET_$1)
PKG_D_$1 := $$(DIR_$1)/$$(NAME_$1).d
ALL_PKGS += $$(PKG_A_$1)
DEPS_$1 := $$(subst $$(COMMA), ,$$(word 8,$$(IMPORT_PATH_INFO_$1)))
DEPS_$1 := $$(wordlist 2,$$(words $$(DEPS_$1)),$$(DEPS_$1))
DEPS_$1 := $$(filter-out $$(GO_STDLIB),$$(DEPS_$1))
INT_DEPS_$1 := $$(filter-out $$(ROOT_IMPORT_PATH)/vendor/%,$$(DEPS_$1))
INT_DEPS_$1 := $$(filter $$(ROOT_IMPORT_PATH)%,$$(INT_DEPS_$1))
EXT_VENDORED_DEPS_$1 := $$(filter $$(ROOT_IMPORT_PATH)/vendor/%,$$(DEPS_$1))
EXT_DEPS_$1 := $$(filter-out $$(ROOT_IMPORT_PATH)%,$$(DEPS_$1))
EXT_DEPS_$1 += $$(EXT_VENDORED_DEPS_$1)
EXT_DEPS += $$(EXT_DEPS_$1)
EXT_DEPS_SRCS_$1 := $$(addprefix $$(GOPATH)/src/,$$(addsuffix /*.go,$$(EXT_DEPS_$1)))
EXT_DEPS_SRCS_$1 := $$(subst $$(GOPATH)/src/$$(ROOT_IMPORT_PATH)/vendor/,./vendor/,$$(EXT_DEPS_SRCS_$1))
ifneq (,$$(filter $$(GOPATH)/src/C/%,$$(EXT_DEPS_SRCS_$1)))
EXT_DEPS_SRCS_$1 := $$(filter-out $$(GOPATH)/src/C/%,$$(EXT_DEPS_SRCS_$1))
ifeq (main,$$(NAME_$1))
C_$1 := 1
endif
endif
EXT_DEPS_SRCS += $$(EXT_DEPS_SRCS_$1)
DEPS_ARKS_$1 := $$(addprefix $$(GOPATH)/pkg/$$(GOOS)_$$(GOARCH)/,$$(addsuffix .a,$$(INT_DEPS_$1)))
endif
TEST_SRCS_$1 := $$(subst $$(COMMA), ,$$(word 7,$$(IMPORT_PATH_INFO_$1)))
TEST_SRCS_$1 := $$(wordlist 2,$$(words $$(TEST_SRCS_$1)),$$(TEST_SRCS_$1))
TEST_SRCS_$1 := $$(addprefix $$(DIR_$1)/,$$(TEST_SRCS_$1))
TEST_SRCS += $$(TEST_SRCS_$1)
ifneq (,$$(strip $$(TEST_SRCS_$1)))
PKG_TA_$1 := $$(DIR_$1)/$$(NAME_$1).test
PKG_TD_$1 := $$(DIR_$1)/$$(NAME_$1).test.d
PKG_TC_$1 := $$(DIR_$1)/$$(NAME_$1).test.out
ALL_TESTS += $$(PKG_TA_$1)
-include $1/coverage.mk
TEST_COVERPKG_$1 ?= $$(IMPORT_PATH_$1)
TEST_DEPS_$1 := $$(subst $$(COMMA), ,$$(word 9,$$(IMPORT_PATH_INFO_$1)))
TEST_DEPS_$1 := $$(wordlist 2,$$(words $$(TEST_DEPS_$1)),$$(TEST_DEPS_$1))
TEST_DEPS_$1 := $$(filter-out $$(GO_STDLIB),$$(TEST_DEPS_$1))
TEST_INT_DEPS_$1 := $$(filter-out $$(ROOT_IMPORT_PATH)/vendor/%,$$(TEST_DEPS_$1))
TEST_INT_DEPS_$1 := $$(filter $$(ROOT_IMPORT_PATH)%,$$(TEST_INT_DEPS_$1))
TEST_EXT_VENDORED_DEPS_$1 := $$(filter $$(ROOT_IMPORT_PATH)/vendor/%,$$(TEST_DEPS_$1))
TEST_EXT_DEPS_$1 := $$(filter-out $$(ROOT_IMPORT_PATH)%,$$(TEST_DEPS_$1))
TEST_EXT_DEPS_$1 := $$(filter-out $$(GOPATH)/src/C/%,$$(TEST_EXT_DEPS_$1))
TEST_EXT_DEPS_$1 += $$(TEST_EXT_VENDORED_DEPS_$1)
TEST_EXT_DEPS += $$(TEST_EXT_DEPS_$1)
TEST_EXT_DEPS_SRCS_$1 := $$(addprefix $$(GOPATH)/src/,$$(addsuffix /*.go,$$(TEST_EXT_DEPS_$1)))
TEST_EXT_DEPS_SRCS_$1 := $$(subst $$(GOPATH)/src/$$(ROOT_IMPORT_PATH)/vendor/,./vendor/,$$(TEST_EXT_DEPS_SRCS_$1))
ifneq (,$$(filter $$(GOPATH)/src/C/%,$$(TEST_EXT_DEPS_SRCS_$1)))
TEST_EXT_DEPS_SRCS_$1 := $$(filter-out $$(GOPATH)/src/C/%,$$(TEST_EXT_DEPS_SRCS_$1))
ifeq (main,$$(NAME_$1))
TEST_C_$1 := 1
endif
endif
TEST_EXT_DEPS_SRCS += $$(TEST_EXT_DEPS_SRCS_$1)
TEST_DEPS_ARKS_$1 := $$(addprefix $$(GOPATH)/pkg/$$(GOOS)_$$(GOARCH)/,$$(addsuffix .a,$$(TEST_INT_DEPS_$1)))
endif
ALL_SRCS_$1 += $$(SRCS_$1) $$(TEST_SRCS_$1)
ALL_SRCS += $$(ALL_SRCS_$1)
endef
$(foreach i,\
$(IMPORT_PATH_INFO),\
$(eval $(call IMPORT_PATH_PREPROCS_DEF,$(subst $(ROOT_DIR),.,$(word 3,$(subst ;, ,$(i)))),$(i))))
################################################################################
## INFO ##
################################################################################
info:
$(info Project Import Path.........$(ROOT_IMPORT_PATH))
$(info Project Name................$(ROOT_IMPORT_NAME))
$(info OS / Arch...................$(GOOS)_$(GOARCH))
$(info Vendored....................$(VENDORED))
ifneq (,$(strip $(SRCS)))
$(info Sources.....................$(patsubst ./%,%,$(firstword $(SRCS))))
$(foreach s,$(patsubst ./%,%,$(wordlist 2,$(words $(SRCS)),$(SRCS))),\
$(info $(5S)$(5S)$(5S)$(5S)$(5S)$(SPACE)$(SPACE)$(SPACE)$(s)))
endif
ifneq (,$(strip $(TEST_SRCS)))
$(info Test Sources................$(patsubst ./%,%,$(firstword $(TEST_SRCS))))
$(foreach s,$(patsubst ./%,%,$(wordlist 2,$(words $(TEST_SRCS)),$(TEST_SRCS))),\
$(info $(5S)$(5S)$(5S)$(5S)$(5S)$(SPACE)$(SPACE)$(SPACE)$(s)))
endif
ifneq (,$(strip $(EXT_DEPS_SRCS)))
$(info Dependency Sources..........$(patsubst ./%,%,$(firstword $(EXT_DEPS_SRCS))))
$(foreach s,$(patsubst ./%,%,$(wordlist 2,$(words $(EXT_DEPS_SRCS)),$(EXT_DEPS_SRCS))),\
$(info $(5S)$(5S)$(5S)$(5S)$(5S)$(SPACE)$(SPACE)$(SPACE)$(s)))
endif
ifneq (,$(strip $(TEST_EXT_DEPS_SRCS)))
$(info Test Dependency Sources.....$(patsubst ./%,%,$(firstword $(TEST_EXT_DEPS_SRCS))))
$(foreach s,$(patsubst ./%,%,$(wordlist 2,$(words $(TEST_EXT_DEPS_SRCS)),$(TEST_EXT_DEPS_SRCS))),\
$(info $(5S)$(5S)$(5S)$(5S)$(5S)$(SPACE)$(SPACE)$(SPACE)$(s)))
endif
################################################################################
## DEPENDENCIES ##
################################################################################
GLIDE := $(GOPATH)/bin/glide
GO_BINDATA := $(GOPATH)/bin/go-bindata
GOGET_LOCK := goget.lock
GLIDE_LOCK := glide.lock
GLIDE_YAML := glide.yaml
GLIDE_LOCK_D := glide.lock.d
EXT_DEPS := $(sort $(EXT_DEPS))
EXT_DEPS_SRCS := $(sort $(EXT_DEPS_SRCS))
TEST_EXT_DEPS := $(sort $(TEST_EXT_DEPS))
TEST_EXT_DEPS_SRCS := $(sort $(TEST_EXT_DEPS_SRCS))
ALL_EXT_DEPS := $(sort $(EXT_DEPS) $(TEST_EXT_DEPS))
ALL_EXT_DEPS_SRCS := $(sort $(EXT_DEPS_SRCS) $(TEST_EXT_DEPS_SRCS))
ifneq (1,$(VENDORED))
$(GLIDE):
go get github.com/Masterminds/glide
GO_DEPS += $(GLIDE_LOCK_D)
$(ALL_EXT_DEPS_SRCS): $(GLIDE_LOCK_D)
$(GLIDE_LOCK_D): $(GLIDE_LOCK) | $(GLIDE)
$(GLIDE) install && touch $@
$(GLIDE_LOCK): $(GLIDE_YAML)
touch $@
$(GLIDE_LOCK)-clean:
rm -f $(GLIDE_LOCK)
GO_PHONY += $(GLIDE_LOCK)-clean
GO_CLOBBER += $(GLIDE_LOCK)-clean
endif
GO_BINDATA_IMPORT_PATH := vendor/github.com/jteeuwen/go-bindata/go-bindata
ifneq (1,$(VENDORED))
GO_BINDATA_IMPORT_PATH := $(ROOT_IMPORT_PATH)/$(GO_BINDATA_IMPORT_PATH)
else
GO_BINDATA_IMPORT_PATH := $(firstword $(subst /vendor/, ,$(ROOT_IMPORT_PATH)))/$(GO_BINDATA_IMPORT_PATH)
endif
ifneq (1,$(VENDORED))
$(GO_BINDATA): $(GLIDE_LOCK_D)
endif
$(GO_BINDATA):
GOOS=$(GOOS) GOARCH=$(GOARCH) go install $(GO_BINDATA_IMPORT_PATH)
@touch $@
GO_DEPS += $(GO_BINDATA)
################################################################################
## VERSION ##
################################################################################
# parse a semver
SEMVER_PATT := ^[^\d]*(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z].+?))?(?:-(\d+)-g(.+?)(?:-(dirty))?)?$$
PARSE_SEMVER = $(shell echo $(1) | perl -pe 's/$(SEMVER_PATT)/$(2)/gim')
# describe the git information and create a parsing function for it
GIT_DESCRIBE := $(shell git describe --long --dirty)
PARSE_GIT_DESCRIBE = $(call PARSE_SEMVER,$(GIT_DESCRIBE),$(1))
# parse the version components from the git information
V_MAJOR := $(call PARSE_GIT_DESCRIBE,$$1)
V_MINOR := $(call PARSE_GIT_DESCRIBE,$$2)
V_PATCH := $(call PARSE_GIT_DESCRIBE,$$3)
V_NOTES := $(call PARSE_GIT_DESCRIBE,$$4)
V_BUILD := $(call PARSE_GIT_DESCRIBE,$$5)
V_SHA_SHORT := $(call PARSE_GIT_DESCRIBE,$$6)
V_DIRTY := $(call PARSE_GIT_DESCRIBE,$$7)
V_OS := $(OS)
V_ARCH := $(ARCH)
V_OS_ARCH := $(V_OS)-$(V_ARCH)
# the long commit hash
V_SHA_LONG := $(shell git show HEAD -s --format=%H)
# the branch name, possibly from travis-ci
ifeq ($(origin TRAVIS_BRANCH), undefined)
TRAVIS_BRANCH := $(shell git branch | grep '*')
else
ifeq (,$(strip $(TRAVIS_BRANCH)))
TRAVIS_BRANCH := $(shell git branch | grep '*')
endif
endif
TRAVIS_BRANCH := $(subst $(ASTERIK) ,,$(TRAVIS_BRANCH))
TRAVIS_BRANCH := $(subst $(LPAREN)HEAD detached at ,,$(TRAVIS_BRANCH))
TRAVIS_BRANCH := $(subst $(RPAREN),,$(TRAVIS_BRANCH))
ifeq ($(origin TRAVIS_TAG), undefined)
TRAVIS_TAG := $(TRAVIS_BRANCH)
else
ifeq ($(strip $(TRAVIS_TAG)),)
TRAVIS_TAG := $(TRAVIS_BRANCH)
endif
endif
V_BRANCH := $(TRAVIS_TAG)
# the build date as an epoch
V_EPOCH := $(shell date +%s)
# the build date
V_BUILD_DATE := $(shell perl -e 'use POSIX strftime; print strftime("%a, %d %b %Y %H:%M:%S %Z", localtime($(V_EPOCH)))')
# the release date as required by bintray
V_RELEASE_DATE := $(shell perl -e 'use POSIX strftime; print strftime("%Y-%m-%d", localtime($(V_EPOCH)))')
# init the semver
V_SEMVER := $(V_MAJOR).$(V_MINOR).$(V_PATCH)
ifneq ($(V_NOTES),)
V_SEMVER := $(V_SEMVER)-$(V_NOTES)
endif
# get the version file's version
V_FILE := $(strip $(shell cat VERSION 2> /dev/null))
# append the build number and dirty values to the semver if appropriate
ifneq ($(V_BUILD),)
ifneq ($(V_BUILD),0)
# if the version file's version is different than the version parsed from the
# git describe information then use the version file's version
ifneq ($(V_SEMVER),$(V_FILE))
V_MAJOR := $(call PARSE_SEMVER,$(V_FILE),$$1)
V_MINOR := $(call PARSE_SEMVER,$(V_FILE),$$2)
V_PATCH := $(call PARSE_SEMVER,$(V_FILE),$$3)
V_NOTES := $(call PARSE_SEMVER,$(V_FILE),$$4)
V_SEMVER := $(V_MAJOR).$(V_MINOR).$(V_PATCH)
ifneq ($(V_NOTES),)
V_SEMVER := $(V_SEMVER)-$(V_NOTES)
endif
endif
V_SEMVER := $(V_SEMVER)+$(V_BUILD)
endif
endif
ifeq ($(V_DIRTY),dirty)
V_SEMVER := $(V_SEMVER)+$(V_DIRTY)
endif
# the rpm version cannot have any dashes
V_RPM_SEMVER := $(subst -,+,$(V_SEMVER))
define CORE_GENERATED_CONTENT
package core
import (
"fmt"
"runtime"
"time"
apitypes "github.com/emccode/libstorage/api/types"
)
func init() {
Version = &apitypes.VersionInfo{}
Version.Arch = fmt.Sprintf("%s-%s", os(runtime.GOOS), arch(runtime.GOARCH))
Version.Branch = "$(V_BRANCH)"
Version.BuildTimestamp = time.Unix($(V_EPOCH), 0)
Version.SemVer = "$(V_SEMVER)"
Version.ShaLong = "$(V_SHA_LONG)"
}
endef
export CORE_GENERATED_CONTENT
PRINTF_VERSION_CMD += @printf "SemVer: %s\nBinary: %s\nBranch: %s\nCommit:
PRINTF_VERSION_CMD += %s\nFormed: %s\n" "$(V_SEMVER)" "$(V_OS_ARCH)"
PRINTF_VERSION_CMD += "$(V_BRANCH)" "$(V_SHA_LONG)" "$(V_BUILD_DATE)"
CORE_GENERATED_SRC := ./core/core_generated.go
$(CORE_GENERATED_SRC):
echo generating $@
@echo "$$CORE_GENERATED_CONTENT" > $@
$(CORE_GENERATED_SRC)-clean:
rm -f $(CORE_GENERATED_SRC)
GO_CLEAN += $(CORE_GENERATED_SRC)-clean
GO_PHONY += $(CORE_GENERATED_SRC)-clean
CORE_A := $(GOPATH)/pkg/$(GOOS)_$(GOARCH)/$(ROOT_IMPORT_PATH)/core.a
$(CORE_A): $(CORE_GENERATED_SRC)
version:
$(PRINTF_VERSION_CMD)
GO_PHONY += version
################################################################################
## PROJECT BUILD ##
################################################################################
define IMPORT_PATH_BUILD_DEF
ifneq (,$$(strip $$(SRCS_$1)))
ifneq (1,$$(C_$1))
DEPS_SRCS_$1 := $$(foreach d,$$(INT_DEPS_$1),$$(SRCS_.$$(subst $$(ROOT_IMPORT_PATH),,$$(d))))
$$(PKG_D_$1): $$(filter-out %_generated.go,$$(SRCS_$1))
$$(file >$$@,$$(PKG_A_$1) $$(PKG_D_$1): $$(filter-out %_generated.go,$$(DEPS_SRCS_$1)))
-include $$(PKG_D_$1)
$$(PKG_D_$1)-clean:
rm -f $$(PKG_D_$1)
GO_CLEAN += $$(PKG_D_$1)-clean
$$(PKG_A_$1): $$(EXT_DEPS_SRCS_$1) $$(SRCS_$1) | $$(DEPS_ARKS_$1)
GOOS=$(GOOS) GOARCH=$(GOARCH) go install $1
ifeq (true,$$(STALE_$1))
GO_PHONY += $$(PKG_A_$1)
endif
$$(PKG_A_$1)-clean:
go clean -i -x $1 && rm -f $$(PKG_A_$1)
GO_BUILD += $$(PKG_A_$1)
GO_CLEAN += $$(PKG_A_$1)-clean
endif
endif
################################################################################
## PROJECT TESTS ##
################################################################################
ifneq (,$$(strip $$(TEST_SRCS_$1)))
ifneq (1,$$(TEST_C_$1))
TEST_DEPS_SRCS_$1 := $$(foreach d,$$(TEST_INT_DEPS_$1),$$(SRCS_.$$(subst $$(ROOT_IMPORT_PATH),,$$(d))))
$$(PKG_TD_$1): $$(filter-out %_generated.go,$$(TEST_SRCS_$1))
$$(file >$$@,$$(PKG_TA_$1) $$(PKG_TD_$1): $$(filter-out %_generated.go,$$(TEST_DEPS_SRCS_$1)))
$$(PKG_TD_$1)-clean:
rm -f $$(PKG_TD_$1)
GO_CLEAN += $$(PKG_TD_$1)-clean
-include $$(PKG_TD_$1)
ifneq (,$$(strip $$(PKG_A_$1)))
$$(PKG_TA_$1): $$(PKG_A_$1)
ifeq (true,$$(STALE_$1))
GO_PHONY += $$(PKG_TA_$1)
endif
endif
ifneq (,$$(strip $$(SRCS_$1)))
$$(PKG_TA_$1): $$(SRCS_$1)
endif
$$(PKG_TA_$1): $$(TEST_SRCS_$1) $$(TEST_EXT_DEPS_SRCS_$1) | $$(TEST_DEPS_ARKS_$1)
go test -cover -coverpkg '$$(TEST_COVERPKG_$1)' -c -o $$@ $1
$$(PKG_TA_$1)-clean:
rm -f $$(PKG_TA_$1)
GO_PHONY += $$(PKG_TA_$1)-clean
GO_CLEAN += $$(PKG_TA_$1)-clean
$$(PKG_TC_$1): $$(PKG_TA_$1)
$$(PKG_TA_$1) -test.coverprofile $$@ $$(GO_TEST_FLAGS)
TEST_PROFILES += $$(PKG_TC_$1)
$$(PKG_TC_$1)-clean:
rm -f $$(PKG_TC_$1)
GO_PHONY += $$(PKG_TC_$1)-clean
GO_TEST += $$(PKG_TC_$1)
GO_BUILD_TESTS += $$(PKG_TA_$1)
GO_CLEAN += $$(PKG_TC_$1)-clean
endif
endif
endef
$(foreach i,\
$(IMPORT_PATH_INFO),\
$(eval $(call IMPORT_PATH_BUILD_DEF,$(subst $(ROOT_DIR),.,$(word 3,$(subst ;, ,$(i)))),$(i))))
################################################################################
## COVERAGE ##
################################################################################
COVERAGE := coverage.out
GO_COVERAGE := $(COVERAGE)
$(COVERAGE): $(TEST_PROFILES)
printf "mode: set\n" > $@
$(foreach f,$?,grep -v "mode: set" $(f) >> $@ &&) true
$(COVERAGE)-clean:
rm -f $(COVERAGE)
GO_CLEAN += $(COVERAGE)-clean
GO_PHONY += $(COVERAGE)-clean
codecov: $(COVERAGE)
ifneq (1,$(CODECOV_OFFLINE))
curl -sSL https://codecov.io/bash | bash -s -- -f $?
else
@echo codecov offline
endif
################################################################################
## LIBSTORAGE ##
################################################################################
LIBSTORAGE_DIR := vendor/github.com/emccode/libstorage
LIBSTORAGE_API := $(LIBSTORAGE_DIR)/api/api_generated.go
LIBSTORAGE_LSX := $(LIBSTORAGE_DIR)/api/server/executors/executors_generated.go
$(LIBSTORAGE_API) $(LIBSTORAGE_LSX):
cd $(LIBSTORAGE_DIR) && $(MAKE) $(subst $(LIBSTORAGE_DIR)/,,$@) && cd -
build-libstorage: $(LIBSTORAGE_API) $(LIBSTORAGE_LSX)
################################################################################
## CLI ##
################################################################################
CLI := $(shell go list -f '{{.Target}}' ./$(PROG))
CLI_LINUX := $(shell env GOOS=linux go list -f '{{.Target}}' ./$(PROG))
CLI_DARWIN := $(shell env GOOS=darwin go list -f '{{.Target}}' ./$(PROG))
CLI_WINDOWS := $(shell env GOOS=windows go list -f '{{.Target}}' ./$(PROG))
build-cli-linux: $(CLI_LINUX)
build-cli-darwin: $(CLI_DARWIN)
build-cli-windows: $(CLI_WINDOWS)
define CLI_RULES
ifneq ($2,$$(GOOS))
$1:
env GOOS=$2 GOARCH=amd64 $$(MAKE) $$@
$1-clean:
rm -f $1
GO_PHONY += $1-clean
GO_CLEAN += $1-clean
endif
CLI_BINS += $1
endef
$(eval $(call CLI_RULES,$(CLI_LINUX),linux))
$(eval $(call CLI_RULES,$(CLI_DARWIN),darwin))
build-cli: $(CLI_BINS)
################################################################################
## TGZ ##
################################################################################
define TGZ_RULES
TGZ_$1 := $(PROG)-$1-$$(ARCH)-$$(V_SEMVER).tar.gz
$$(TGZ_$1): $2
tar -czf $$@ -C $$(dir $$?) $(PROG)
$$(TGZ_$1)-clean:
rm -f $$(TGZ_$1)
GO_PHONY += $$(TGZ_$1)-clean
GO_CLEAN += $$(TGZ_$1)-clean
TGZ += $$(TGZ_$1)
endef
$(eval $(call TGZ_RULES,Linux,$(CLI_LINUX)))
$(eval $(call TGZ_RULES,Darwin,$(CLI_DARWIN)))
build-tgz: $(TGZ)
################################################################################
## RPM ##
################################################################################
RPMDIR := .rpm
RPM := $(PROG)-$(V_RPM_SEMVER)-1.$(V_ARCH).rpm
$(RPM)-clean:
rm -f $(RPM)
GO_PHONY += $(RPM)-clean
GO_CLEAN += $(RPM)-clean
$(RPM): $(CLI_LINUX)
rm -fr $(RPMDIR)
mkdir -p $(RPMDIR)/BUILD \
$(RPMDIR)/RPMS \
$(RPMDIR)/SRPMS \
$(RPMDIR)/SPECS \
$(RPMDIR)/SOURCES \
$(RPMDIR)/tmp
cp rpm.spec $(RPMDIR)/SPECS/$(PROG).spec
cd $(RPMDIR) && \
setarch $(V_ARCH) rpmbuild -ba \
-D "rpmbuild $(abspath $(RPMDIR))" \
-D "v_semver $(V_RPM_SEMVER)" \
-D "v_arch $(V_ARCH)" \
-D "$(PROG) $?" \
SPECS/$(PROG).spec
mv $(RPMDIR)/RPMS/$(V_ARCH)/$(RPM) $@
build-rpm: $(RPM)
################################################################################
## ALIEN ##
################################################################################
ALIEN_HOME := $(HOME)/.opt/alien/8.86
ALIEN_PKG := alien_8.86_all.deb
ALIEN_URL := http://archive.ubuntu.com/ubuntu/pool/main/a/alien/$(ALIEN_PKG)
ALIEN := $(ALIEN_HOME)/usr/bin/alien
$(ALIEN):
wget $(ALIEN_URL)
mkdir -p $(ALIEN_HOME)
dpkg -X $(ALIEN_PKG) $(ALIEN_HOME)
rm -f $(ALIEN_PKG)
touch $@
PATH := $(ALIEN_HOME)/usr/bin:$(PATH)
PERL5LIB := $(ALIEN_HOME)/usr/share/perl5:$(PERL5LIB)
export PATH
export PERL5LIB
################################################################################
## DEB ##
################################################################################
DEB := $(PROG)_$(V_RPM_SEMVER)-1_$(GOARCH).deb
$(DEB)-clean:
rm -f $(DEB)
GO_PHONY += $(DEB)-clean
GO_CLEAN += $(DEB)-clean
$(DEB): $(RPM) | $(ALIEN)
fakeroot $(ALIEN) -k -c --bump=0 $?
build-deb: $(DEB)
################################################################################
## BINTRAY ##
################################################################################
BINTRAY_SUBJ ?= emccode
BINTRAY_JSON := bintray.json
BINTRAY_UNSTABLE := bintray-unstable.json
BINTRAY_STAGED := bintray-staged.json
BINTRAY_STABLE := bintray-stable.json
$(BINTRAY_UNSTABLE) $(BINTRAY_STAGED) $(BINTRAY_STABLE): $(BINTRAY_JSON)
sed -e 's/$${SUBJ}/$(BINTRAY_SUBJ)/g' \
-e 's/$${PROG}/$(PROG)/g' \
-e 's/$${REPO}/$(subst bintray-,,$(subst .json,,$@))/g' \
-e 's/$${SEMVER}/$(V_SEMVER)/g' \
-e 's|$${DSCRIP}|$(V_SEMVER).Branch.$(V_BRANCH).Sha.$(V_SHA_LONG)|g' \
-e 's/$${RELDTE}/$(V_RELEASE_DATE)/g' \
$? > $@
bintray: $(BINTRAY_UNSTABLE) $(BINTRAY_STAGED) $(BINTRAY_STABLE)
bintray-clean:
rm -f bintray-*.json
GO_PHONY += bintray-clean
GO_CLEAN += bintray-clean
################################################################################
## TARGETS ##
################################################################################
deps: $(GO_DEPS)
build-tests: $(GO_BUILD_TESTS)
build-$(PROG): $(GO_BUILD)
build-generated:
$(MAKE) $(CORE_GENERATED_SRC)
build:
$(MAKE) build-libstorage
$(MAKE) build-generated
$(MAKE) build-$(PROG)
cli: build-cli
tgz: build-tgz
rpm: build-rpm
deb: build-deb
pkg: build
$(MAKE) tgz rpm deb
pkg-clean:
rm -f $(PROG)*.tar.gz && rm -f *.rpm && rm -f *.deb
test: $(GO_TEST)
test-debug:
env REXRAY_DEBUG=true $(MAKE) test
cover: codecov
clean: $(GO_CLEAN) pkg-clean
clobber: clean $(GO_CLOBBER)
.PHONY: info clean clobber $(GO_PHONY)