diff --git a/Makefile b/Makefile index 623df41..5d33599 100644 --- a/Makefile +++ b/Makefile @@ -1,67 +1,78 @@ V ?= @ BUILDDIR ?= build +DOCKER_CONTAINER := pumptools:build +DOCKER_CONTAINER_NAME := pumptools-build + gitrev := $(shell git rev-parse HEAD) libcver := $(shell ldd --version | head -n 1) -all: \ -usage +.DEFAULT_GOAL := help -.PHONY: \ -build \ -clean \ -test \ -build-docker \ -git-version \ -libc-version \ -clang-format \ -package +# ----------------------------------------------------------------------------- +# Targets +# ----------------------------------------------------------------------------- -usage: - $(V)echo "Pumptools project build makefile" - $(V)echo " build: Build the pumptools project" - $(V)echo " clean: Clean up all build output" - $(V)echo " test: Run pumptools's unit tests" - $(V)echo " build-docker: Build the pumptools project in a docker container" - $(V)echo " git-version: Generate a text file with the current git revision" - $(V)echo " libc-version: Generate a text file with the libc version available" - $(V)echo " clang-format: Apply code style defined in .clang-format style to all code in src/" - $(V)echo " package: Package the build output into distribution zip files" - -# Standard build target to build pumptools +.PHONY: build # Build the pumptools project and create a distribution package. Build output in build/ build: git-version libc-version $(V)mkdir -p $(BUILDDIR) $(V)cd $(BUILDDIR) && cmake .. && make -j $(grep -c ^processor /proc/cpuinfo) +.PHONY: clean # Cleanup all build output clean: $(V)rm -rf $(BUILDDIR) +.PHONY: test # Run pumptools's unit tests test: build $(V)scripts/run-tests.sh $(BUILDDIR) -# Build pumptools in a docker image and extract the build output +.PHONY: build-docker # Build pumptools in a docker container and extract the build output to build/docker build-docker: $(V)rm -rf $(BUILDDIR)/docker $(V)mkdir -p $(BUILDDIR)/docker - $(V)docker build -t pumptools:build . - $(V)docker create --name pumptools-build pumptools:build - $(V)docker cp pumptools-build:/pumptools/build $(BUILDDIR)/docker + $(V)docker build -t $(DOCKER_CONTAINER) . + $(V)docker create --name $(DOCKER_CONTAINER_NAME) $(DOCKER_CONTAINER) + $(V)docker cp $(DOCKER_CONTAINER_NAME):/pumptools/build $(BUILDDIR)/docker $(V)mv $(BUILDDIR)/docker/build/* $(BUILDDIR)/docker $(V)rm -r $(BUILDDIR)/docker/build - $(V)docker rm -f pumptools-build + $(V)docker rm -f $(DOCKER_CONTAINER_NAME) $(V)echo "Build output of docker build can be found in build/docker subfolder." -# Generate a version file to identify the build +.PHONY: git-version # Generate a text file with the current git revision git-version: $(V)mkdir -p $(BUILDDIR) $(V)echo "$(gitrev)" > $(BUILDDIR)/git-version -# Generate a version file to identify the libc runtime used to build +.PHONY: libc-version # Generate a text file with the libc version available libc-version: $(V)mkdir -p $(BUILDDIR) $(V)echo "$(libcver)" > $(BUILDDIR)/libc-version +.PHONY: clang-format # Apply code style defined in .clang-format style to all code in src/ clang-format: $(V)find src/ -iname *.h -o -iname *.c | xargs clang-format -i -style=file -include Package.mk \ No newline at end of file +.PHONY: package # Package the build output into distribution zip files +package: $(BUILDDIR)/pumptools.zip $(BUILDDIR)/pumptools-public.zip + +include Package.mk + +# ----------------------------------------------------------------------------- +# Utility, combo and alias targets +# ----------------------------------------------------------------------------- + +# Help screen note: +# Variables that need to be displayed in the help screen need to strictly +# follow the pattern "^[A-Z_]+ \?= .* # .*". +# Targets that need to be displayed in the help screen need to add a separate +# phony definition strictly following the pattern "^\.PHONY\: .* # .*". + +.PHONY: help # Print help screen +help: + $(V)echo Pumptools project makefile. + $(V)echo + $(V)echo "Environment variables:" + $(V)grep -E '^[A-Z_]+ \?\= .* #' Makefile | gawk 'match($$0, /([A-Z_]+) \?= [$$\(]*([^\)]*)[\)]{0,1} # (.*)/, a) { printf(" \033[0;35m%-25s \033[0;0m%-45s [%s]\n", a[1], a[3], a[2]) }' + $(V)echo "" + $(V)echo "Targets:" + $(V)grep '^.PHONY: .* #' Makefile | gawk 'match($$0, /\.PHONY: (.*) # (.*)/, a) { printf(" \033[0;32m%-25s \033[0;0m%s\n", a[1], a[2]) }' diff --git a/Package.mk b/Package.mk index bf3f4f7..97ff573 100644 --- a/Package.mk +++ b/Package.mk @@ -279,7 +279,3 @@ $(builddir)/pumptools-public.zip: \ $(builddir)/libc-version $(V)echo ... $@ $(V)zip -j $@ $^ - -################################################ - -package: $(builddir)/pumptools.zip $(builddir)/pumptools-public.zip