Преглед на файлове

makefile: update makefile

Nick Peng преди 6 месеца
родител
ревизия
d92371d6ed
променени са 2 файла, в които са добавени 33 реда и са изтрити 12 реда
  1. 8 0
      plugin/smartdns-ui/Cargo.toml
  2. 25 12
      plugin/smartdns-ui/Makefile

+ 8 - 0
plugin/smartdns-ui/Cargo.toml

@@ -45,3 +45,11 @@ tempfile = "3.16.0"
 
 [build-dependencies]
 bindgen = "0.69.5"
+
+[profile.release-optmize-size]
+inherits = "release"
+lto = true
+opt-level = "s"
+strip = true
+codegen-units = 1
+panic = "abort"

+ 25 - 12
plugin/smartdns-ui/Makefile

@@ -21,26 +21,39 @@ SLIBDIR := $(PREFIX)/lib
 DESTDIR :=
 SMARTDNS_SRC_DIR=../../src
 
-ARCH_TARGET:=$(shell $(CC) -dumpmachine | sed 's/-[^-]*-/-/')
-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)/
+ifeq ($(origin CC), environment)
+  ARCH_TARGET:=$(shell $(CC) -dumpmachine | sed 's/-[^-]*-linux-/-linux-/')
+  ARCH=$(shell echo $(ARCH_TARGET) | cut -d - -f 1)
+  ABI=$(shell echo $(ARCH_TARGET) | cut -d - -f 3)
+  ifneq ($(ABI),)
+    RUST_ARCH_TARGET:=$(shell rustc --print target-list | grep $(ARCH) | grep linux | grep $(ABI) | head -n 1)
+  endif
+
+  ifneq ($(RUST_ARCH_TARGET),)
+    ARCH_TARGET_PATH=$(RUST_ARCH_TARGET)/
+    override CARGO_RUSTFLAGS=-C linker=$(CC)
+    CARGO_BUILD_ARGS +=--target=$(RUST_ARCH_TARGET)
+  endif
+endif
 
-override CARGO_RUSTFLAGS=-C linker=$(CC)
-CARGO_BUILD_ARGS +=--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_PATH=target/$(ARCH_TARGET_PATH)debug
-SMARTDNS_BUILD_TYPE=DEBUG=1
+  CARGO_BUILD_PATH=target/$(ARCH_TARGET_PATH)debug
+  SMARTDNS_BUILD_TYPE=DEBUG=1
 else
-CARGO_BUILD_ARGS +=--release
-CARGO_BUILD_PATH=target/$(ARCH_TARGET_PATH)release
-SMARTDNS_BUILD_TYPE=
+  ifdef OPTIMIZE_SIZE
+    CARGO_BUILD_ARGS += --profile release-optmize-size
+	CARGO_BUILD_PATH=target/$(ARCH_TARGET_PATH)release-optmize-size
+  else
+    CARGO_BUILD_ARGS +=--release
+  	CARGO_BUILD_PATH=target/$(ARCH_TARGET_PATH)release
+  endif
+
+  SMARTDNS_BUILD_TYPE=
 endif
 
 .PHONY: all clean install $(BIN)