-
Notifications
You must be signed in to change notification settings - Fork 50
/
Makefile
1115 lines (908 loc) · 37 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
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
SHELL := /bin/bash
GO_VERSION := 1.8
ifeq (undefined,$(origin BUILD_TAGS))
BUILD_TAGS := gofig \
pflag \
libstorage_integration_driver_linux
ifneq (true,$(TRAVIS))
BUILD_TAGS += libstorage_storage_driver \
libstorage_storage_driver_vfs \
libstorage_storage_executor \
libstorage_storage_executor_vfs
endif
endif
ifneq (,$(DRIVERS))
BUILD_TAGS += libstorage_storage_driver libstorage_storage_executor
BUILD_TAGS += $(foreach d,$(DRIVERS),libstorage_storage_driver_$(d) libstorage_storage_executor_$(d))
endif
ifneq (,$(BUILD_TAGS))
BUILD_TAGS := $(sort $(BUILD_TAGS))
endif
all:
# if docker is running, then let's use docker to build it
ifneq (,$(shell if docker version &> /dev/null; then echo -; fi))
$(MAKE) docker-build
else
$(MAKE) deps
$(MAKE) build
endif
################################################################################
## DOCKER ##
################################################################################
ifneq (,$(shell if docker version &> /dev/null; then echo -; fi))
DPKG := github.com/codedellemc/libstorage
DIMG := golang:$(GO_VERSION)
DGOHOSTOS := $(shell uname -s | tr A-Z a-z)
ifeq (undefined,$(origin DGOOS))
DGOOS := $(DGOHOSTOS)
endif
DGOARCH := amd64
DPRFX := build-libstorage
DNAME := $(DPRFX)
ifeq (1,$(DBUILD_ONCE))
DNAME := $(DNAME)-$(shell date +%s)
endif
DPATH := /go/src/$(DPKG)
DSRCS := $(shell git ls-files)
ifneq (,$(DGLIDE_YAML))
DSRCS := $(filter-out glide.yaml,$(DSRCS))
DSRCS := $(filter-out glide.lock,$(DSRCS))
DSRCS := $(filter-out glide.lock.d,$(DSRCS))
endif
DPROG1_NAME := lss-$(DGOOS)
DPROG1_PATH := /go/bin/$(DPROG1_NAME)
DPROG2_NAME := lsx-$(DGOOS)
DPROG2_PATH := /go/bin/$(DPROG2_NAME)
ifneq (linux,$(DGOOS))
DPROG1_PATH := /go/bin/$(DGOOS)_$(DGOARCH)/$(DPROG1_NAME)
DPROG2_PATH := /go/bin/$(DGOOS)_$(DGOARCH)/$(DPROG2_NAME)
endif
ifeq (darwin,$(DGOHOSTOS))
DTARC := -
endif
DIMG_EXISTS := docker images --format '{{.Repository}}:{{.Tag}}' | grep $(DIMG) &> /dev/null
DTO_CLOBBER := docker ps -a --format '{{.Names}}' | grep $(DPRFX)
DNETRC := $(HOME)/.netrc
# DLOCAL_IMPORTS specifics a list of imported packages to copy into the
# container build's vendor directory instead of what is specified in the
# glide.lock file. If this variable is set and the GOPATH variable is not
# then the target will fail.
ifeq (undefined,$(DLOCAL_IMPORTS))
DLOCAL_IMPORTS :=
endif
ifneq (,$(DLOCAL_IMPORTS))
ifneq (,$(GOPATH))
DLOCAL_IMPORTS_FILES := $(foreach I,$(DLOCAL_IMPORTS),$(addprefix $I/,$(shell git --git-dir=$(GOPATH)/src/$(I)/.git --work-tree=$(GOPATH)/src/$(I) ls-files)))
DLOCAL_IMPORTS_FILES += $(foreach I,$(DLOCAL_IMPORTS),$I/.git)
endif
endif
docker-init:
@if ! $(DIMG_EXISTS); then docker pull $(DIMG); fi
@docker run --name $(DNAME) -d $(DIMG) /sbin/init -D &> /dev/null || true && \
docker exec $(DNAME) mkdir -p $(DPATH) && \
tar -c $(DTARC) .git $(DSRCS) | docker cp - $(DNAME):$(DPATH)
ifneq (,$(DGLIDE_YAML))
@docker cp $(DGLIDE_YAML) $(DNAME):$(DPATH)/glide.yaml
endif
ifneq (,$(wildcard $(DNETRC)))
@docker cp $(DNETRC) $(DNAME):/root
endif
docker exec -t $(DNAME) env make -C $(DPATH) deps
ifneq (,$(DLOCAL_IMPORTS))
ifeq (,$(GOPATH))
@echo GOPATH must be set when using DLOCAL_IMPORTS && false
else
@docker exec -t $(DNAME) rm -fr $(addprefix $(DPATH)/vendor/,$(DLOCAL_IMPORTS))
@tar -C $(GOPATH)/src -c $(DTARC) $(DLOCAL_IMPORTS_FILES) | docker cp - $(DNAME):$(DPATH)/vendor
endif
endif
docker exec -t $(DNAME) \
env BUILD_TAGS="$(BUILD_TAGS)" GOOS=$(DGOOS) GOARCH=$(DGOARCH) DOCKER=1 \
make -C $(DPATH) -j build
docker-build: docker-init
@docker cp $(DNAME):$(DPROG1_PATH) $(DPROG1_NAME)
@docker cp $(DNAME):$(DPROG2_PATH) $(DPROG2_NAME)
@bytes=$$(stat --format '%s' $(DPROG1_NAME) 2> /dev/null || \
stat -f '%z' $(DPROG1_NAME) 2> /dev/null) && mb=$$(($$bytes / 1024 / 1024)) && \
printf "\nThe $(DPROG1_NAME) binary is $${mb}MB and located at: \n\n" && \
printf " ./$(DPROG1_NAME)\n\n"
@bytes=$$(stat --format '%s' $(DPROG2_NAME) 2> /dev/null || \
stat -f '%z' $(DPROG2_NAME) 2> /dev/null) && mb=$$(($$bytes / 1024 / 1024)) && \
printf "\nThe $(DPROG2_NAME) binary is $${mb}MB and located at: \n\n" && \
printf " ./$(DPROG2_NAME)\n\n"
ifeq (1,$(DBUILD_ONCE))
docker stop $(DNAME) &> /dev/null && docker rm $(DNAME) &> /dev/null
endif
docker-test: DGOOS=linux
docker-test: DTEST_ENV_VARS=TRAVIS=true LIBSTORAGE_DISABLE_STARTUP_INFO=true
docker-test: docker-init
docker exec -t $(DNAME) \
env BUILD_TAGS="$(BUILD_TAGS)" $(DTEST_ENV_VARS) \
make -C $(DPATH) test
docker-clean:
-docker stop $(DNAME) &> /dev/null && docker rm $(DNAME) &> /dev/null
docker-clobber:
-CNAMES=$$($(DTO_CLOBBER)); if [ "$$CNAMES" != "" ]; then \
docker stop $$CNAMES && docker rm $$CNAMES; \
fi
docker-list:
-$(DTO_CLOBBER)
endif # ifneq (,$(shell if docker version &> /dev/null; then echo -; fi))
################################################################################
## CONSTANTS ##
################################################################################
ifneq (,$(shell which go 2> /dev/null)) # if go exists
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
################################################################################
## SYSTEM INFO ##
################################################################################
GOPATH := $(shell go env | grep GOPATH | sed 's/GOPATH="\(.*\)"/\1/')
GOHOSTOS := $(shell go env | grep GOHOSTOS | sed 's/GOHOSTOS="\(.*\)"/\1/')
GOHOSTARCH := $(shell go env | grep GOHOSTARCH | sed 's/GOHOSTARCH="\(.*\)"/\1/')
ifneq (,$(TRAVIS_GO_VERSION))
GOVERSION := $(TRAVIS_GO_VERSION)
else
GOVERSION := $(shell go version | awk '{print $$3}' | cut -c3-)
endif
ifeq ($(GO_VERSION),$(TRAVIS_GO_VERSION))
ifeq (linux,$(TRAVIS_OS_NAME))
COVERAGE_ENABLED := 1
endif
endif
# explicitly enable vendoring for Go 1.5.x versions.
GO15VENDOREXPERIMENT := 1
ifneq (,$(strip $(findstring 1.3.,$(TRAVIS_GO_VERSION))))
PRE_GO15 := 1
endif
ifneq (,$(strip $(findstring 1.4.,$(TRAVIS_GO_VERSION))))
PRE_GO15 := 1
endif
ifneq (1,$(PRE_GO15))
export GO15VENDOREXPERIMENT
endif
################################################################################
## PATH ##
################################################################################
export PATH := $(GOPATH)/bin:$(PATH)
################################################################################
## 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}}'
ifneq (,$(BUILD_TAGS))
GO_LIST_BUILD_INFO_CMD += -tags "$(BUILD_TAGS)"
endif
BUILD_INFO := $(shell $(GO_LIST_BUILD_INFO_CMD))
ROOT_IMPORT_PATH := $(word 1,$(BUILD_INFO))
ROOT_IMPORT_PATH_NV := $(ROOT_IMPORT_PATH)
ROOT_IMPORT_NAME := $(word 2,$(BUILD_INFO))
ROOT_DIR := $(word 3,$(BUILD_INFO))
GOOS ?= $(word 4,$(BUILD_INFO))
GOARCH ?= $(word 5,$(BUILD_INFO))
VENDORED := 0
ifneq (,$(strip $(findstring vendor,$(ROOT_IMPORT_PATH))))
VENDORED := 1
ROOT_IMPORT_PATH_NV := $(shell echo $(ROOT_IMPORT_PATH) | sed 's/.*vendor\///g')
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}}'
ifneq (,$(BUILD_TAGS))
GO_LIST_IMPORT_PATHS_INFO_CMD += -tags "$(BUILD_TAGS)"
endif
GO_LIST_IMPORT_PATHS_INFO_CMD += ./...
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))
ifeq (1,$(VENDORED))
$(info No Vendor Import Path.......$(ROOT_IMPORT_PATH_NV))
endif
$(info Project Name................$(ROOT_IMPORT_NAME))
$(info OS / Arch...................$(GOOS)_$(GOARCH))
$(info Build Tags..................$(BUILD_TAGS))
$(info Vendored....................$(VENDORED))
$(info GOPATH......................$(GOPATH))
$(info GOHOSTOS....................$(GOHOSTOS))
$(info GOHOSTARCH..................$(GOHOSTARCH))
$(info GOVERSION...................$(GOVERSION))
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
GLIDE_VER := 0.11.1
GLIDE_TGZ := glide-v$(GLIDE_VER)-$(GOHOSTOS)-$(GOHOSTARCH).tar.gz
GLIDE_URL := https://github.com/Masterminds/glide/releases/download/v$(GLIDE_VER)/$(GLIDE_TGZ)
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):
@curl -SLO $(GLIDE_URL) && \
tar xzf $(GLIDE_TGZ) && \
rm -f $(GLIDE_TGZ) && \
mkdir -p $(GOPATH)/bin && \
mv $(GOHOSTOS)-$(GOHOSTARCH)/glide $(GOPATH)/bin && \
rm -fr $(GOHOSTOS)-$(GOHOSTARCH)
glide: $(GLIDE)
GO_DEPS += $(GLIDE)
GO_DEPS += $(GLIDE_LOCK_D)
$(ALL_EXT_DEPS_SRCS): $(GLIDE_LOCK_D)
ifeq (,$(strip $(wildcard $(GLIDE_LOCK))))
$(GLIDE_LOCK_D): $(GLIDE_LOCK) | $(GLIDE)
touch $@
$(GLIDE_LOCK): $(GLIDE_YAML)
$(GLIDE) up
else #ifeq (,$(strip $(wildcard $(GLIDE_LOCK))))
$(GLIDE_LOCK_D): $(GLIDE_LOCK) | $(GLIDE)
$(GLIDE) install && touch $@
$(GLIDE_LOCK): $(GLIDE_YAML)
$(GLIDE) up && touch $@ && touch $(GLIDE_LOCK_D)
endif #ifeq (,$(strip $(wildcard $(GLIDE_LOCK))))
$(GLIDE_YAML):
$(GLIDE) init
$(GLIDE_LOCK)-clean:
rm -f $(GLIDE_LOCK)
GO_PHONY += $(GLIDE_LOCK)-clean
GO_CLOBBER += $(GLIDE_LOCK)-clean
endif #ifneq (1,$(VENDORED))
################################################################################
## GOBINDATA ##
################################################################################
GO_BINDATA := $(GOPATH)/bin/go-bindata
go-bindata: $(GO_BINDATA)
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)
################################################################################
## GOMETALINTER ##
################################################################################
ifeq (1,$(PRE_GO15))
GOMETALINTER_DISABLED := 1
endif
ifneq (1,$(GOMETALINTER_DISABLED))
GOMETALINTER := $(GOPATH)/bin/gometalinter
$(GOMETALINTER): | $(GOMETALINTER_TOOLS)
go get -u github.com/alecthomas/gometalinter
gometalinter: $(GOMETALINTER)
GO_DEPS += $(GOMETALINTER)
GOMETALINTER_TOOLS_D := .gometalinter.tools.d
$(GOMETALINTER_TOOLS_D): $(GOMETALINTER)
$(GOMETALINTER) --install --update && touch $@
GO_DEPS += $(GOMETALINTER_TOOLS_D)
GOMETALINTER_ARGS := --vendor \
--fast \
--tests \
--cyclo-over=16 \
--deadline=30s \
--enable=gofmt \
--enable=goimports \
--enable=misspell \
--enable=lll \
--disable=gotype \
--severity=gofmt:error \
--severity=goimports:error \
--exclude=_generated.go \
--linter='gofmt:gofmt -l ./*.go:^(?P<path>[^\n]+)$''
gometalinter-warn: | $(GOMETALINTER_TOOLS_D) $(GLIDE)
-$(GOMETALINTER) $(GOMETALINTER_ARGS) $(shell $(GLIDE) nv)
gometalinter-error: | $(GOMETALINTER_TOOLS_D) $(GLIDE)
$(GOMETALINTER) $(GOMETALINTER_ARGS) --errors $(shell $(GLIDE) nv)
gometalinter-all:
ifeq (1,$(GOMETALINTER_WARN_ENABLED))
$(MAKE) gometalinter-warn
endif
$(MAKE) gometalinter-error
else
gometalinter-all:
@echo gometalinter disabled
endif
################################################################################
## VERSION ##
################################################################################
# figure out the git dirs
GIT_WORK:=.
GIT_ROOT:=.git
ifeq (1,$(VENDORED))
ifneq (,$(wildcard $(HOME)/.glide))
ROOT_IMPORT_PATH_DASH:=$(subst /,-,$(ROOT_IMPORT_PATH_NV))
VGIT_WORK:=$(shell find $(HOME)/.glide -name "*$(ROOT_IMPORT_PATH_DASH)" -type d)
ifneq (,$(wildcard $(VGIT_WORK)))
GIT_WORK:=$(VGIT_WORK)
ifneq (,$(wildcard $(VGIT_WORK)/.git))
GIT_ROOT:=$(VGIT_WORK)/.git
endif
endif
endif
endif
# 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 --git-dir="$(GIT_ROOT)" --work-tree="$(GIT_WORK)" 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 --git-dir="$(GIT_ROOT)" --work-tree="$(GIT_WORK)" show HEAD -s --format=%H)
# the branch name, possibly from travis-ci
ifeq ($(origin TRAVIS_BRANCH), undefined)
TRAVIS_BRANCH := $(shell git --git-dir="$(GIT_ROOT)" --work-tree="$(GIT_WORK)" branch | grep '*')
else
ifeq (,$(strip $(TRAVIS_BRANCH)))
TRAVIS_BRANCH := $(shell git --git-dir="$(GIT_ROOT)" --work-tree="$(GIT_WORK)" 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
define API_GENERATED_CONTENT
package api
import (
"time"
"github.com/codedellemc/libstorage/api/types"
)
func init() {
Version = &types.VersionInfo{}
Version.Arch = "$(V_OS_ARCH)"
Version.Branch = "$(V_BRANCH)"
Version.BuildTimestamp = time.Unix($(V_EPOCH), 0)
Version.SemVer = "$(V_SEMVER)"
Version.ShaLong = "$(V_SHA_LONG)"
}
endef
export API_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)"
API_GENERATED_SRC := ./api/api_generated.go
$(API_GENERATED_SRC):
echo generating $@
@echo "$$API_GENERATED_CONTENT" > $@
$(API_GENERATED_SRC)-clean:
rm -f $(API_GENERATED_SRC)
GO_CLEAN += $(API_GENERATED_SRC)-clean
GO_PHONE += $(API_GENERATED_SRC)-clean
API_A := $(GOPATH)/pkg/$(GOOS)_$(GOARCH)/$(ROOT_IMPORT_PATH)/api.a
$(API_A): $(API_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)
ifeq (,$$(BUILD_TAGS))
GOOS=$(GOOS) GOARCH=$(GOARCH) go install $1
else
GOOS=$(GOOS) GOARCH=$(GOARCH) go install -tags "$$(BUILD_TAGS)" $1
endif
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)
ifeq (,$$(BUILD_TAGS))
go test -cover -coverpkg '$$(TEST_COVERPKG_$1)' -c -o $$@ $1
else
go test -cover -coverpkg '$$(TEST_COVERPKG_$1)' -tags "$$(BUILD_TAGS)" -c -o $$@ $1
endif
$$(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))))
################################################################################
## SCHEMA ##
################################################################################
LIBSTORAGE_JSON := libstorage.json
LIBSTORAGE_SCHEMA_GENERATED := api/utils/schema/schema_generated.go
LIBSTORAGE_SCHEMA_A := $(GOPATH)/pkg/$(GOOS)_$(GOARCH)/$(ROOT_IMPORT_PATH)/api/utils/schema.a
$(LIBSTORAGE_SCHEMA_A): $(LIBSTORAGE_SCHEMA_GENERATED)
$(LIBSTORAGE_SCHEMA_GENERATED): $(LIBSTORAGE_JSON)
@echo generating $@
@printf "package schema\n\nconst (\n" >$@; \
printf "\t// JSONSchema is the libStorage API JSON schema\n" >>$@; \
printf "\tJSONSchema = \`" >>$@; \
sed -e 's/^//' $< >>$@; \
printf "\`\n)\n" >>$@;
################################################################################
## EXECUTORS ##
################################################################################
EXECUTOR := $(shell go list -f '{{.Target}}' ./cli/lsx/lsx-$(GOOS))
EXECUTOR_LINUX := $(shell env GOOS=linux go list -f '{{.Target}}' ./cli/lsx/lsx-linux)
EXECUTOR_DARWIN := $(shell env GOOS=darwin go list -f '{{.Target}}' ./cli/lsx/lsx-darwin)
EXECUTOR_WINDOWS := $(shell env GOOS=windows go list -f '{{.Target}}' ./cli/lsx/lsx-windows)
build-executor-linux: $(EXECUTOR_LINUX)
build-executor-darwin: $(EXECUTOR_DARWIN)
build-executor-windows: $(EXECUTOR_WINDOWS)
EXECUTORS_GENERATED := ./api/server/executors/executors_generated.go
API_SERVER_EXECUTORS_A := $(GOPATH)/pkg/$(GOOS)_$(GOARCH)/$(ROOT_IMPORT_PATH)/api/server/executors.a
define EXECUTOR_RULES
LSX_EMBEDDED_$2 := ./api/server/executors/bin/$$(notdir $1)
ifneq ($2,$$(GOOS))
$1:
BUILD_TAGS="$$(BUILD_TAGS)" GOOS=$2 GOARCH=amd64 $$(MAKE) $$@
$1-clean:
rm -f $1
rm -f $(EXECUTORS_GENERATED)
GO_PHONY += $1-clean
GO_CLEAN += $1-clean
endif
$$(LSX_EMBEDDED_$2): $1
@mkdir -p $$(@D) && cp -f $$? $$@
ifeq (linux,$2)
EXECUTORS_EMBEDDED += $$(LSX_EMBEDDED_$2)
endif
ifeq (darwin,$2)
ifeq (1,$$(EMBED_EXECUTOR_DARWIN))
EXECUTORS_EMBEDDED += $$(LSX_EMBEDDED_$2)
endif
endif
endef
$(eval $(call EXECUTOR_RULES,$(EXECUTOR_LINUX),linux))
$(eval $(call EXECUTOR_RULES,$(EXECUTOR_DARWIN),darwin))
#$(eval $(call EXECUTOR_RULES,$(EXECUTOR_WINDOWS),windows))
$(EXECUTORS_GENERATED): $(EXECUTORS_EMBEDDED)
$(GO_BINDATA) -md5checksum -pkg executors -prefix $(@D)/bin -o $@ $(@D)/bin/...
$(EXECUTORS_GENERATED)-clean:
rm -fr $(dir $(EXECUTORS_GENERATED))/bin
GO_PHONY += $(EXECUTORS_GENERATED)-clean
GO_CLEAN += $(EXECUTORS_GENERATED)-clean
$(API_SERVER_EXECUTORS_A): $(EXECUTORS_GENERATED)
################################################################################
## C ##
################################################################################
CC := gcc -Wall -pedantic -std=c99
ifneq (,$(wildcard /usr/include))
CC += -I/usr/include
endif
################################################################################
## C CLIENT ##
################################################################################
C_LIBSTOR_DIR := ./c
C_LIBSTOR_C_DIR := $(C_LIBSTOR_DIR)/libstor-c
C_LIBSTOR_C_SO := $(GOPATH)/pkg/$(GOOS)_$(GOARCH)/$(ROOT_IMPORT_PATH)/c/libstor-c.so
C_LIBSTOR_C_BIN := $(GOPATH)/bin/libstor-c
C_LIBSTOR_C_BIN_SRC := $(C_LIBSTOR_DIR)/libstor-c.c
C_LIBSTOR_C_GO_DEPS := $(GOPATH)/pkg/$(GOOS)_$(GOARCH)/$(ROOT_IMPORT_PATH)/api/types.a \
$(GOPATH)/pkg/$(GOOS)_$(GOARCH)/$(ROOT_IMPORT_PATH)/client.a \
libstor-c: $(C_LIBSTOR_C_SO) $(C_LIBSTOR_C_BIN)
$(C_LIBSTOR_C_SO): $(EXT_DEPS_SRCS_./c/libstor-c) \
$(SRCS_./c/libstor-c) | $(DEPS_ARKS_./c/libstor-c)
ifeq (,$(BUILD_TAGS))
go build -buildmode=c-shared -o $@ $(C_LIBSTOR_C_DIR)
else
go build -tags "$(BUILD_TAGS)" -buildmode=c-shared -o $@ $(C_LIBSTOR_C_DIR)
endif
$(C_LIBSTOR_C_SO)-clean:
rm -f $(C_LIBSTOR_C_SO) $(basename $(C_LIBSTOR_C_SO).h)
GO_PHONY += $(C_LIBSTOR_C_SO)-clean
GO_CLEAN += $(C_LIBSTOR_C_SO)-clean
$(C_LIBSTOR_C_BIN): $(C_LIBSTOR_C_BIN_SRC) \
$(C_LIBSTOR_C_SO) \
$(C_LIBSTOR_C_GO_DEPS)
$(CC) -I$(abspath $(C_LIBSTOR_C_DIR)) \
-I$(dir $(C_LIBSTOR_C_SO)) \
-L$(dir $(C_LIBSTOR_C_SO)) \
-o $@ \
$(C_LIBSTOR_C_BIN_SRC) \
-lstor-c
################################################################################
## C SERVER ##
################################################################################
C_LIBSTOR_S_DIR := $(C_LIBSTOR_DIR)/libstor-s
C_LIBSTOR_S_SO := $(GOPATH)/pkg/$(GOOS)_$(GOARCH)/$(ROOT_IMPORT_PATH)/c/libstor-s.so
C_LIBSTOR_S_BIN := $(GOPATH)/bin/libstor-s
C_LIBSTOR_S_BIN_SRC := $(C_LIBSTOR_DIR)/libstor-s.c
C_LIBSTOR_S_GO_DEPS := $(GOPATH)/pkg/$(GOOS)_$(GOARCH)/$(ROOT_IMPORT_PATH)/api/server.a
libstor-s: $(C_LIBSTOR_S_BIN) $(C_LIBSTOR_S_SO)
$(C_LIBSTOR_S_SO): $(EXT_DEPS_SRCS_./c/libstor-s) \
$(SRCS_./c/libstor-s) | $(DEPS_ARKS_./c/libstor-s)
ifeq (,$(BUILD_TAGS))
go build -buildmode=c-shared -o $@ $(C_LIBSTOR_S_DIR)
else
go build -tags "$(BUILD_TAGS)" -buildmode=c-shared -o $@ $(C_LIBSTOR_S_DIR)
endif
$(C_LIBSTOR_S_SO)-clean:
rm -f $(C_LIBSTOR_S_SO) $(basename $(C_LIBSTOR_S_SO).h)
GO_PHONY += $(C_LIBSTOR_S_SO)-clean
GO_CLEAN += $(C_LIBSTOR_S_SO)-clean
$(C_LIBSTOR_S_BIN): $(C_LIBSTOR_TYPES_H) \
$(C_LIBSTOR_S_BIN_SRC) \
$(C_LIBSTOR_S_SO) \
$(C_LIBSTOR_S_GO_DEPS)
$(CC) -I$(abspath $(C_LIBSTOR_DIR)) \
-I$(dir $(C_LIBSTOR_S_SO)) \
-L$(dir $(C_LIBSTOR_S_SO)) \
-o $@ \
$(C_LIBSTOR_S_BIN_SRC) \
-lstor-s
################################################################################
## SERVERS ##
################################################################################
LSS_BIN := $(shell go list -f '{{.Target}}' ./cli/lss/lss-$(GOOS))
LSS_ALL += $(LSS_BIN)
LSS_LINUX := $(shell env GOOS=linux go list -f '{{.Target}}' ./cli/lss/lss-linux)
LSS_DARWIN := $(shell env GOOS=darwin go list -f '{{.Target}}' ./cli/lss/lss-darwin)
LSS_WINDOWS := $(shell env GOOS=windows go list -f '{{.Target}}' ./cli/lss/lss-windows)
build-lss-linux: $(LSS_LINUX)
build-lss-darwin: $(LSS_DARWIN)
build-lss-windows: $(LSS_WINDOWS)
define LSS_RULES
ifneq ($2,$$(GOOS))
$1:
BUILD_TAGS="$$(BUILD_TAGS)" GOOS=$2 GOARCH=amd64 $$(MAKE) $$@
$1-clean:
rm -f $1
GO_PHONY += $1-clean
GO_CLEAN += $1-clean
endif
LSS_ALL += $1
endef
#$(eval $(call LSS_RULES,$(LSS_LINUX),linux))