SHELL := bash
.SHELLFLAGS := -o pipefail -o noclobber -o errexit -o pipefail -o nounset -c
.DEFAULT_GOAL := all
.DELETE_ON_ERROR:
MAKEFLAGS += --print-directory
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
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
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
.PHONY: run
run:
@printf "%b" "${GREEN}" "$@ ---> running ... " "${RESET}" "\n"
VERBOSE="--verbose" cargo run -- $(filter-out $@,$(MAKECMDGOALS))
%:
@:
.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
@ @ @ @
.PHONY: rustup
rustup:
@printf "%b" "${GREEN}" "$@ ---> running ... " "${RESET}" "\n"
rustup update
rustup component add clippy
rustup component add rustfmt
rustup component add rustfmt-preview
@ @ @
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})"
@ 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"