#
# Linux
#
# Make settings for Linux/clang (C++20)
#
#

#
# General Settings
#
LINKMODE ?= SHARED

ARCHFLAGS     ?=
OSFLAGS       ?=
SANITIZEFLAGS ?=
#
# sanitize flags:
#

#  -fsanitize=address

# UBSan adds the vptr sanitizer, and V8 exposes polymorphic
# classes (e.g., v8::ArrayBuffer::Allocator) without RTTI
# in the shared library. When we build the JS components
# with -fsanitize=undefined, the vptr checks require typeinfo
# for every polymorphic class; since V8 stripped it, the linker
# trips over typeinfo for v8::ArrayBuffer::Allocator.
# With vptr checks disabled, linking against V8 succeeds, and
# UBSan still covers the other undefined-behavior categories.
#  -fsanitize=undefined -fno-sanitize=vptr

#  -fsanitize=thread
#  -fsanitize=memory

# Define Tools
#
CC      = clang$(CLANG_VERSION)
CXX     = clang++$(CLANG_VERSION)
LINK    = $(CXX)
LIB     = ${CROSS_COMPILE}ar -cr
RANLIB  = ${CROSS_COMPILE}ranlib
SHLIB   = $(CXX) -shared -Wl,-soname,$(notdir $@) -o $@
SHLIBLN = $(POCO_BASE)/build/script/shlibln
STRIP   = ${CROSS_COMPILE}strip
DEP     = $(POCO_BASE)/build/script/makedepend.gcc
SHELL   = sh
RM      = rm -rf
CP      = cp
MKDIR   = mkdir -p

#
# Extension for Shared Libraries
#
SHAREDLIBEXT     = .so.$(target_version)
SHAREDLIBLINKEXT = .so

#
# Compiler and Linker Flags
#
CFLAGS          = $(ARCHFLAGS) $(OSFLAGS) $(SANITIZEFLAGS) -std=c11
CFLAGS32        = $(ARCHFLAGS) $(OSFLAGS) $(SANITIZEFLAGS)
CFLAGS64        = $(ARCHFLAGS) $(OSFLAGS) $(SANITIZEFLAGS)
CXXFLAGS        = $(ARCHFLAGS) $(OSFLAGS) $(SANITIZEFLAGS) -std=c++20 -Wall -Wno-sign-compare
CXXFLAGS32      = $(ARCHFLAGS) $(OSFLAGS) $(SANITIZEFLAGS)
CXXFLAGS64      = $(ARCHFLAGS) $(OSFLAGS) $(SANITIZEFLAGS)
LINKFLAGS       = $(ARCHFLAGS) $(OSFLAGS) $(SANITIZEFLAGS) -stdlib=libstdc++
LINKFLAGS32     =
LINKFLAGS64     =
STATICOPT_CC    =
STATICOPT_CXX   =
STATICOPT_LINK  = -static
SHAREDOPT_CC    = -fPIC
SHAREDOPT_CXX   = -fPIC
SHAREDOPT_LINK  = -Wl,-rpath,$(LIBPATH)
DEBUGOPT_CC     = -O0 -g3 -gdwarf-5 -fno-omit-frame-pointer -D_DEBUG
DEBUGOPT_CXX    = -O0 -g3 -gdwarf-5 -fno-omit-frame-pointer -D_DEBUG
DEBUGOPT_LINK   = -g3 -gdwarf-5 -fno-lto -Wl,--build-id -Wl,--no-gc-sections
RELEASEOPT_CC   = -O2 -DNDEBUG
RELEASEOPT_CXX  = -O2 -DNDEBUG
RELEASEOPT_LINK = -O2

# Standard library selection fixed to libstdc++ to match prebuilt libnode

#
# System Specific Flags
#
SYSFLAGS = -D_XOPEN_SOURCE=600 -D_REENTRANT -D_THREAD_SAFE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -DPOCO_HAVE_FD_EPOLL

#
# System Specific Libraries
#
SYSLIBS  = -lpthread -ldl -lrt
