-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathMakefile
More file actions
192 lines (154 loc) · 7.85 KB
/
Makefile
File metadata and controls
192 lines (154 loc) · 7.85 KB
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
# === This file is part of ALICE O² ===
#
# Copyright 2017-2020 CERN and copyright holders of ALICE O².
# Author: Teo Mrnjavac <teo.mrnjavac@cern.ch>
#
# Partially derived from Torus Makefile <https://github.com/coreos/torus>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# In applying this license CERN does not waive the privileges and
# immunities granted to it by virtue of its status as an
# Intergovernmental Organization or submit itself to any jurisdiction.
include VERSION
BUILD := `git rev-parse --short HEAD`
ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
HOST_GOOS=$(shell go env GOOS)
HOST_GOARCH=$(shell go env GOARCH)
CGO_LDFLAGS=
BUILD_FLAGS=$(BUILD_ENV_FLAGS)
ifdef WITH_LIBINFOLOGGER
CGO_LDFLAGS=CGO_LDFLAGS="$(ROOT_DIR)/vendor/infoLoggerForGo/infoLoggerForGo.a -static-libstdc++ -static-libgcc"
BUILD_FLAGS=$(CGO_LDFLAGS) $(BUILD_ENV_FLAGS)
endif
REPOPATH = github.com/AliceO2Group/Control
ODC_PROTO="https://raw.githubusercontent.com/FairRootGroup/ODC/master/grpc-proto/odc.proto"
DD_PROTO="https://raw.githubusercontent.com/AliceO2Group/DataDistribution/master/src/DataDistControl/DataDistControl.proto"
VERBOSE_1 := -v
VERBOSE_2 := -v -x
WHAT := o2-aliecs-core o2-aliecs-executor coconut peanut walnut o2-apricot
WHAT_o2-aliecs-core_BUILD_FLAGS=$(BUILD_ENV_FLAGS)
WHAT_o2-aliecs-executor_BUILD_FLAGS=$(BUILD_ENV_FLAGS)
WHAT_coconut_BUILD_FLAGS=$(BUILD_ENV_FLAGS)
WHAT_peanut_BUILD_FLAGS=$(BUILD_ENV_FLAGS)
WHAT_walnut_BUILD_FLAGS=$(BUILD_ENV_FLAGS)
WHAT_o2-apricot_BUILD_FLAGS=$(BUILD_ENV_FLAGS)
INSTALL_WHAT:=$(patsubst %, install_%, $(WHAT))
GENERATE_DIRS := ./apricot ./coconut/cmd ./common/runtype ./common/system ./core ./core/integration/ccdb ./core/integration/dcs ./core/integration/ddsched ./core/integration/odc ./executor ./walnut ./core/integration/trg
SRC_DIRS := ./apricot ./cmd/* ./core ./coconut ./executor ./common ./configuration ./occ/peanut ./walnut
# Use linker flags to provide version/build settings to the target
PROD :=-X=$(REPOPATH)/common/product
EXTLDFLAGS :="-static"
LDFLAGS=-ldflags "-extldflags $(EXTLDFLAGS) $(PROD).VERSION_MAJOR=$(VERSION_MAJOR) $(PROD).VERSION_MINOR=$(VERSION_MINOR) $(PROD).VERSION_PATCH=$(VERSION_PATCH) $(PROD).BUILD=$(BUILD)" -tags osusergo,netgo
# We expect to find the protoc-gen-go executable in $GOPATH/bin
GOPATH := $(shell go env GOPATH)
GOPROTOCPATH=$(ROOT_DIR)/tools/protoc-gen-go
HAS_PROTOC := $(shell command -v $(GOPROTOCPATH) 2> /dev/null)
.PHONY: build all install generate test debugtest vet fmt clean cleanall help $(WHAT) tools vendor doc docs
build: $(WHAT)
all: vendor generate build
install: $(INSTALL_WHAT)
# @for w in $(WHAT); do \
# FLAGS="WHAT_$${w}_BUILD_FLAGS"; \
# echo -e "${$${FLAGS}}"; \
# echo -e "\033[1;33mgo install\033[0m ./cmd/$$w \033[1;33m==>\033[0m \033[1;34m$$GOPATH/bin/$$w\033[0m"; \
# $(WHAT_$${w}_BUILD_FLAGS) go install $(VERBOSE_$(V)) $(LDFLAGS) ./cmd/$$w; \
# done
$(WHAT):
# @echo -e "WHAT_$@_BUILD_FLAGS $(WHAT_$@_BUILD_FLAGS)"
@echo -e "\033[1;33mgo build -mod=vendor\033[0m ./cmd/$@ \033[1;33m==>\033[0m \033[1;34m./bin/$@\033[0m"
# @echo ${PWD}
@$(WHAT_$@_BUILD_FLAGS) go build -mod=vendor $(VERBOSE_$(V)) -o bin/$@ $(LDFLAGS) ./cmd/$@
# special case: if the current WHAT is o2-aliecs-executor, also copy over the shmcleaner script
@if [ $@ == "o2-aliecs-executor" ]; then \
echo -e "\033[1;33mcopy\033[0m ./cmd/o2-aliecs-shmcleaner \033[1;33m==>\033[0m \033[1;34m./bin/o2-aliecs-shmcleaner\033[0m"; \
cp cmd/o2-aliecs-shmcleaner bin/o2-aliecs-shmcleaner; \
chmod +x bin/o2-aliecs-shmcleaner; \
fi; \
$(INSTALL_WHAT):
# @echo -e "WHAT_$(@:install_%=%)_BUILD_FLAGS $(WHAT_$(@:install_%=%)_BUILD_FLAGS)"
@echo -e "\033[1;33mgo install -mod=vendor\033[0m ./cmd/$(@:install_%=%) \033[1;33m==>\033[0m \033[1;34m$$GOPATH/bin/$(@:install_%=%)\033[0m"
# @echo ${PWD}
@$(WHAT_$(@:install_%=%)_BUILD_FLAGS) go install -mod=vendor $(VERBOSE_$(V)) $(LDFLAGS) ./cmd/$(@:install_%=%)
# special case: if the current WHAT is o2-aliecs-executor, also copy over the shmcleaner script
@if [ $@ == "install_o2-aliecs-executor" ]; then \
echo -e "\033[1;33minstall\033[0m ./cmd/o2-aliecs-shmcleaner \033[1;33m==>\033[0m \033[1;34m$$GOPATH/bin/o2-aliecs-shmcleaner\033[0m"; \
cp cmd/o2-aliecs-shmcleaner $${GOPATH}/bin/o2-aliecs-shmcleaner; \
chmod +x $${GOPATH}/bin/o2-aliecs-shmcleaner; \
fi; \
generate:
ifndef HAS_PROTOC
$(MAKE) tools/protoc
endif
@for gendir in $(GENERATE_DIRS); do \
echo -e "\033[1;33mgo generate\033[0m $$gendir"; \
PATH="$(ROOT_DIR)/tools:$$PATH" go generate $(VERBOSE_$(V)) $$gendir; \
done
test:
$(BUILD_FLAGS) go test -v --race $(SRC_DIRS) -ginkgo.progress
debugtest:
$(BUILD_FLAGS) go test -v --race $(SRC_DIRS) -ginkgo.v -ginkgo.trace -ginkgo.progress
vet:
go vet $(SRC_DIRS)
fmt:
go fmt $(SRC_DIRS)
clean:
@rm -rf ./bin/*
@echo -e "clean done: \033[1;34mbin\033[0m"
cleanall:
@rm -rf bin tools vendor
@echo -e "clean done: \033[1;34mbin tools vendor\033[0m"
vendor:
@echo -e "\033[1;33mgo mod vendor\033[0m"
@go mod vendor
# FIXME: these two protofiles should be committed in order to be available offline
@echo -e "\033[1;33mcurl odc.proto\033[0m"
@mkdir -p core/integration/odc/protos
@curl -s -L $(ODC_PROTO) -o core/integration/odc/protos/odc.proto
@echo -e "\033[1;33mcurl ddsched.proto\033[0m"
@mkdir -p core/integration/ddsched/protos
@curl -s -L $(DD_PROTO) -o core/integration/ddsched/protos/ddsched.proto
# WORKAROUND: In order to avoid the following issues:
# https://github.com/golang/protobuf/issues/992
# https://github.com/golang/protobuf/issues/1158
# we insert a go_package specification into the ODC protofile right
# after we download it.
@echo -e "\033[1;33mpatch odc.proto\033[0m"
@perl -pi -e '$$_.="option go_package = \"protos;odc\";\n" if (/^package/)' core/integration/odc/protos/odc.proto
# vendor: tools/dep
# @echo -e "\033[1;33mdep ensure\033[0m"
# @./tools/dep ensure
# @mkdir -p vendor/infoLoggerForGo
# @cp ${INFOLOGGER_ROOT}/lib/infoLoggerForGo.* vendor/infoLoggerForGo/
# For cgo, *.a means C, so by default it will use gcc when linking against it. For
# this reason, we must create a dummy *.cpp file in the package dir to force cgo to
# use g++ instead of gcc.
# @touch vendor/infoLoggerForGo/infoLoggerForGo.cpp
tools: tools/protoc
tools/protoc:
@echo "installing Protobuf tools"
@export GOBIN="$(ROOT_DIR)/tools" && cat common/tools/tools.go | grep _ | awk -F'"' '{print $$2}' | xargs -tI % go install -mod=readonly %
docs: doc
doc:
@echo -e "generating coconut documentation \033[1;33m==>\033[0m \033[1;34m./coconut/doc\033[0m"
@cd coconut/doc && go run . && cd ../..
@echo -e "generating gRPC API documentation \033[1;33m==>\033[0m \033[1;34m./docs\033[0m"
@cd apricot/protos && PATH="$(ROOT_DIR)/tools:$$PATH" protoc --doc_out="$(ROOT_DIR)/docs" --doc_opt=markdown,apidocs_apricot.md "apricot.proto"
@cd core/protos && PATH="$(ROOT_DIR)/tools:$$PATH" protoc --doc_out="$(ROOT_DIR)/docs" --doc_opt=markdown,apidocs_aliecs.md "o2control.proto"
@cd occ/protos && PATH="$(ROOT_DIR)/tools:$$PATH" protoc --doc_out="$(ROOT_DIR)/docs" --doc_opt=markdown,apidocs_occ.md "occ.proto"
help:
@echo "available make variables:"
@echo " V - Build verbosity {0,1,2}."
@echo " BUILD_ENV_FLAGS - Environment added to 'go build'."
@echo " WHAT - Command to build. (e.g. WHAT=o2-aliecs-core)"