From 2b2ca1baf5d4a58fb5c2660b0feec186312dc1b9 Mon Sep 17 00:00:00 2001 From: Samuel Aubertin Date: Thu, 24 Feb 2022 12:00:22 +0100 Subject: [PATCH] OpenBSD has no uuid, bring it with us --- Makefile | 27 +++++++++++++++++++-------- uuid.c | 15 +++++++++++++++ 2 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 uuid.c diff --git a/Makefile b/Makefile index 1e73b44..71b7c9f 100644 --- a/Makefile +++ b/Makefile @@ -17,12 +17,18 @@ .SILENT: ifeq ($(shell uname),OpenBSD) -GCC:= egcc +GCC:= egcc +DEPS:= $(GCC) clang ./uuid +ifndef MKUUID +MKUUID!= $(shell $(MAKE) uuid) +endif else -GCC:= gcc +GCC:= gcc +DEPS:= $(GCC) clang uuid lld +LDFLAGS+= -fuse-ld=lld endif -EXECUTABLES= clang $(GCC) uuid lld +EXECUTABLES= $(DEPS) XXXX:= $(foreach exec,$(EXECUTABLES), $(if $(shell which $(exec) 2> /dev/null),X,$(error "No '$(exec)' in PATH, please install it and restart octopus !"))) ### Generic flags @@ -33,13 +39,12 @@ CFLAGS+= -Wall CFLAGS+= -Werror -Wextra CFLAGS+= -Wno-unused-parameter CFLAGS+= -Wno-missing-field-initializers -LDFLAGS= -fuse-ld=lld ### Octopus flags CCS= clang $(GCC) OPTIMIZATIONS= 0 1 2 3 fast s RETPOLINE= mretpoline -UUID:= $(shell uuid || uuidgen) +UUID:= $(shell uuid || uuidgen || ./uuid) RESULTS_FILE:= results-$(UUID).json SSH_KEY= octoupload TIMES= 3 @@ -47,18 +52,21 @@ OCTOFLAGS= -j ### Octopus internals CPU:= $(shell LC_ALL=en_US.UTF-8 lscpu | grep "Model name" | cut -d":" -f 2 | sort | uniq | awk '{$$1=$$1;print}') -UCODE:= $(shell grep microcode /proc/cpuinfo | sort | uniq | awk '{print $$NF}' || printf none) +UCODE:= $(shell (grep microcode /proc/cpuinfo || printf unknown) | sort | uniq | awk '{print $$NF}' || printf unknown) KERN:= $(shell uname -svm) CLANGV:= $(shell clang -v 2>&1 | head -n 1) GCCV:= $(shell gcc -v 2>&1 | grep 'gcc version') -VULN1:= $(shell cat /sys/devices/system/cpu/vulnerabilities/spectre_v1) -VULN2:= $(shell cat /sys/devices/system/cpu/vulnerabilities/spectre_v2) +VULN1:= $(shell (cat /sys/devices/system/cpu/vulnerabilities/spectre_v1 || printf unknown)) +VULN2:= $(shell (cat /sys/devices/system/cpu/vulnerabilities/spectre_v2 || printf unknown)) + +ifneq ($(shell uname),OpenBSD) ifndef PROGRESS HIT_TOTAL!= $(MAKE) $(MAKECMDGOALS) --dry-run PROGRESS="HIT_MARK" | grep -c "HIT_MARK" HIT_COUNT= $(eval HIT_N != expr $(HIT_N) + 1)$(HIT_N) PROGRESS= echo "[`expr $(HIT_COUNT) '*' 100 / $(HIT_TOTAL)`%]" endif +endif SUB_ONE= $(word 1, $(subst -, ,$@)) SUB_TWO= $(word 2, $(subst -, ,$@)) @@ -212,5 +220,8 @@ $(RSGPROGS): @$(PROGRESS) $(SUB_TWO) $(addprefix -, $(SUB_FOUR)) $(CFLAGS) -mfunction-return=thunk -mindirect-branch=thunk -mindirect-branch-register -$(SUB_THREE) -o $@ $(SUB_ONE).c $(SUB_TWO) $(addprefix -, $(SUB_FOUR)) $(CFLAGS) -mfunction-return=thunk -mindirect-branch=thunk -mindirect-branch-register -$(SUB_THREE) -o $@ $(SUB_ONE).c +uuid: + $(CC) -o $@ uuid.c + clean: rm -rf $(PROGS) *.json diff --git a/uuid.c b/uuid.c new file mode 100644 index 0000000..45be21c --- /dev/null +++ b/uuid.c @@ -0,0 +1,15 @@ +#include +#include +#include + +int +main() +{ + uuid_t uuid; + uint32_t status; + char* str[UUID_BUF_LEN]; + uuid_create(&uuid, &status); + uuid_to_string(&uuid, str, &status); + printf("%s\n", *str); + return status; +}