Skip to content

Commit

Permalink
ci: cmake Makefile fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizux committed Sep 22, 2023
1 parent d1b6127 commit 16dc087
Showing 1 changed file with 40 additions and 17 deletions.
57 changes: 40 additions & 17 deletions cmake/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,31 @@ help:
@echo -e "\te.g. 'make alpine_cpp_build'"
@echo -e "\te.g. 'make archlinux_cpp_build'"
@echo
@echo -e "\tBuild using docker buildx with a platform specified."
@echo -e "\t${BOLD}<platform>_<stage>${RESET}: build <stage> docker images for ALL DISTROS."
@echo -e "\t${BOLD}<platform>_<distro>_<stage>${RESET}: build <stage> docker image for a specific distro."
@echo -e "\t${BOLD}save_<platform>_<stage>${RESET}: Save <stage> docker images for ALL DISTROS."
@echo -e "\t${BOLD}save_<platform>_<distro>_<stage>${RESET}: Save the <stage> docker image for a specific distro."
@echo -e "\t${BOLD}sh_<platform>_<distro>_<stage>${RESET}: run a container using the <stage> docker image specified (debug purpose)."
@echo -e "\t${BOLD}clean_<platform>_<distro>_<stage>${RESET}: Remove cache and docker image."
@echo -e "\t${BOLD}clean_platforms${RESET}: Remove ALL cache and docker image."
@echo
@echo -e "\tWith ${BOLD}<platform>${RESET}:"
@echo -e "\t\t${BOLD}amd64${RESET}: linux/amd64 (x86_64)"
@echo -e "\t\t${BOLD}386${RESET}: linux/386 (x86)"
@echo -e "\t\t${BOLD}arm${RESET}: linux/arm (armv7)"
@echo -e "\t\t${BOLD}arm64${RESET}: linux/arm64 (aarch64, arm64v8)"
@echo -e "\t\t${BOLD}mips${RESET}: linux/mips (mips 32bits)"
@echo -e "\t\t${BOLD}mipsle${RESET}: linux/mipsle (mips 32bits Little Endian)"
@echo -e "\t\t${BOLD}mips64${RESET}: linux/mips64 (mips 64bits)"
@echo -e "\t\t${BOLD}mips64le${RESET}: linux/mips64le (mips 64bits Little Endian)"
@echo -e "\t\t${BOLD}ppc64${RESET}: linux/ppc64 (PowerPC 64Bits)"
@echo -e "\t\t${BOLD}ppc64le${RESET}: linux/ppc64le (PowerPC 64Bits Little Endian)"
@echo -e "\t\t${BOLD}riscv64${RESET}: linux/riscv64 (RISC-V 64bits)"
@echo -e "\t\t${BOLD}s390x${RESET}: linux/s390x (IBM System/390x)"
@echo -e "\te.g. 'make amd64_ubuntu_test'"
@echo -e "\tDocker image unavailable: arm64_archlinux"
@echo
@echo -e "\tBuild using a toolchain."
@echo -e "\t${BOLD}<toolchain>_<toolchain_stage>${RESET}: build <stage> docker image for a specific toolchain target."
@echo -e "\t${BOLD}save_<toolchain>_<toolchain_stage>${RESET}: Save the <stage> docker image for a specific platform."
Expand Down Expand Up @@ -112,7 +137,6 @@ help:
@echo
@echo -e "\tGlobal targets."
@echo -e "\t${BOLD}clean${RESET}: Remove ALL caches and docker images."
@echo -e "\t${BOLD}clean_<distro>${RESET}: Remove cache and docker image for the specified distro."
@echo -e "\t${BOLD}distclean${RESET}: Remove everything."
@echo
@echo -e "\t${BOLD}NOCACHE=1${RESET}: use 'docker build --no-cache' when building container (default use cache)."
Expand Down Expand Up @@ -153,7 +177,6 @@ DOCKER_RUN_CMD := docker run --rm --init --net=host

# Currently supported distro
DISTROS := alpine archlinux centos debian fedora opensuse ubuntu system_deps
LANGUAGES := cpp python java dotnet

