Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 38 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,42 @@ APPS2 := mdacore
APPS3 := kmesh-cni
APPS4 := kmeshctl

ALL_BINARIES := $(APPS1) $(APPS2) $(APPS3) $(APPS4)

BINARIES ?= $(ALL_BINARIES)

INVALID_BINARIES := $(filter-out $(ALL_BINARIES), $(BINARIES))
ifneq ($(INVALID_BINARIES),)
$(error Invalid binaries: $(INVALID_BINARIES). Valid: $(ALL_BINARIES))
endif


.PHONY: configure-pkg-config
configure-pkg-config:
$(QUIET) find $(ROOT_DIR)/mk -name "*.pc" | xargs sed -i "s#^prefix=.*#prefix=${ROOT_DIR}#g"

# Individual binary build targets
.PHONY: build-kmesh-daemon build-mdacore build-kmesh-cni build-kmeshctl

build-kmesh-daemon: configure-pkg-config
$(call printlog, BUILD, $(APPS1))
$(QUIET) (export PKG_CONFIG_PATH=$(PKG_CONFIG_PATH):$(ROOT_DIR)mk; \
$(GO) build -ldflags $(LDFLAGS) -tags $(ENHANCED_KERNEL) -o $(APPS1) $(GOFLAGS) ./daemon/main.go)

build-mdacore: configure-pkg-config
$(call printlog, BUILD, $(APPS2))
$(QUIET) cd oncn-mda && cmake . -B build && make -C build

build-kmesh-cni: configure-pkg-config
$(call printlog, BUILD, $(APPS3))
$(QUIET) (export PKG_CONFIG_PATH=$(PKG_CONFIG_PATH):$(ROOT_DIR)mk; \
CGO_ENABLED=0 $(GO) build -ldflags $(GOLDFLAGS) -o $(APPS3) $(GOFLAGS) ./cniplugin/main.go)

build-kmeshctl: configure-pkg-config
$(call printlog, BUILD, $(APPS4))
$(QUIET) (export PKG_CONFIG_PATH=$(PKG_CONFIG_PATH):$(ROOT_DIR)mk; \
CGO_ENABLED=0 $(GO) build -ldflags $(GOLDFLAGS) -o $(APPS4) $(GOFLAGS) ./ctl/main.go)


# If the hub is not explicitly set, use default to kmesh-net.
HUB ?= ghcr.io/kmesh-net
Expand Down Expand Up @@ -102,22 +138,7 @@ kmesh-ko:
$(call printlog, BUILD, "kernel")
$(QUIET) make -C kernel/ko_src

all-binary:
$(QUIET) find $(ROOT_DIR)/mk -name "*.pc" | xargs sed -i "s#^prefix=.*#prefix=${ROOT_DIR}#g"
$(call printlog, BUILD, $(APPS1))
$(QUIET) (export PKG_CONFIG_PATH=$(PKG_CONFIG_PATH):$(ROOT_DIR)mk; \
$(GO) build -ldflags $(LDFLAGS) -tags $(ENHANCED_KERNEL) -o $(APPS1) $(GOFLAGS) ./daemon/main.go)

$(call printlog, BUILD, $(APPS2))
$(QUIET) cd oncn-mda && cmake . -B build && make -C build

$(call printlog, BUILD, $(APPS3))
$(QUIET) (export PKG_CONFIG_PATH=$(PKG_CONFIG_PATH):$(ROOT_DIR)mk; \
CGO_ENABLED=0 $(GO) build -ldflags $(GOLDFLAGS) -o $(APPS3) $(GOFLAGS) ./cniplugin/main.go)

$(call printlog, BUILD, $(APPS4))
$(QUIET) (export PKG_CONFIG_PATH=$(PKG_CONFIG_PATH):$(ROOT_DIR)mk; \
CGO_ENABLED=0 $(GO) build -ldflags $(GOLDFLAGS) -o $(APPS4) $(GOFLAGS) ./ctl/main.go)
all-binary: $(addprefix build-, $(BINARIES))

OUT ?= kmeshctl
.PHONY: kmeshctl
Expand Down Expand Up @@ -200,7 +221,7 @@ uninstall:

.PHONY: build
build:
VERSION=$(VERSION) ./kmesh_compile.sh
VERSION=$(VERSION) BINARIES="$(BINARIES)" ./kmesh_compile.sh

.PHONY: docker
docker: build
Expand Down
8 changes: 5 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ if [ "$1" == "-h" -o "$1" == "--help" ]; then
fi

if [ -z "$1" -o "$1" == "-b" -o "$1" == "--build" ]; then
prepare
make
exit
prepare
make kmesh-bpf
make kmesh-ko
make all-binary
Comment on lines +47 to +49

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The all target in the Makefile is defined as all: kmesh-bpf kmesh-ko all-binary. Replacing make (which defaults to make all) with explicit calls for each prerequisite makes this script harder to maintain. If the Makefile's all target changes, this script would need a corresponding manual update to avoid incomplete builds.

It's better to rely on the Makefile to orchestrate the build by using a single make or make all command.

Suggested change
make kmesh-bpf
make kmesh-ko
make all-binary
make all

exit
fi

if [ "$1" == "-i" -o "$1" == "--install" ]; then
Expand Down
4 changes: 2 additions & 2 deletions hack/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function get_arch() {
function build_kmesh() {
local container_id=$1
docker exec $container_id git config --global --add safe.directory /kmesh
docker exec -e VERSION=$VERSION $container_id sh /kmesh/build.sh
docker exec -e VERSION=$VERSION $container_id sh /kmesh/build.sh -i
docker exec -e VERSION=$VERSION -e "BINARIES=$BINARIES" $container_id sh /kmesh/build.sh
docker exec -e VERSION=$VERSION -e "BINARIES=$BINARIES" $container_id sh /kmesh/build.sh -i
docker exec $container_id sh -c "$(declare -f copy_to_host); copy_to_host"
}

Expand Down
Loading