Skip to content

Commit 361dc7e

Browse files
committed
makefile: update make for smartdns-ui plugin
1 parent e228e18 commit 361dc7e

File tree

2 files changed

+42
-11
lines changed

2 files changed

+42
-11
lines changed

package/openwrt/files/etc/init.d/smartdns

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,14 @@ load_service()
856856

857857
config_foreach load_IP_rule_list "ip-rule-list"
858858

859+
config_get_bool ui "$section" "ui" '0'
860+
861+
[ "$ui" = "1" ] && {
862+
conf_append "plugin" "/usr/lib/libsmartdns_ui.so"
863+
conf_append "smartdns-ui.www-root" "/usr/share/smartdns/wwwroot"
864+
conf_append "data-dir" "/etc/smartdns/data"
865+
}
866+
859867
{
860868
echo "conf-file $ADDRESS_CONF"
861869
echo "conf-file $BLACKLIST_IP_CONF"

plugin/smartdns-ui/Makefile

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,43 @@ PREFIX := /usr
1919
SBINDIR := $(PREFIX)/sbin
2020
SLIBDIR := $(PREFIX)/lib
2121
DESTDIR :=
22+
CARGO_BUILD_ENV :=
2223
SMARTDNS_SRC_DIR=../../src
23-
24+
2425
ifeq ($(origin CC), environment)
25-
ARCH_TARGET:=$(shell $(CC) -dumpmachine | sed 's/-[^-]*-linux-/-linux-/')
26-
ARCH=$(shell echo $(ARCH_TARGET) | cut -d - -f 1)
27-
ABI=$(shell echo $(ARCH_TARGET) | cut -d - -f 3)
28-
ifneq ($(ABI),)
29-
RUST_ARCH_TARGET:=$(shell rustc --print target-list | grep $(ARCH) | grep linux | grep $(ABI) | head -n 1)
26+
ifeq ($(CARGO_BUILD_ARGS),)
27+
# find default target by compiler
28+
ARCH_TARGET:=$(shell $(CC) -dumpmachine)
29+
RUST_ARCH_TARGET:=$(shell rustc --print target-list | grep $(ARCH_TARGET) | head -n 1)
30+
31+
ifeq ($(RUST_ARCH_TARGET),)
32+
# not found, try to find target by compiler
33+
ARCH_TARGET:=$(shell $(CC) -dumpmachine | sed 's/-[^-]*-linux-/-linux-/')
34+
ARCH=$(shell echo $(ARCH_TARGET) | cut -d - -f 1)
35+
ABI=$(shell echo $(ARCH_TARGET) | cut -d - -f 3)
36+
ifneq ($(ABI),)
37+
# force set target to $(ARCH)-unknown-linux-$(ABI)
38+
RUST_ARCH_TARGET:=$(shell rustc --print target-list | grep $(ARCH) | grep linux | grep $(ABI) | grep unknown | head -n 1)
39+
endif
40+
endif
41+
42+
ifneq ($(RUST_ARCH_TARGET),)
43+
ARCH_TARGET_PATH=$(RUST_ARCH_TARGET)/
44+
override CARGO_RUSTFLAGS=-C linker=$(CC)
45+
CARGO_BUILD_ARGS +=--target=$(RUST_ARCH_TARGET)
46+
endif
3047
endif
3148

32-
ifneq ($(RUST_ARCH_TARGET),)
33-
ARCH_TARGET_PATH=$(RUST_ARCH_TARGET)/
34-
override CARGO_RUSTFLAGS=-C linker=$(CC)
35-
CARGO_BUILD_ARGS +=--target=$(RUST_ARCH_TARGET)
49+
# find sysroot
50+
SYSROOT:=$(shell $(CC) -print-sysroot)
51+
ifeq ($(SYSROOT),)
52+
# if sysroot is not set, try find sysroot from compiler default include path
53+
SYSROOT:=$(shell $(CC) -xc /dev/null -E -Wp,-v 2>&1 | sed -n 's,^ ,,p' | head -n 1)
54+
ifneq ($(SYSROOT),)
55+
# find sysroot, add sysroot to BINDGEN_EXTRA_CLANG_ARGS
56+
SYSROOT:=$(SYSROOT)/..
57+
override CARGO_BUILD_ENV += BINDGEN_EXTRA_CLANG_ARGS="--sysroot=$(SYSROOT)"
58+
endif
3659
endif
3760
endif
3861

@@ -64,7 +87,7 @@ test-prepare:
6487
$(MAKE) -C $(SMARTDNS_SRC_DIR) libsmartdns-test.a
6588

6689
$(BIN):
67-
MAKEFLAGS= RUSTFLAGS="$(CARGO_RUSTFLAGS) $(RUSTFLAGS)" cargo build $(CARGO_BUILD_ARGS) --features "build-release"
90+
MAKEFLAGS= RUSTFLAGS="$(CARGO_RUSTFLAGS) $(RUSTFLAGS)" $(CARGO_BUILD_ENV) cargo build $(CARGO_BUILD_ARGS) --features "build-release"
6891
cp $(CARGO_BUILD_PATH)/libsmartdns_ui.so target/
6992

7093
install: $(BIN)

0 commit comments

Comments
 (0)