Skip to content

Commit

Permalink
Using pkg-config to find out insrtalled pkg-config
Browse files Browse the repository at this point in the history
  • Loading branch information
yashwantsahu20 committed Dec 23, 2024
1 parent 2c80f4a commit e9b57ac
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 39 deletions.
38 changes: 25 additions & 13 deletions deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,38 @@ endif

libinjection: libinjection/libinjection/src/libinjection.a

ssl_header_path := $(shell find /usr /usr/local /opt -name "ssl.h" -path "*/openssl/*" 2>/dev/null | head -n 1)
LIB_SSL_PATH := $(shell find /usr /usr/local /opt -name "libssl.so" 2>/dev/null | head -n 1)
LIB_CRYPTO_PATH := $(shell find /usr /usr/local /opt -name "libcrypto.so" 2>/dev/null | head -n 1)
CUSTOM_OPENSSL_PATH ?=

OPENSSL_PACKAGE := openssl

ifeq ($(DISTRO),almalinux)
ifeq ($(CENTOSVER),8)
ssl_header_path := $(shell find /usr /usr/local /opt -name "ssl.h" -path "*/openssl3/*" 2>/dev/null | head -n 1)
LIB_SSL_PATH := $(shell find /usr /usr/local /opt -name "libssl.so.3" 2>/dev/null | head -n 1)
LIB_CRYPTO_PATH := $(shell find /usr /usr/local /opt -name "libcrypto.so.3" 2>/dev/null | head -n 1)
OPENSSL_PACKAGE := openssl3
endif
endif

$(info OPENSSL_PACKAGE: $(OPENSSL_PACKAGE))
# Use pkg-config to get the compiler and linker flags for OpenSSL if CUSTOM_OPENSSL_PATH is not set
ifeq ($(CUSTOM_OPENSSL_PATH),)
$(info No custom path specified.)
SSL_IDIR := $(shell pkg-config --cflags --keep-system-cflags $(OPENSSL_PACKAGE) | grep -oP "(?<=-I)[^ ]+")
SSL_LDIR := $(shell pkg-config --variable=libdir $(OPENSSL_PACKAGE) )
LIB_SSL_PATH := $(shell find $(SSL_LDIR) -name "libssl.so" 2>/dev/null | head -n 1)
LIB_CRYPTO_PATH := $(shell find $(SSL_LDIR) -name "libcrypto.so" 2>/dev/null | head -n 1)
else
SSL_IDIR := -I$(CUSTOM_OPENSSL_PATH)/include
SSL_LDIR := -L$(CUSTOM_OPENSSL_PATH)/lib -lssl -lcrypto
$(info Using custom OpenSSL path: $(CUSTOM_OPENSSL_PATH))
endif
SSL_LDIR := $(dir $(LIB_SSL_PATH))

ifneq ($(ssl_header_path),)
SSL_IDIR := $(shell dirname $(shell dirname $(ssl_header_path)))
$(info Found OpenSSL headers at $(SSL_IDIR))
$(info OpenSSL lib full path is $(LIB_SSL_PATH))
$(info OpenSSL libs directory is $(SSL_LDIR))
# Check if required flags are set and provide feedback
ifneq ($(SSL_IDIR),)
$(info SSL_IDIR: $(SSL_IDIR))
$(info SSL_LDIR: $(SSL_LDIR))
$(info LIB_SSL_PATH: $(LIB_SSL_PATH))
$(info LIB_CRYPTO_PATH: $(LIB_CRYPTO_PATH))
else
$(error Warning: OpenSSL headers not found. exiting, please install openssl version 3.)
$(error Warning: OpenSSL headers not found. Exiting. Please install OpenSSL version 3.)
endif

OPENSSL_VERSION_3 := 3.0.0
Expand Down
40 changes: 27 additions & 13 deletions lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,39 @@ COREDUMPER_IDIR := $(COREDUMPER_DIR)/include
CURL_DIR := $(DEPS_PATH)/curl/curl
CURL_IDIR := $(CURL_DIR)/include

ssl_header_path := $(shell find /usr /usr/local /opt -name "ssl.h" -path "*/openssl/*" 2>/dev/null | head -n 1)
LIB_SSL_PATH := $(shell find /usr /usr/local /opt -name "libssl.so" 2>/dev/null | head -n 1)
LIB_CRYPTO_PATH := $(shell find /usr /usr/local /opt -name "libcrypto.so" 2>/dev/null | head -n 1)
CUSTOM_OPENSSL_PATH ?=

OPENSSL_PACKAGE := openssl

ifeq ($(DISTRO),almalinux)
ifeq ($(CENTOSVER),8)
ssl_header_path := $(shell find /usr /usr/local /opt -name "ssl.h" -path "*/openssl3/*" 2>/dev/null | head -n 1)
LIB_SSL_PATH := $(shell find /usr /usr/local /opt -name "libssl.so.3" 2>/dev/null | head -n 1)
LIB_CRYPTO_PATH := $(shell find /usr /usr/local /opt -name "libcrypto.so.3" 2>/dev/null | head -n 1)endif
OPENSSL_PACKAGE := openssl3
endif
endif

$(info OPENSSL_PACKAGE: $(OPENSSL_PACKAGE))

