commit 2fcbb05110545d8ae3cd25fe087b8b71374f102d
parent d4506d24bce69994dd2cf1c240ae8a4a7a403a49
Author: bsandro <email@bsandro.tech>
Date: Sun, 7 Sep 2025 10:24:50 +0300
Minimizing the size of the release binary
Diffstat:
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/gui/Makefile b/gui/Makefile
@@ -4,24 +4,24 @@ DEPS:=$(wildcard ../include/*.h)
OBJ:=$(SRC:.c=.o)
LIBS:=libwebp libwebpdemux
ifeq ($(OS),Windows_NT)
+$(info OS is $(OS))
else
LIBS+=x11
endif
-CFLAGS=-std=c99 -ffast-math -I. -I../include/ ${shell pkg-config --cflags $(LIBS)}
+CFLAGS=-std=c99 -ffast-math -fno-stack-protector -fomit-frame-pointer -fwrapv -ffunction-sections -fdata-sections -fno-asynchronous-unwind-tables -fno-unwind-tables -fmerge-all-constants -fno-ident -march=native -I. -I../include/ ${shell pkg-config --cflags $(LIBS)}
ifeq ($(DEBUG),1)
CFLAGS+=-O0 -g
else
-CFLAGS+=-O2
+CFLAGS+=-Os -s
endif
-LDFLAGS=-lc -lm ${shell pkg-config --libs $(LIBS)}
+LDFLAGS=-lc -lm -Wl,--gc-sections ${shell pkg-config --libs $(LIBS)}
ifeq ($(OS),Windows_NT)
CFLAGS+=-DUI_WINDOWS
LDFLAGS+=-lgdi32 -luser32 -lshell32
else
CFLAGS+=-DUI_LINUX
endif
-
-$(info OS is $(OS))
+UPX_FOUND:=$(shell command -v upx 2>/dev/null)
all: $(NAME)
@@ -36,5 +36,17 @@ clean:
$(NAME): $(OBJ)
$(CC) $(OBJ) -o ../$@ $(LDFLAGS)
-run: $(NAME)
+strip: $(NAME)
+ strip -S --strip-unneeded --remove-section=.note.gnu.gold-version --remove-section=.comment --remove-section=.note --remove-section=.note.gnu.build-id --remove-section=.note.ABI-tag ../$(NAME)
+
+upx: strip
+ifdef UPX_FOUND
+ upx --ultra-brute ../$(NAME)
+else
+ @echo "upx is not installed"
+endif
+ @echo -ne "file size: "
+ @stat -c%s ../$(NAME)
+
+run: upx
../$(NAME)