Skip to content

Commit

Permalink
add CONFIG_STATIC to skip linking for static binary builds
Browse files Browse the repository at this point in the history
Signed-off-by: strawberry <strawberry@pupbrain.dev>
  • Loading branch information
girlbossceo committed Apr 10, 2024
1 parent 67aea43 commit dd52b42
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,20 @@ $(shell $(CC) $(if $(filter clang%,$(CC)),-Werror=unknown-warning-option) -E $1
endef

CPPFLAGS := $(CPPFLAGS) -D_GNU_SOURCE -I include
SHARED_FLAGS := -pipe -O3 -flto -fPIC -fvisibility=hidden -fno-plt \
SHARED_FLAGS := -pipe -O3 -fPIC -fvisibility=hidden -fno-plt \
-fstack-clash-protection $(call safe_flag,-fcf-protection) -fstack-protector-strong \
-Wall -Wextra $(call safe_flag,-Wcast-align=strict,-Wcast-align) -Wcast-qual -Wwrite-strings \
-Wundef

# assume dynamic build if not specified
ifeq ($(CONFIG_STATIC),)
SHARED_FLAGS += -flto
else ifeq ($(CONFIG_STATIC),false)
SHARED_FLAGS += -flto
else ifeq ($(CC),"gcc")
SHARED_FLAGS += -flto
endif

ifeq ($(CONFIG_WERROR),true)
SHARED_FLAGS += -Werror
endif
Expand Down Expand Up @@ -110,8 +119,15 @@ CPPFLAGS += \
-DCONFIG_STATS=$(CONFIG_STATS) \
-DCONFIG_SELF_INIT=$(CONFIG_SELF_INIT)

$(OUT)/libhardened_malloc$(SUFFIX).so: $(OBJECTS)

ifeq ($(CONFIG_STATIC),)
$(OUT)/libhardened_malloc$(SUFFIX).so: $(OBJECTS) | $(OUT)
$(CC) $(CFLAGS) $(LDFLAGS) -shared $^ $(LDLIBS) -o $@
else ifeq ($(CONFIG_STATIC),false)
$(OUT)/libhardened_malloc$(SUFFIX).so: $(OBJECTS) | $(OUT)
$(CC) $(CFLAGS) $(LDFLAGS) -shared $^ $(LDLIBS) -o $@
endif

$(OUT):
mkdir -p $(OUT)
Expand Down
1 change: 1 addition & 0 deletions config/default.mk
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CONFIG_STATIC := false
CONFIG_WERROR := true
CONFIG_NATIVE := true
CONFIG_CXX_ALLOCATOR := true
Expand Down
1 change: 1 addition & 0 deletions config/light.mk
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CONFIG_STATIC := false
CONFIG_WERROR := true
CONFIG_NATIVE := true
CONFIG_CXX_ALLOCATOR := true
Expand Down

0 comments on commit dd52b42

Please sign in to comment.