# $* stem
# $< first prerequist
Expand Down Expand Up @@ -204,6 +227,7 @@ $(foreach prestage,$(PRESTAGES),$(eval $(call make-prestage-target,$(prestage)))
############
## STAGES ##
############
LANGUAGES := cpp python java dotnet
STAGES := env devel build test install_env install_devel install_build install_test

define make-stage-target =
Expand Down Expand Up @@ -361,16 +385,16 @@ PLATFORMS := \
riscv64

define make-platform-prestage-target =
#$$(info PLATFORM: '$1' PRESTAGE: '$2')
#$$(info Create targets: $1_all_$2 $(addprefix $1_, $(addsuffix _$2, $(DISTROS))).)
$$(info PLATFORM: '$1' PRESTAGE: '$2')
$$(info Create targets: $1_all_$2 $(addprefix $1_, $(addsuffix _$2, $(DISTROS))).)
targets_$1_$2 = $(addprefix $1_, $(addsuffix _$2, $(DISTROS)))
.PHONY: $1_all_$2 $$(targets_$1_$2)
$1_all_$2: $$(targets_$1_$2)
$$(targets_$1_$2): $1_%_$2: docker/%/Dockerfile
#@docker image rm -f ${IMAGE}:$1_$$*_$2 2>/dev/null
${DOCKER_BUILDX_CMD} --platform linux/$1 --target=$2 --tag ${IMAGE}:$1_$$*_$2 -f $$< ..

#$$(info Create targets: save_$1_all_$2 $(addprefix save_$1_, $(addsuffix _$2, $(DISTROS))) (debug).)
$$(info Create targets: save_$1_all_$2 $(addprefix save_$1_, $(addsuffix _$2, $(DISTROS))) (debug).)
save_targets_$1_$2 = $(addprefix save_$1_, $(addsuffix _$2, $(DISTROS)))
.PHONY: save_$1_all_$2 $$(save_targets_$1_$2)
save_$1_all_$2: $$(save_targets_$1_$2)
Expand All @@ -380,13 +404,13 @@ cache/$1/%/docker_$2.tar: $1_%_$2
mkdir -p cache/$1/$$*
docker save ${IMAGE}:$1_$$*_$2 -o $$@

#$$(info Create targets: $(addprefix sh_$1_, $(addsuffix _$2, $(DISTROS))) (debug).)
$$(info Create targets: $(addprefix sh_$1_, $(addsuffix _$2, $(DISTROS))) (debug).)
sh_targets_$1_$2 = $(addprefix sh_$1_, $(addsuffix _$2, $(DISTROS)))
.PHONY: $$(sh_targets_$1_$2)
$$(sh_targets_$1_$2): sh_$1_%_$2: $1_%_$2
${DOCKER_RUN_CMD} --platform linux/$1 -it --name ${PROJECT}_${BUILD_SYSTEM}_$1_$$*_$2 ${IMAGE}:$1_$$*_$2

#$$(info Create targets: clean_$1_all_$2 $(addprefix clean_$1_, $(addsuffix _$2, $(DISTROS))).)
$$(info Create targets: clean_$1_all_$2 $(addprefix clean_$1_, $(addsuffix _$2, $(DISTROS))).)
clean_targets_$1_$2 = $(addprefix clean_$1_, $(addsuffix _$2, $(DISTROS)))
.PHONY: clean_$1_all_$2 $$(clean_targets_$1_$2)
clean_$1_all_$2: $$(clean_targets_$1_$2)
Expand All @@ -396,14 +420,14 @@ $$(clean_targets_$1_$2): clean_$1_%_$2:
endef

define make-platform-stage-target =
#$$(info PLATFORM: '$1' STAGE: '$2')
#$$(info Create targets: $1_all_$2 $(addprefix $1_, $(addsuffix _$2, $(DISTROS))).)
$$(info PLATFORM: '$1' STAGE: '$2')
$$(info Create targets: $1_all_$2 $(addprefix $1_, $(addsuffix _$2, $(DISTROS))).)
targets_$1_$2 = $(addprefix $1_, $(addsuffix _$2, $(DISTROS)))
.PHONY: $1_all_$2 $$(targets_$1_$2)
$1_all_$2: $$(targets_$1_$2)
$$(targets_$1_$2): $1_%_$2: $(addprefix $1_%_, $(addsuffix _$2, $(LANGUAGES)))

#$$(info Create targets: $(addprefix $1_, $(addsuffix _$2, $(LANGUAGES))).)
$$(info Create targets: $(addprefix $1_, $(addsuffix _$2, $(LANGUAGES))).)
targets_$1_$2 = $(addprefix $1_, $(addsuffix _$2, $(LANGUAGES)))
.PHONY: $$(targets_$1_$2)
$$(targets_$1_$2): $1_%_$2: $(addprefix $1_, $(addsuffix _$2, $(addsuffix _%, $(DISTROS))))
Expand Down Expand Up @@ -493,7 +517,7 @@ $$(java_targets_$1_$2): sh_$1_%_java_$2: $1_%_java_$2
$$(python_targets_$1_$2): sh_$1_%_python_$2: $1_%_python_$2
${DOCKER_RUN_CMD} -it --name ${PROJECT}_${BUILD_SYSTEM}_$1_$$*_python_$2 ${IMAGE}:$1_$$*_python_$2

#$$(info Create targets: clean_all_$1_$2 $(addprefix clean_$1_, $(addsuffix _$2, $(DISTROS))).)
$$(info Create targets: clean_all_$1_$2 $(addprefix clean_$1_, $(addsuffix _$2, $(DISTROS))).)
targets_$1_$2 = $(addprefix clean_$1_, $(addsuffix _$2, $(DISTROS)))
.PHONY: clean_all_$1_$2 $(targets_$1_$2)
clean_all_$1_$2: $$(targets_$1_$2)
Expand All @@ -505,13 +529,13 @@ targets_$1_$2 = $(addprefix clean_$1_, $(addsuffix _$2, $(LANGUAGES)))
$$(targets_$1_$2): clean_$1_%_$2: $(addprefix clean_$1_, $(addsuffix _%_$2, $(DISTROS)))

#$$(info Create targets: $(addprefix clean_$1_, $(addsuffix _cpp_$2, $(DISTROS))))
cpp_targets_$1_$2 = $(addprefix clean_, $(addsuffix _cpp_$2, $(DISTROS)))
cpp_targets_$1_$2 = $(addprefix clean_$1_, $(addsuffix _cpp_$2, $(DISTROS)))
#$$(info Create targets: $(addprefix clean_, $(addsuffix _dotnet_$2, $(DISTROS))))
dotnet_targets_$1_$2 = $(addprefix clean_, $(addsuffix _dotnet_$2, $(DISTROS)))
dotnet_targets_$1_$2 = $(addprefix clean_$1_, $(addsuffix _dotnet_$2, $(DISTROS)))
#$$(info Create targets: $(addprefix clean_, $(addsuffix _java_$2, $(DISTROS))))
java_targets_$1_$2 = $(addprefix clean_, $(addsuffix _java_$2, $(DISTROS)))
java_targets_$1_$2 = $(addprefix clean_$1_, $(addsuffix _java_$2, $(DISTROS)))
#$$(info Create targets: $(addprefix clean_, $(addsuffix _python_$2, $(DISTROS))))
python_targets_$1_$2 = $(addprefix clean_, $(addsuffix _python_$2, $(DISTROS)))
python_targets_$1_$2 = $(addprefix clean_$1_, $(addsuffix _python_$2, $(DISTROS)))
.PHONY: $$(cpp_targets_$1_$2) $$(dotnet_targets_$1_$2) $$(java_targets_$1_$2) $$(python_targets_$1_$2)

$$(cpp_targets_$1_$2): clean_$1_%_cpp_$2:
Expand All @@ -531,7 +555,6 @@ endef
define make-platform-target =
#$$(info PLATFORM: $1)
$(foreach prestage,$(PRESTAGES),$(eval $(call make-platform-prestage-target,$1,$(prestage))))

$(foreach stage,$(STAGES),$(eval $(call make-platform-stage-target,$1,$(stage))))

# merge
Expand Down Expand Up @@ -708,7 +731,7 @@ clean_glop: $(addprefix clean_glop_, $(STAGES))
## CLEAN ##
###########
.PHONY: clean
clean: clean_all clean_platforms clean_web clean_freebsd clean_glop
clean: clean_all clean_platforms clean_toolchains clean_web clean_freebsd clean_glop
docker container prune -f
docker image prune -f
-rmdir cache
Expand Down

0 comments on commit 16dc087

Please sign in to comment.