Browse Source

make: update makefile for UI.

Nick Peng 7 months ago
parent
commit
7ee2e1e864
2 changed files with 26 additions and 6 deletions
  1. 17 5
      plugin/smartdns-ui/Makefile
  2. 9 1
      src/Makefile

+ 17 - 5
plugin/smartdns-ui/Makefile

@@ -21,13 +21,25 @@ SLIBDIR := $(PREFIX)/lib
 DESTDIR :=
 SMARTDNS_SRC_DIR=../../src
 
+ARCH_TARGET:=$(shell $(CC) -dumpmachine | sed 's/-unknown-/-/')
+ARCH=$(shell echo $(ARCH_TARGET) | cut -d - -f 1)
+ABI=$(shell echo $(ARCH_TARGET) | cut -d - -f 3)
+ARCH_TARGET:=$(shell rustc --print target-list | grep $(ARCH) | grep linux | grep $(ABI) | head -n 1)
+ARCH_TARGET_PATH=$(ARCH_TARGET)/
+
+override CARGO_RUSTFLAGS=-C linker=$(CC)
+CARGO_BUILD_TYPE +=--target=$(ARCH_TARGET)
+IS_MUSL=$(shell $(CC) -v 2>&1 | grep -i musl >/dev/null 2>&1 && echo 1 || echo 0)
+ifeq ($(IS_MUSL), 1)
+override CARGO_RUSTFLAGS +=-C target-feature=-crt-static
+endif
+
 ifdef DEBUG
-CARGO_BUILD_TYPE=
-CARGO_BUILD_PATH=target/debug
+CARGO_BUILD_PATH=target/$(ARCH_TARGET_PATH)debug
 SMARTDNS_BUILD_TYPE=DEBUG=1
 else
-CARGO_BUILD_TYPE=--release
-CARGO_BUILD_PATH=target/release
+CARGO_BUILD_TYPE +=--release
+CARGO_BUILD_PATH=target/$(ARCH_TARGET_PATH)release
 SMARTDNS_BUILD_TYPE=
 endif
 
@@ -39,7 +51,7 @@ test-prepare:
 	$(MAKE) -C $(SMARTDNS_SRC_DIR) libsmartdns-test.a
 
 $(BIN):
-	MAKEFLAGS= cargo build $(CARGO_BUILD_TYPE) --features "build-release"
+	MAKEFLAGS= RUSTFLAGS="$(CARGO_RUSTFLAGS) $(RUSTFLAGS)" cargo build $(CARGO_BUILD_TYPE) --features "build-release"
 	cp $(CARGO_BUILD_PATH)/libsmartdns_ui.so target/ 
 
 install: $(BIN)

+ 9 - 1
src/Makefile

@@ -25,7 +25,11 @@ OBJS=$(OBJS_MAIN) $(OBJS_LIB)
 
 # cflags
 ifndef CFLAGS
- CFLAGS = -g -DDEBUG
+ ifdef DEBUG
+  CFLAGS = -g -DDEBUG
+ else
+  CFLAGS = -O2
+ endif
  CFLAGS +=-Wall -Wstrict-prototypes -fno-omit-frame-pointer -Wstrict-aliasing -funwind-tables -Wmissing-prototypes -Wshadow -Wextra -Wno-unused-parameter -Wno-implicit-fallthrough
 endif
 
@@ -61,6 +65,10 @@ CXXFLAGS=-O2 -g -Wall -std=c++11
 override CXXFLAGS +=-Iinclude
 
 ifeq ($(STATIC), yes)
+STATIC = 1
+endif
+
+ifdef STATIC
  override CFLAGS += -DBUILD_STATIC
  override LDFLAGS += -lssl -lcrypto -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -ldl -lm -static -rdynamic
 else