From 93b6c6d85c6f197880a14f85c096d3198bff99b6 Mon Sep 17 00:00:00 2001 From: r4sas Date: Mon, 17 Aug 2020 10:52:30 +0000 Subject: [PATCH] add static build for linux Signed-off-by: r4sas --- Makefile | 32 ++++++++++++++++++++++++++------ Makefile.mingw | 2 +- README.md | 2 ++ 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 212153e..f8a60d8 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,36 @@ -SYS := $(shell $(CXX) -dumpmachine) -CXX = g++ +CXX := g++ +SYS = $(shell $(CXX) -dumpmachine) + +STATIC := no +DEBUG := no SYG_SRC = sygcpp.cpp SYGCPP = sygcpp -LDFLAGS = -O3 -s -LDLIBS = -lcrypto -lpthread +ifeq ($(DEBUG),yes) + CXX_DEBUG = -g +else + LD_DEBUG = -s +endif + +CXXFLAGS = $(CXX_DEBUG) -fPIC +LDFLAGS = $(LD_DEBUG) -Os -SYG_OBJS += $(patsubst %.cpp,obj/%.o,$(SYG_SRC)) +SYG_OBJS = $(patsubst %.cpp,obj/%.o,$(SYG_SRC)) ifneq (, $(findstring mingw, $(SYS))$(findstring cygwin, $(SYS))) include Makefile.mingw +else + ifeq ($(STATIC),yes) + LIBPATH = /usr/lib/$(SYS) + LDLIBS = -pthread $(LIBPATH)/libcrypto.a -lpthread -ldl + else ifeq ($(STATIC),full) + LIBPATH = /usr/lib/$(SYS) + LDFLAGS += -static + LDLIBS = -pthread $(LIBPATH)/libcrypto.a -lpthread -ldl + else + LDLIBS = -lcrypto -lpthread + endif endif all: mk_obj_dir $(SYGCPP) @@ -22,7 +42,7 @@ clean: $(RM) -r obj $(SYGCPP) obj/%.o: %.cpp - $(CXX) -c -o $@ $< + $(CXX) -c $(CXXFLAGS) $< -o $@ $(SYGCPP): $(SYG_OBJS) $(CXX) -o $@ $^ $(LDFLAGS) $(LDLIBS) diff --git a/Makefile.mingw b/Makefile.mingw index 3cedfc1..ca73993 100644 --- a/Makefile.mingw +++ b/Makefile.mingw @@ -2,7 +2,7 @@ WINDRES = windres SYG_RC = windows/resource.rc -LDFLAGS = -O3 -s -Wl,-Bstatic +LDFLAGS = $(LD_DEBUG) -Os -Wl,-Bstatic LDLIBS = -static-libgcc -lcrypto -lws2_32 -lpthread SYG_OBJS += $(patsubst %.rc,obj/%.o,$(SYG_RC)) diff --git a/README.md b/README.md index 814a3f0..89fffdf 100644 --- a/README.md +++ b/README.md @@ -32,3 +32,5 @@ make ``` * Run it using `./sygcpp` + +*Note*: If you want compile static binary, add `STATIC=yes` or `STATIC=full` to `make` command. That works only on Linux.