diff --git a/Makefile b/Makefile index 61a4409df..a0a5762f9 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 @@ -200,7 +221,7 @@ uninstall: .PHONY: build build: - VERSION=$(VERSION) ./kmesh_compile.sh + VERSION=$(VERSION) BINARIES="$(BINARIES)" ./kmesh_compile.sh .PHONY: docker docker: build diff --git a/build.sh b/build.sh index 1d40a7b3e..3624768d4 100755 --- a/build.sh +++ b/build.sh @@ -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 + exit fi if [ "$1" == "-i" -o "$1" == "--install" ]; then diff --git a/hack/utils.sh b/hack/utils.sh index 2f7eaad63..b9c91b7ec 100644 --- a/hack/utils.sh +++ b/hack/utils.sh @@ -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" }