From c6069c067a477b21bd792a42fb1f57ad6fefbc65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Peccatte?= Date: Thu, 18 Mar 2021 17:35:12 +0100 Subject: [PATCH] Fixes #19046: Add windows support to http client build --- agent/sources/client/Makefile | 38 +++++++++++++++++++++++++++------ agent/sources/client/toml.patch | 11 ++++++++++ 2 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 agent/sources/client/toml.patch diff --git a/agent/sources/client/Makefile b/agent/sources/client/Makefile index ceda709da1d..b4a0a2bdc74 100644 --- a/agent/sources/client/Makefile +++ b/agent/sources/client/Makefile @@ -30,7 +30,7 @@ CFLAGS ?= -std=c99 -Wall -Wextra -Wpedantic \ -Wredundant-decls -Wnested-externs -Wmissing-include-dirs \ -D_FORTIFY_SOURCE=2 -fstack-protector-strong -fPIE BUILD_CFLAGS=$(CFLAGS) -LDFLAGS ?= -Wl,-z,now -Wl,-z,relro -pie +LDFLAGS ?= -Wl,-z,now -Wl,-z,relro -pie -fstack-protector-strong BUILD_LDFLAGS=$(LDFLAGS) # Debug flags CFLAGS_DEBUG := -O -g3 -DDEBUG -fsanitize=address,undefined @@ -42,15 +42,28 @@ endif CFLAGS_RELEASE := -O2 BUILD_LDFLAGS += -lcurl -lm +BUILD_DEP:= + # to use static tomlc use: make STATIC_TOML=1 # in this case you need to put its sources in ./tomlc99/ ifdef STATIC_TOML BUILD_CFLAGS += -I./tomlc99 BUILD_LDFLAGS += ./tomlc99/libtoml.a +BUILD_DEP += toml else BUILD_LDFLAGS += -ltoml endif +# Cross compilation +# you need the mingw-w64 package for this +ifeq (windows,$(TARGET)) +CC := x86_64-w64-mingw32-gcc +BUILD_DEP += curl +BUILD_CFLAGS += -I./curl/include/ +BUILD_LDFLAGS += -L./curl/lib/ +EXEC := rudder_client.exe +endif + # build is debug b : build build: BUILD_CFLAGS += $(CFLAGS_DEBUG) @@ -63,12 +76,23 @@ $(BUILD_DIR): install -d $(BUILD_DIR) # No separate dirs for debug and release, we clean at every run -bin-target: clean $(BUILD_DIR) toml $(BUILD_DIR)/$(EXEC) - -toml: -ifdef STATIC_TOML - cd tomlc99 && $(MAKE) "CFLAGS=$(BUILD_CFLAGS) -std=c99 -fPIC" -endif +bin-target: clean $(BUILD_DIR) $(BUILD_DEP) $(BUILD_DIR)/$(EXEC) + +curl: + wget -nv http://repository.rudder.io/build-dependencies/curl/curl-7.69.1_1-win64-mingw.zip + unzip curl-7.69.1_1-win64-mingw.zip + mv curl-7.69.1-win64-mingw/ curl + rm curl-7.69.1_1-win64-mingw.zip + +tomlc99: + wget -nv http://repository.rudder.io/build-dependencies/tomlc99/tomlc99-c5d2e37.tar.gz + tar xf tomlc99-c5d2e37.tar.gz + mv tomlc99-master tomlc99 + rm tomlc99-c5d2e37.tar.gz + patch -p1 < toml.patch + +toml: tomlc99 + cd tomlc99 && $(MAKE) CC=$(CC) "CFLAGS=$(CFLAGS) -std=c99 -fPIC" LDFLAGS="$(LDFLAGS)" $(BUILD_DIR)/%.o: $(SRC_DIR)/%.c $(CC) $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) -c -o $@ $< diff --git a/agent/sources/client/toml.patch b/agent/sources/client/toml.patch new file mode 100644 index 00000000000..7ab7d13bfb8 --- /dev/null +++ b/agent/sources/client/toml.patch @@ -0,0 +1,11 @@ +--- a/tomlc99/Makefile 2021-01-28 03:53:31.000000000 +0100 ++++ b/tomlc99/Makefile 2021-03-18 17:24:24.440455804 +0100 +@@ -24,7 +24,7 @@ + ar -rcs $@ $^ + + libtoml.so: toml.o +- $(CC) -shared -o $@ $^ ++ $(CC) $(LDFLAGS) -shared -o $@ $^ + + toml_json: toml_json.c $(LIB) +