# Use pkg-config to get the compiler and linker flags for OpenSSL if CUSTOM_OPENSSL_PATH is not set
ifeq ($(CUSTOM_OPENSSL_PATH),)
$(info No custom path specified.)
SSL_IDIR := $(shell pkg-config --cflags --keep-system-cflags $(OPENSSL_PACKAGE) | grep -oP "(?<=-I)[^ ]+")
SSL_LDIR := $(shell pkg-config --variable=libdir $(OPENSSL_PACKAGE) )
LIB_SSL_PATH := $(shell find $(SSL_LDIR) -name "libssl.so" 2>/dev/null | head -n 1)
LIB_CRYPTO_PATH := $(shell find $(SSL_LDIR) -name "libcrypto.so" 2>/dev/null | head -n 1)
else
SSL_IDIR := -I$(CUSTOM_OPENSSL_PATH)/include
SSL_LDIR := -L$(CUSTOM_OPENSSL_PATH)/lib -lssl -lcrypto
$(info Using custom OpenSSL path: $(CUSTOM_OPENSSL_PATH))
endif
SSL_LDIR := $(dir $(LIB_SSL_PATH))

ifneq ($(ssl_header_path),)
SSL_IDIR := $(shell dirname $(shell dirname $(ssl_header_path)))
$(info Found OpenSSL headers at $(SSL_IDIR))
$(info OpenSSL lib full path is $(LIB_SSL_PATH))
$(info OpenSSL libs directory is $(SSL_LDIR))
# Check if required flags are set and provide feedback
ifneq ($(SSL_IDIR),)
$(info SSL_IDIR: $(SSL_IDIR))
$(info SSL_LDIR: $(SSL_LDIR))
$(info LIB_SSL_PATH: $(LIB_SSL_PATH))
$(info LIB_CRYPTO_PATH: $(LIB_CRYPTO_PATH))
else
$(error Warning: OpenSSL headers not found. exiting, please install openssl version 3.)
$(error Warning: OpenSSL headers not found. Exiting. Please install OpenSSL version 3.)
endif

EV_DIR := $(DEPS_PATH)/libev/libev/
Expand Down
40 changes: 27 additions & 13 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,39 @@ CURL_PATH := $(DEPS_PATH)/curl/curl
CURL_IDIR := $(CURL_PATH)/include
CURL_LDIR := $(CURL_PATH)/lib/.libs

ssl_header_path := $(shell find /usr /usr/local /opt -name "ssl.h" -path "*/openssl/*" 2>/dev/null | head -n 1)
LIB_SSL_PATH := $(shell find /usr /usr/local /opt -name "libssl.so" 2>/dev/null | head -n 1)
LIB_CRYPTO_PATH := $(shell find /usr /usr/local /opt -name "libcrypto.so" 2>/dev/null | head -n 1)
CUSTOM_OPENSSL_PATH ?=

OPENSSL_PACKAGE := openssl

ifeq ($(DISTRO),almalinux)
ifeq ($(CENTOSVER),8)
ssl_header_path := $(shell find /usr /usr/local /opt -name "ssl.h" -path "*/openssl3/*" 2>/dev/null | head -n 1)
LIB_SSL_PATH := $(shell find /usr /usr/local /opt -name "libssl.so.3" 2>/dev/null | head -n 1)
LIB_CRYPTO_PATH := $(shell find /usr /usr/local /opt -name "libcrypto.so.3" 2>/dev/null | head -n 1)
OPENSSL_PACKAGE := openssl3
endif
endif

$(info OPENSSL_PACKAGE: $(OPENSSL_PACKAGE))

# Use pkg-config to get the compiler and linker flags for OpenSSL if CUSTOM_OPENSSL_PATH is not set
ifeq ($(CUSTOM_OPENSSL_PATH),)
$(info No custom path specified.)
SSL_IDIR := $(shell pkg-config --cflags --keep-system-cflags $(OPENSSL_PACKAGE) | grep -oP "(?<=-I)[^ ]+")
SSL_LDIR := $(shell pkg-config --variable=libdir $(OPENSSL_PACKAGE) )
LIB_SSL_PATH := $(shell find $(SSL_LDIR) -name "libssl.so" 2>/dev/null | head -n 1)
LIB_CRYPTO_PATH := $(shell find $(SSL_LDIR) -name "libcrypto.so" 2>/dev/null | head -n 1)
else
SSL_IDIR := -I$(CUSTOM_OPENSSL_PATH)/include
SSL_LDIR := -L$(CUSTOM_OPENSSL_PATH)/lib -lssl -lcrypto
$(info Using custom OpenSSL path: $(CUSTOM_OPENSSL_PATH))
endif
SSL_LDIR := $(dir $(LIB_SSL_PATH))

ifneq ($(ssl_header_path),)
SSL_IDIR := $(shell dirname $(shell dirname $(ssl_header_path)))
$(info Found OpenSSL headers at $(SSL_IDIR))
$(info OpenSSL lib full path is $(LIB_SSL_PATH))
$(info OpenSSL libs directory is $(SSL_LDIR))
# Check if required flags are set and provide feedback
ifneq ($(SSL_IDIR),)
$(info SSL_IDIR: $(SSL_IDIR))
$(info SSL_LDIR: $(SSL_LDIR))
$(info LIB_SSL_PATH: $(LIB_SSL_PATH))
$(info LIB_CRYPTO_PATH: $(LIB_CRYPTO_PATH))
else
$(error Warning: OpenSSL headers not found. exiting, please install openssl version 3.)
$(error Warning: OpenSSL headers not found. Exiting. Please install OpenSSL version 3.)
endif

EV_PATH := $(DEPS_PATH)/libev/libev/
Expand Down

0 comments on commit e9b57ac

Please sign in to comment.