Skip to content

Commit

Permalink
Makefile_v1,README.md: major update with improved diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
DDvO committed Oct 19, 2024
1 parent ca6a334 commit d0750e8
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 27 deletions.
99 changes: 74 additions & 25 deletions Makefile_v1
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@
#
# SPDX-License-Identifier: Apache-2.0

# Optional OPENSSL_DIR defines absolute or relative (to ../) path to OpenSSL installation
# Optional OPENSSL_LIB defines where to find the OpenSSL library installation (default: OPENSSL_DIR/lib).
# Optional OPENSSL_DIR defines where to find the OpenSSL installation
# with header files at include/openssl (default: will try, e.g., /usr).
# Optional OPENSSL_LIB defines where to find the OpenSSL libraries
# (default: will try, e.g., OPENSSL_DIR/lib).
# Optional CFLAGS and LDFLAGS are appended by local settings.
# Optional DEBUG_FLAGS may set to prepend to local CFLAGS and LDFLAGS (default see below).
# Builds are done in release mode if optional NDEBUG is defined.
# Optional OUT_DIR defines absolute or relative (to ./) path where to place the library.
# Optional OUT_DIR defines where to place the resulting library (default: '.').
# Optional DESTDIR defines a prefix for the installation target directories.
# All paths may be absolute or relative to the directory containing this Makefile.

ROOTFS ?= $(DESTDIR)$(prefix)

ifeq ($(OUT_DIR),)
override OUT_DIR = .
endif
override OUT_DIR ?= .

VERSION=2.0
# must be kept in sync with debian/changelog and CMakeLists.txt
Expand All @@ -33,9 +34,13 @@ VERSION=2.0

SHELL=bash # This is needed for supporting extended file name globbing

ifeq ($(OS),Windows_NT)
# https://stackoverflow.com/questions/714100/os-detecting-makefile
ifeq ($(OS),Windows_NT) # strange but apparently this string is used also for all later versions
OS=Windows
USERS="\\Users\\"
EXE=.exe
DLL=.dll
SONAME=
OBJ=.obj
LIB=bin
else
Expand All @@ -44,26 +49,68 @@ else
LIB=lib
ifeq ($(shell uname -s),Darwin)
OS=MacOS
USERS="/Users/"
DLL=.dylib
SONAME=install_name,@rpath/
else # assuming Linux
USERS="/home/"
DLL=.so
SONAME=soname,
endif
endif

ifeq ($(OPENSSL_DIR),)
OPENSSL_DIR=$(ROOTFS)/usr
ifneq ($(filter-out doc install uninstall clean clean_config clean_all clean_uta clean_deb,$(MAKECMDGOALS)),)
ifeq ($(OPENSSL_DIR),) # for convenience, use heuristics to determine OPENSSL_DIR
ifeq ($(OS),MacOS)
SYSTEM_INCLUDE_OPENSSL=/opt/homebrew/include/openssl # usually symlink
else # TODO for Windows
SYSTEM_INCLUDE_OPENSSL=/usr/include/openssl
endif
OPENSSL_INCLUDE_DIR = $(realpath $(SYSTEM_INCLUDE_OPENSSL))
override OPENSSL_DIR = $(realpath $(OPENSSL_INCLUDE_DIR)/../..)
endif
ifeq ($(shell echo $(OPENSSL_DIR) | grep "^/"),)
# $(OPENSSL_DIR) is relative path, assumed relative to ../
OPENSSL=../$(OPENSSL_DIR)
OPENSSL_LIB ?= ../$(OPENSSL_DIR)
else
# $(OPENSSL_DIR) is absolute path
OPENSSL=$(OPENSSL_DIR)
OPENSSL_LIB ?= $(OPENSSL_DIR)
ifneq ($(OPENSSL_DIR),) # due to the above, always true
LIB_NAME_PATTERN=libcrypto*$(DLL)*
ifeq ($(realpath $(OPENSSL_DIR)),)
$(error OPENSSL_DIR appears to be an invalid path: $(OPENSSL_DIR))
endif
override OPENSSL_DIR := $(realpath $(OPENSSL_DIR))

