Skip to content

Commit

Permalink
fixup! feat(debug): improved debug messages
Browse files Browse the repository at this point in the history
  • Loading branch information
DDvO committed Oct 11, 2024
1 parent b14214d commit 8871aa6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 33 deletions.
8 changes: 4 additions & 4 deletions OpenSSL_version.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@

int main(int argc, char *argv[])
{
fprintf(stdout, "[DEBUG] Starting OpenSSL version check\n");
fprintf(stdout, DEBUG_MESSAGE);
fprintf(stderr, "[DEBUG] Starting OpenSSL version check\n");
fprintf(stderr, DEBUG_MESSAGE);

unsigned long static_version = (unsigned long)OPENSSL_VERSION_NUMBER;
fprintf(stdout, "[DEBUG] OPENSSL_VERSION_NUMBER: 0x%lx\n", static_version);
fprintf(stderr, "[DEBUG] OPENSSL_VERSION_NUMBER: 0x%lx\n", static_version);

unsigned long runtime_version = OpenSSL_version_num();
fprintf(stdout, "[DEBUG] runtime_version: 0x%lx\n", runtime_version);
fprintf(stderr, "[DEBUG] runtime_version: 0x%lx\n", runtime_version);

#define MAJOR_MINOR_MASK 0xfff00000L
if ((MAJOR_MINOR_MASK & runtime_version ) != (MAJOR_MINOR_MASK & OPENSSL_VERSION_NUMBER)) {
Expand Down
52 changes: 26 additions & 26 deletions OpenSSL_version.mk
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
ifeq ($(LIB),)
$(info [DEBUG] LIB is empty or not set)
$(warning [DEBUG] LIB is empty or not set)

ifeq ($(OS),Windows_NT)
$(info [DEBUG] OS is Windows_NT)
$(warning [DEBUG] OS is Windows_NT)
EXE = .exe
LIB = bin
else
$(info [DEBUG] OS is supposed to be Unix-like)
$(warning [DEBUG] OS is supposed to be Unix-like)
EXE =
LIB = lib
ifeq ($(shell uname -s),Darwin)
$(info [DEBUG] OS is Darwin (MacOS))
$(warning [DEBUG] OS is Darwin (MacOS))
OS = MacOS
endif
endif
Expand All @@ -21,29 +21,29 @@ ifeq ($(LIB),)

# CC = gcc
ifneq ($(OPENSSL_DIR),)
$(info [DEBUG] OPENSSL_DIR is set: $(OPENSSL_DIR))
$(warning [DEBUG] OPENSSL_DIR is set: $(OPENSSL_DIR))
ifeq ($(shell echo $(OPENSSL_DIR) | grep "^/"),)
$(info [DEBUG] OPENSSL_DIR is a relative path)
$(warning [DEBUG] OPENSSL_DIR is a relative path)
# $(OPENSSL_DIR) is relative path
OPENSSL_LIB = $(OPENSSL_DIR)
else
$(info [DEBUG] OPENSSL_DIR is an absolute path)
$(warning [DEBUG] OPENSSL_DIR is an absolute path)
# $(OPENSSL_DIR) is absolute path
OPENSSL_LIB = $(OPENSSL_DIR)/$(LIB)
endif
$(info [TRACE] After OPENSSL_DIR check: OPENSSL_LIB="$(OPENSSL_LIB)")
$(warning [TRACE] After OPENSSL_DIR check: OPENSSL_LIB="$(OPENSSL_LIB)")
CFLAGS += -isystem $(OPENSSL_DIR)/include
LDFLAGS += -L$(OPENSSL_DIR) -L$(OPENSSL_LIB) -Wl,-rpath,$(OPENSSL_DIR) -Wl,-rpath,$(OPENSSL_LIB)
endif

LDLIBS = -lcrypto

$(info [TRACE] After OPENSSL_DIR set: EXE=$(EXE))
$(info [TRACE] After OPENSSL_DIR set: LIB=$(LIB))
$(info [TRACE] After OPENSSL_DIR set: OPENSSL_LIB=$(OPENSSL_LIB))
$(info [TRACE] After OPENSSL_DIR set: CFLAGS=$(CFLAGS))
$(info [TRACE] After OPENSSL_DIR set: LDFLAGS=$(LDFLAGS))
$(info [TRACE] After OPENSSL_DIR set: LDLIBS=$(LDLIBS))
$(warning [TRACE] After OPENSSL_DIR set: EXE=$(EXE))
$(warning [TRACE] After OPENSSL_DIR set: LIB=$(LIB))
$(warning [TRACE] After OPENSSL_DIR set: OPENSSL_LIB=$(OPENSSL_LIB))
$(warning [TRACE] After OPENSSL_DIR set: CFLAGS=$(CFLAGS))
$(warning [TRACE] After OPENSSL_DIR set: LDFLAGS=$(LDFLAGS))
$(warning [TRACE] After OPENSSL_DIR set: LDLIBS=$(LDLIBS))

.PHONY: default build show clean

Expand All @@ -58,46 +58,46 @@ ifeq ($(LIB),)
@rm -f OpenSSL_version$(EXE)

else ifeq ($(LIB),header)
$(info [DEBUG] LIB is set to header)
$(warning [DEBUG] LIB is set to header)

OPENSSL_NUMBER_SEL = head -n 1 | sed -r 's/.*OpenSSL //' | awk '{print ($$0+0)}'
OPENSSLV_H = $(OPENSSL_DIR)/include/openssl/opensslv.h
ifeq ($(shell fgrep OPENSSL_VERSION_MAJOR "$(OPENSSLV_H)"),)
$(info [DEBUG] OPENSSL_VERSION_MAJOR not found in OPENSSLV_H)
$(warning [DEBUG] OPENSSL_VERSION_MAJOR not found in OPENSSLV_H)
OPENSSL_VERSION = $(shell grep 'OPENSSL_VERSION_TEXT\s* "OpenSSL ' "$(OPENSSLV_H)" | $(OPENSSL_NUMBER_SEL))
else
$(info [DEBUG] OPENSSL_VERSION_MAJOR found in OPENSSLV_H)
$(warning [DEBUG] OPENSSL_VERSION_MAJOR found in OPENSSLV_H)
ifeq ($(OS),MacOS)
$(info [DEBUG] OS is MacOS)
$(warning [DEBUG] OS is MacOS)
OPENSSL_VERSION = $(shell fgrep OPENSSL_VERSION_M "$(OPENSSLV_H)" | head -n 2 | awk -v RS="" '{print $4"."$8 }')
else
$(info [DEBUG] OS is not MacOS)
$(warning [DEBUG] OS is not MacOS)
OPENSSL_VERSION = $(shell fgrep OPENSSL_VERSION_M "$(OPENSSLV_H)" | head -n 2 | awk -v RS="" '{print $$4"."$$8 }')
endif
$(info [TRACE] After OS check in header: OPENSSL_VERSION=$(OPENSSL_VERSION))
$(warning [TRACE] After OS check in header: OPENSSL_VERSION=$(OPENSSL_VERSION))
endif

ifeq ($(OPENSSL_VERSION),1)
OPENSSL_VERSION = 1.0
endif

$(info [TRACE] OPENSSL_NUMBER_SEL=$(OPENSSL_NUMBER_SEL))
$(info [TRACE] OPENSSLV_H=$(OPENSSLV_H))
$(info [TRACE] OPENSSL_VERSION=$(OPENSSL_VERSION))
$(warning [TRACE] OPENSSL_NUMBER_SEL=$(OPENSSL_NUMBER_SEL))
$(warning [TRACE] OPENSSLV_H=$(OPENSSLV_H))
$(warning [TRACE] OPENSSL_VERSION=$(OPENSSL_VERSION))

else # $(LIB) is name of library file
$(info [DEBUG] LIB is supposed to be a library file: $(LIB))
$(warning [DEBUG] LIB is supposed to be a library file: $(LIB))

OPENSSL_VERSION = $(shell strings "$(LIB)" | grep -E 'OpenSSL [0-9]+\.[0-9]+\.' | head -n 1 | sed -r 's/.*OpenSSL //' | awk -v FS="." '{print $$1"."$$2}')
ifeq ($(OPENSSL_VERSION),)
$(info [DEBUG] OpenSSL version info not found in library file contents; now trying to get it from the file name)
$(warning [DEBUG] OpenSSL version info not found in library file contents; now trying to get it from the file name)
OPENSSL_VERSION = $(shell strings "$(LIB)" | grep -E 'libcrypto\.' | head -n 1 | sed -r 's/.*libcrypto(.[a-z]+)?\.//')
endif
ifeq ($(OPENSSL_VERSION),1.0.0)
OPENSSL_VERSION = 1.0
endif

$(info [TRACE] OPENSSL_VERSION=$(OPENSSL_VERSION))
$(warning [TRACE] OPENSSL_VERSION=$(OPENSSL_VERSION))

endif # $(LIB)

Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,11 @@ you can execute in a shell on a Unix-like system:
```
git clone https://github.com/siemens/gencmpclient.git
cd genCMPClient
make -f OpenSSL_version.mk
make -s -f OpenSSL_version.mk 2>/dev/null
```

This should output on the console something like
```
cc [...] OpenSSL_version.c -lcrypto -o OpenSSL_version
OpenSSL 3.0.13 30 Jan 2024 (0x300000d0)
```

Expand All @@ -129,6 +127,12 @@ make sure that the system-level configuration for finding header and library fil
as well as the optional environment variables `OPENSSL_DIR` and `OPENSSL_LIB`
described [below](#configuring) are set up in a consistent way.

When having trouble building, which may be due to unsuitably set environment variables,
```
make -f OpenSSL_version.mk
```
can provides useful diagnostics.


## Getting the software

Expand Down

0 comments on commit 8871aa6

Please sign in to comment.