# http://agdr.org/2020/05/14/Polyglot-Makefiles.html # https://tech.davis-hansson.com/p/make/ # .ONESHELL: SHELL := bash # IFS := $'\n\t' .SHELLFLAGS := -o pipefail -o noclobber -o errexit -o pipefail -o nounset -c # .SHELLFLAGS := -o pipefail -o errexit -o pipefail -o nounset -c # .SHELLFLAGS := -euf -o pipefail -c .DEFAULT_GOAL := all .DELETE_ON_ERROR: MAKEFLAGS += --print-directory MAKEFLAGS += --warn-undefined-variables MAKEFLAGS += --no-builtin-rules # MAKEFLAGS += --no-builtin-variables # MAKEFLAGS += --environment-overrides # MAKEFLAGS += --jobs=32 # https://www.gnu.org/software/make/manual/html_node/Parallel-Output.html#Parallel-Output # MAKEFLAGS += --output-sync=target # # debug # MAKEFLAGS += --just-print # MAKEFLAGS += --dry-run # MAKEFLAGS += --recon BOLD := \033[1m MISC := \033[32m YELLOW := \033[33m GREEN := \033[92m${BOLD} RED := \033[91m RESET := \033[0m GIT_REV := $(shell git rev-parse --short HEAD) DIR_NAME := $(shell basename $(shell pwd)) PATH := $(shell echo "${HOME}/.cargo/bin:${PATH}") PATH_FULL := $(shell pwd) PATH_TEST_RANDOM_GENERATED_STRING := ${PATH_FULL}/testdata RANDOM_GENERATED_STRINGS_TOTAL := 1000 VERBOSE := --verbose CARGO_TERM_VERBOSE := 1 export VERBOSE export CARGO_TERM_VERBOSE .PHONY: format run all: format run # .PHONY: debug format lint build test run # all: debug format lint build test run .PHONY: debug debug: @printf "%b" "${GREEN}" "$@ ---> printing environmental variables ... " "${RESET}" "\n" @echo -e $(foreach VAR,$(.VARIABLES),"${BOLD}${MISC}$(VAR)${RESET}=$($(VAR))\n") @printf "%b" "${GREEN}" "$@ ---> running ... " "${RESET}" "\n" @printf "%b" "${BOLD}${MISC}" "GIT_REV" "${RESET}" "=" "${GIT_REV}" "\n" @printf "%b" "${BOLD}${MISC}" "PATH" "${RESET}" "=" "${PATH}" "\n" @printf "%b" "${BOLD}${MISC}" "DIR_NAME" "${RESET}" "=" "${DIR_NAME}" "\n" @printf "%b" "${BOLD}${MISC}" "VERBOSE" "${RESET}" "=" "${VERBOSE}" "\n" @printf "%b" "${BOLD}${MISC}" "CARGO_TERM_VERBOSE" "${RESET}" "=" "${CARGO_TERM_VERBOSE}" "\n" .PHONY: clean clean: @printf "%b" "${GREEN}" "$@ ---> running ... " "${RESET}" "\n" VERBOSE="--verbose" cargo clean .PHONY: build build: @printf "%b" "${GREEN}" "$@ ---> running ... " "${RESET}" "\n" VERBOSE="--verbose" cargo build .PHONY: test test: @printf "%b" "${GREEN}" "$@ ---> running ... " "${RESET}" "\n" VERBOSE="--verbose" cargo test # https://stackoverflow.com/questions/6273608/how-to-pass-argument-to-makefile-from-command-line/6273809 # https://stackoverflow.com/questions/2214575/passing-arguments-to-make-run .PHONY: run run: @printf "%b" "${GREEN}" "$@ ---> running ... " "${RESET}" "\n" VERBOSE="--verbose" cargo run -- $(filter-out $@,$(MAKECMDGOALS)) # This allows us to accept extra arguments (by doing nothing when we get a job that doesn't match, rather than throwing an error). %: @: .PHONY: lint lint: @printf "%b" "${GREEN}" "$@ ---> running ... " "${RESET}" "\n" VERBOSE="--verbose" cargo clippy .PHONY: format format: @printf "%b" "${GREEN}" "$@ ---> running ... " "${RESET}" "\n" VERBOSE="--verbose" cargo +nightly fmt --verbose --all @# VERBOSE="--verbose" cargo +nightly --all @# #rustup toolchain install nightly @# rustup toolchain install --profile minimal --component rustfmt,clippy nightly @# rustup component add rustfmt --toolchain nightly .PHONY: rustup rustup: @printf "%b" "${GREEN}" "$@ ---> running ... " "${RESET}" "\n" rustup update rustup component add clippy rustup component add rustfmt rustup component add rustfmt-preview @# #rustup toolchain install nightly @# rustup toolchain install --profile minimal --component rustfmt,clippy nightly @# rustup component add rustfmt --toolchain nightly # TODO: Check the rest of the commands exist ... CMD_EXISTS := $(shell command -v shuf 2> /dev/null) .PHONY: generate_random generate_random: OUTPUT_FILE_BASENAME:=${PATH_TEST_RANDOM_GENERATED_STRING}/countdistinct/elements generate_random: @printf "%b" "${GREEN}" "$@ ---> running: generating random data to OUTPUT_FILE_BASENAME=${OUTPUT_FILE_BASENAME}/*... " "${RESET}" "\n" mkdir -p "$(shell dirname ${OUTPUT_FILE_BASENAME})" @# echo $(shell echo ${OUTPUT_FILE_BASENAME}{,_binary,_hex}.txt) rm -vf $(shell echo ${OUTPUT_FILE_BASENAME}{,_binary,_hex}.txt) ifdef CMD_EXISTS @for x in `seq ${RANDOM_GENERATED_STRINGS_TOTAL}`; do \ echo $$(shuf -r -n10 /usr/share/dict/words); \ done > "${OUTPUT_FILE_BASENAME}.txt" else $(error 'canot find shuf') endif @for x in `seq ${RANDOM_GENERATED_STRINGS_TOTAL}`; do \ for y in `seq 64`; do \ printf "%d" $$(( $$RANDOM % 2 )); \ done; \ echo; \ done > "${OUTPUT_FILE_BASENAME}_binary.txt" @for x in `seq ${RANDOM_GENERATED_STRINGS_TOTAL}`; do \ echo "obase=16; ibase=2; $$(for y in `seq 32`; do \ printf "%d" $$(( $$RANDOM % 2 )); \ done)" | bc; \ done > "${OUTPUT_FILE_BASENAME}_hex.txt" @printf "%b" "${GREEN}" "$@ ---> completed: generating random data to ${OUTPUT_FILE_BASENAME}/*, contents=$(shell ls -1C $(shell dirname ${OUTPUT_FILE_BASENAME})) ... " "${RESET}" "\n" @cat $(shell echo ${OUTPUT_FILE_BASENAME}{,_binary,_hex}.txt) .PHONY: web web: @printf "%b" "${GREEN}" "$@ ---> running ... " "${RESET}" "\n"