ifeq ($(OPENSSL_LIB),) # for convenience, use heuristics to determine OPENSSL_LIB
override OPENSSL_LIB = $(OPENSSL_DIR)/$(LIB)
ifeq ($(wildcard $(OPENSSL_LIB)/$(LIB_NAME_PATTERN)),)
# $(warning Warning: cannot find OpenSSL libraries at determined location $(OPENSSL_LIB), now trying OPENSSL_DIR)
override OPENSSL_LIB = $(OPENSSL_DIR)
ifeq ($(wildcard $(OPENSSL_LIB)/$(LIB_NAME_PATTERN)),)
ifeq ($(OS),Linux)
ifeq ($(findstring $(USERS),$(OPENSSL_FULL_DIR)),)
override OPENSSL_LIB = $(wildcard /lib/*linux-gnu*)
# $(warning Warning: cannot find OpenSSL libraries at $(OPENSSL_DIR), now trying $(OPENSSL_LIB))
endif
endif
endif
endif
else
ifeq ($(wildcard $(OPENSSL_LIB)/$(LIB_NAME_PATTERN)),)
# $(warning Warning: cannot find OpenSSL libraries at given OPENSSL_LIB $(OPENSSL_LIB), now trying OPENSSL_DIR)
override OPENSSL_LIB = $(OPENSSL_DIR)
endif
endif
# ifeq ($(findstring $(USERS),$(OPENSSL_FULL_DIR)),)
# $(warning [DEBUG] OPENSSL_DIR is assumed to be an installation directory)
# else
# $(warning [DEBUG] OPENSSL_DIR is assumed to be a local build directory)
# endif
ifeq ($(wildcard $(OPENSSL_LIB)/$(LIB_NAME_PATTERN)),)
$(error Error: cannot find OpenSSL library $(LIB_NAME_PATTERN) at $(OPENSSL_LIB)/)
endif
override OPENSSL_LIB := $(realpath $(OPENSSL_LIB))
endif
ifeq ($(wildcard $(OPENSSL_DIR)/include/openssl),)
$(error cannot find directory '$(OPENSSL_DIR)/include/openssl', check OPENSSL_DIR variable)
endif
endif # neq ($(filter-out doc install uninstall clean clean_config clean_all clean_uta clean_deb,$(MAKECMDGOALS)),)


################################################################################
# Basic definitions targeted at debugging
Expand All @@ -73,10 +120,10 @@ endif
################################################################################

ifdef NDEBUG
DEBUG_FLAGS ?= -O2
override DEBUG_FLAGS ?= -O2
override DEBUG_FLAGS += -DNDEBUG=1 -Werror
else
DEBUG_FLAGS ?= -g -O0 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all # not every compiler(version) supports -Og
override DEBUG_FLAGS ?= -g -O0 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all # not every compiler(version) supports -Og
endif
override CFLAGS += $(DEBUG_FLAGS) \
-Wall -Woverflow -Wextra -Wswitch -Wmissing-prototypes -Wstrict-prototypes \
Expand All @@ -94,7 +141,7 @@ override CFLAGS += -pedantic -DPEDANTIC
################################################################################

CC ?= gcc
OUTLIB_=libsecutils
override OUTLIB_= libsecutils
OUTLIB=$(OUTLIB_)$(DLL)
ifeq ($(OS),MacOS)
OUTLIBV=$(OUTLIB_).$(VERSION)$(DLL)
Expand All @@ -109,7 +156,7 @@ DEST_DOC=$(DEST_PRE)/share/doc/libsecutils-dev
OUTBIN=icvutil$(EXE)
DEST_BIN=$(DEST_PRE)/bin
LOCAL_CFLAGS= -fPIC # -std=gnu90 TODO clean up code and re-enable flag
override CFLAGS += -isystem $(OPENSSL)/include# # # use of -isystem is critical for selecting wanted OpenSSL version
override CFLAGS += -isystem $(OPENSSL_DIR)/include# # use of -isystem is critical for selecting wanted OpenSSL version
override CFLAGS += -Isrc/libsecutils/include
override CFLAGS += -Isrc/libsecutils/include/secutils
ifneq ($(SECUTILS_USE_UTA),)
Expand All @@ -120,12 +167,9 @@ ifneq ($(SECUTILS_USE_ICV),)
endif

override LDFLAGS += $(DEBUG_FLAGS) # needed for -fsanitize=...
override LDFLAGS += -L $(OPENSSL_LIB) -L $(OPENSSL)
override LDFLAGS += -L $(OPENSSL_LIB)
ifeq ($(DEB_TARGET_ARCH),) # not during Debian packaging
override LDFLAGS += -Wl,-rpath,$(OPENSSL_LIB)
ifneq ($(OPENSSL_LIB),$(OPENSSL))
override LDFLAGS += -Wl,-rpath,$(OPENSSL)
endif
endif
ifneq ($(SECUTILS_USE_UTA),)
override LDFLAGS += -luta
Expand Down Expand Up @@ -173,6 +217,11 @@ OBJS := $(patsubst %.c,$(BUILDDIR)/%$(OBJ),$(notdir $(wildcard src/libsecutils/s
# Default target
all: build_all doc

ifneq ($(findstring build_only,$(MAKECMDGOALS)),)
$(info Build info: source directory is '$(PWD)')
$(info detected OpenSSL base directory '$(OPENSSL_DIR)')
$(info detected OpenSSL lib directory '$(OPENSSL_LIB)')
endif
build_only: $(OUT_DIR)/$(OUTLIB)

build:
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# libsecutils
# libSecUtils

<img src="libsecutils.svg" width="200">

Expand Down Expand Up @@ -76,7 +76,7 @@ including the C header files needed for development

By default any OpenSSL installation available on the system is used.
Set the optional environment variable `OPENSSL_DIR` to specify the
absolute (or relative to `../`) path of the OpenSSL installation to use, e.g.:
absolute or relative path of the OpenSSL installation to use, e.g.:
```
export OPENSSL_DIR=/usr/local
```
Expand All @@ -85,6 +85,9 @@ In case its libraries are in a different location, set also `OPENSSL_LIB`, e.g.:
export OPENSSL_LIB=$OPENSSL_DIR/lib
```

For all environment variables specifying a directory, relative paths such as `.`
are interpreted relative to the libSecUtils source directory.

Use of the UTA library can be enabled
by setting the environment variable `SECUTILS_USE_UTA`.

Expand Down

0 comments on commit d0750e8

Please sign in to comment.