|
| 1 | +PROJECT := coinutils |
| 2 | +BRANCH := $(shell git rev-parse --abbrev-ref HEAD) |
| 3 | +SHA1 := $(shell git rev-parse --verify HEAD) |
| 4 | + |
| 5 | +# General commands |
| 6 | +.PHONY: help |
| 7 | +BOLD=\e[1m |
| 8 | +RESET=\e[0m |
| 9 | + |
| 10 | +help: |
| 11 | + @echo -e "${BOLD}SYNOPSIS${RESET}" |
| 12 | + @echo -e "\tmake <target> [NOCACHE=1]" |
| 13 | + @echo |
| 14 | + @echo -e "${BOLD}DESCRIPTION${RESET}" |
| 15 | + @echo -e "\ttest build inside docker containers so we can test against various major distro setup." |
| 16 | + @echo |
| 17 | + @echo -e "${BOLD}MAKE TARGETS${RESET}" |
| 18 | + @echo -e "\t${BOLD}help${RESET}: display this help and exit." |
| 19 | + @echo |
| 20 | + @echo -e "\t${BOLD}docker${RESET}: generate all docker devel images." |
| 21 | + @echo -e "\t${BOLD}docker_<distro>${RESET}: generate docker devel image for the specified distro." |
| 22 | + @echo |
| 23 | + @echo -e "\t${BOLD}configure${RESET}: cmake 'configure' using all devel image containers." |
| 24 | + @echo -e "\t${BOLD}configure_<distro>${RESET}: cmake 'configure' using the devel image container specified." |
| 25 | + @echo |
| 26 | + @echo -e "\t${BOLD}build${RESET}: cmake 'build' target ${BOLD}all${RESET} using all the devel image containers." |
| 27 | + @echo -e "\t${BOLD}build_<distro>${RESET}: cmake 'build' target ${BOLD}all${RESET} using the devel image container specified." |
| 28 | + @echo |
| 29 | + @echo -e "\t${BOLD}test${RESET}: cmake 'build' target ${BOLD}test${RESET} using all devel image containers." |
| 30 | + @echo -e "\t${BOLD}test_<distro>${RESET}: cmake 'build' target ${BOLD}test${RESET} using the devel image container specified." |
| 31 | + @echo |
| 32 | + @echo -e "\t${BOLD}install${RESET}: execute the cmake target ${BOLD}install${RESET} using all devel image container, then create an install image with it." |
| 33 | + @echo -e "\t${BOLD}install_<distro>${RESET}: execute the cmake target ${BOLD}install${RESET} using the devel image container specified, then create an install image with it." |
| 34 | + @echo |
| 35 | + @echo -e "\t${BOLD}test_install${RESET}: configure, build, install then test a sample project against it using all ${BOLD}install${RESET} image containers." |
| 36 | + @echo -e "\t${BOLD}test_install_<distro>${RESET}: configure, build, install then test a sample project against it using the ${BOLD}install${RESET} image container specified." |
| 37 | + @echo |
| 38 | + @echo -e "\t${BOLD}clean${RESET}: Remove build directories and log files for all distros." |
| 39 | + @echo -e "\t${BOLD}clean_<distro>${RESET}: Remove build directories and log files for the distro specified." |
| 40 | + @echo |
| 41 | + @echo -e "\t${BOLD}distclean${RESET}: execute ${BOLD}clean${RESET} and also remove all docker images." |
| 42 | + @echo -e "\t${BOLD}distclean_<distro>${RESET}: execute ${BOLD}clean_<distro>${RESET} and also remove the docker images." |
| 43 | + @echo |
| 44 | + @echo -e "\t${BOLD}<distro>${RESET}:" |
| 45 | + @echo -e "\t\t${BOLD}alpine${RESET} (latest)" |
| 46 | + @echo -e "\t\t${BOLD}archlinux${RESET} (latest)" |
| 47 | + @echo -e "\t\t${BOLD}centos${RESET} (latest)" |
| 48 | + @echo -e "\t\t${BOLD}fedora${RESET} (latest)" |
| 49 | + @echo -e "\t\t${BOLD}opensuse${RESET} (latest)" |
| 50 | + @echo -e "\t\t${BOLD}debian${RESET} (latest)" |
| 51 | + @echo -e "\t\t${BOLD}ubuntu${RESET} (latest)" |
| 52 | + @echo -e "\t\t${BOLD}xenial${RESET} (Ubuntu 16.04 LTS)" |
| 53 | + @echo -e "\te.g. 'make test_ubuntu'" |
| 54 | + @echo |
| 55 | + @echo -e "\t${BOLD}NOCACHE=1${RESET}: use 'docker build --no-cache' when building container (default use cache)." |
| 56 | + @echo |
| 57 | + @echo -e "${BOLD}NOTES${RESET}" |
| 58 | + @echo -e "\tAll generated code will be located in the cache/ folder, use distclean to remove it." |
| 59 | + @echo |
| 60 | + @echo -e "branch: $(BRANCH)" |
| 61 | + @echo -e "sha1: $(SHA1)" |
| 62 | + |
| 63 | +# Need to add cmd_distro to PHONY otherwise target are ignored since they do not |
| 64 | +# contain recipe (using FORCE do not work here) |
| 65 | +.PHONY: all |
| 66 | +all: build |
| 67 | + |
| 68 | +# Delete all implicit rules to speed up makefile |
| 69 | +.SUFFIXES: |
| 70 | +# Remove some rules from gmake that .SUFFIXES does not remove. |
| 71 | +SUFFIXES = |
| 72 | +# Keep all intermediate files |
| 73 | +# ToDo: try to remove it later |
| 74 | +.SECONDARY: |
| 75 | + |
| 76 | +# Docker image name prefix. |
| 77 | +IMAGE := ${PROJECT} |
| 78 | + |
| 79 | +ifdef NOCACHE |
| 80 | +DOCKER_BUILD_CMD := docker build --no-cache |
| 81 | +else |
| 82 | +DOCKER_BUILD_CMD := docker build |
| 83 | +endif |
| 84 | + |
| 85 | +# Use host user id instead of default root:root |
| 86 | +UID := $(shell id -u) |
| 87 | +GID := $(shell id -g) |
| 88 | +DOCKER_DEVEL_CMD := docker run --rm -it -v ${PWD}/..:/project -w /project --user ${UID}:${GID} |
| 89 | +#DOCKER_DEVEL_CMD := docker run --rm -it -v ${PWD}:/project -w /project |
| 90 | + |
| 91 | +DOCKER_INSTALL_CMD := docker run --rm -it -v ${PWD}/sample:/project -w /project |
| 92 | + |
| 93 | +# Currently supported distro |
| 94 | +DISTROS = alpine archlinux centos fedora opensuse debian ubuntu xenial |
| 95 | + |
| 96 | +# $* stem |
| 97 | +# $< first prerequist |
| 98 | +# $@ target name |
| 99 | + |
| 100 | +# DOCKER |
| 101 | +targets = $(addprefix docker_, $(DISTROS)) |
| 102 | +.PHONY: docker $(targets) |
| 103 | +docker: $(targets) |
| 104 | +$(targets): docker_%: cache/%/docker_devel.tar |
| 105 | +cache/%/docker_devel.tar: docker/%/Dockerfile |
| 106 | + mkdir -p cache/$* |
| 107 | + @docker image rm -f ${IMAGE}_$*:devel 2>/dev/null |
| 108 | + @rm -f $@ |
| 109 | + ${DOCKER_BUILD_CMD} -t ${IMAGE}_$*:devel -f $< docker/$* |
| 110 | + docker save ${IMAGE}_$*:devel -o $@ |
| 111 | + |
| 112 | +# DOCKER BASH (debug) |
| 113 | +targets = $(addprefix bash_, $(DISTROS)) |
| 114 | +.PHONY: $(targets) |
| 115 | +$(targets): bash_%: cache/%/docker_devel.tar |
| 116 | + ${DOCKER_DEVEL_CMD} ${IMAGE}_$*:devel /bin/sh |
| 117 | + |
| 118 | +# CONFIGURE |
| 119 | +targets = $(addprefix configure_, $(DISTROS)) |
| 120 | +.PHONY: configure $(targets) |
| 121 | +configure: $(targets) |
| 122 | +$(targets): configure_%: cache/%/configure.log |
| 123 | +cache/%/configure.log: cache/%/docker_devel.tar \ |
| 124 | + ../CMakeLists.txt ../*/CMakeLists.txt ../cmake/*Config.cmake.in |
| 125 | + @rm -rf cache/$*/build |
| 126 | + @docker load -i $< |
| 127 | + ${DOCKER_DEVEL_CMD} ${IMAGE}_$*:devel /bin/sh -c \ |
| 128 | + "cmake -version && cmake -H. -Bci/cache/$*/build" |
| 129 | + @date > $@ |
| 130 | + |
| 131 | +# BUILD |
| 132 | +targets = $(addprefix build_, $(DISTROS)) |
| 133 | +.PHONY: build $(targets) |
| 134 | +build: $(targets) |
| 135 | +$(targets): build_%: cache/%/build.log |
| 136 | +cache/%/build.log: cache/%/configure.log ../CoinUtils |
| 137 | + ${DOCKER_DEVEL_CMD} ${IMAGE}_$*:devel /bin/sh -c \ |
| 138 | + "cmake --build ci/cache/$*/build --target all" |
| 139 | + @date > $@ |
| 140 | + |
| 141 | +# TEST |
| 142 | +targets = $(addprefix test_, $(DISTROS)) |
| 143 | +.PHONY: test $(targets) |
| 144 | +test: $(targets) |
| 145 | +$(targets): test_%: cache/%/test.log |
| 146 | +cache/%/test.log: cache/%/build.log |
| 147 | + ${DOCKER_DEVEL_CMD} ${IMAGE}_$*:devel /bin/sh -c \ |
| 148 | + "cmake --build ci/cache/$*/build --target test -- CTEST_OUTPUT_ON_FAILURE=1" |
| 149 | + @date > $@ |
| 150 | + |
| 151 | +# INSTALL |
| 152 | +targets = $(addprefix install_, $(DISTROS)) |
| 153 | +.PHONY: install $(targets) |
| 154 | +install: $(targets) |
| 155 | +$(targets): install_%: cache/%/install.log |
| 156 | +cache/%/install.log: docker/%/InstallDockerfile cache/%/build.log |
| 157 | + ${DOCKER_DEVEL_CMD} ${IMAGE}_$*:devel /bin/sh -c \ |
| 158 | + "cmake --build ci/cache/$*/build --target install -- DESTDIR=../install" |
| 159 | + @docker image rm -f ${IMAGE}_$*:install 2>/dev/null |
| 160 | + @rm -f cache/$*/docker_install.tar |
| 161 | + ${DOCKER_BUILD_CMD} -t ${IMAGE}_$*:install -f $< cache/$* |
| 162 | + docker save ${IMAGE}_$*:install -o cache/$*/docker_install.tar |
| 163 | + @date > $@ |
| 164 | + |
| 165 | +# DOCKER BASH INSTALL (debug) |
| 166 | +targets = $(addprefix bash_install_, $(DISTROS)) |
| 167 | +.PHONY: $(targets) |
| 168 | +$(targets): bash_install_%: cache/%/install.log |
| 169 | + @docker load -i cache/$*/docker_install.tar |
| 170 | + ${DOCKER_INSTALL_CMD} ${IMAGE}_$*:install /bin/sh |
| 171 | + |
| 172 | +# TEST INSTALL of ProjectConfigs.cmake |
| 173 | +targets = $(addprefix test_install_, $(DISTROS)) |
| 174 | +.PHONY: test_install $(targets) |
| 175 | +test_install: $(targets) |
| 176 | +$(targets): test_install_%: cache/%/test_install.log |
| 177 | +cache/%/test_install.log: cache/%/install.log sample |
| 178 | + @docker load -i cache/$*/docker_install.tar |
| 179 | + ${DOCKER_INSTALL_CMD} ${IMAGE}_$*:install /bin/sh -c \ |
| 180 | + "cmake -H. -B/cache; \ |
| 181 | + cmake --build /cache; \ |
| 182 | + cmake --build /cache --target test; \ |
| 183 | + cmake --build /cache --target install" |
| 184 | + @date > $@ |
| 185 | + |
| 186 | +# CLEAN |
| 187 | +targets = $(addprefix clean_, $(DISTROS)) |
| 188 | +.PHONY: clean $(targets) |
| 189 | +clean: $(targets) |
| 190 | +$(targets): clean_%: |
| 191 | + -rm -f cache/$*/test_install.log |
| 192 | + -rm -f cache/$*/install.log |
| 193 | + -rm -rf cache/$*/install |
| 194 | + -rm -f cache/$*/test.log |
| 195 | + -rm -f cache/$*/build.log |
| 196 | + -rm -f cache/$*/configure.log |
| 197 | + -rm -rf cache/$*/build |
| 198 | + |
| 199 | +# DISTCLEAN |
| 200 | +targets = $(addprefix distclean_, $(DISTROS)) |
| 201 | +.PHONY: distclean $(targets) |
| 202 | +distclean: $(targets) |
| 203 | + docker image prune -f |
| 204 | + rmdir cache |
| 205 | +$(targets): distclean_%: clean_% |
| 206 | + -docker image rm -f ${IMAGE}_$*:install 2>/dev/null |
| 207 | + -rm -f cache/$*/docker_install.tar |
| 208 | + -docker image rm -f ${IMAGE}_$*:devel 2>/dev/null |
| 209 | + -rm -f cache/$*/docker_devel.tar |
| 210 | + -rmdir cache/$* |
0 commit comments