From c6e28d6087a66b4bd7b4e07dbc81d497f174f058 Mon Sep 17 00:00:00 2001 From: Nick Peng Date: Fri, 15 Dec 2023 22:18:42 +0800 Subject: [PATCH] Makefile: update make file. --- src/Makefile | 18 ++++++++++++++---- src/dns_server.c | 5 +++-- test/Makefile | 6 +++--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/Makefile b/src/Makefile index ac9fb9c..fabec56 100644 --- a/src/Makefile +++ b/src/Makefile @@ -15,8 +15,8 @@ # along with this program. If not, see . BIN=smartdns -OBJS_LIB=lib/rbtree.o lib/art.o lib/bitops.o lib/radix.o lib/timer_wheel.o lib/idna.o lib/conf.o lib/nftset.o -OBJS_MAIN=smartdns.o fast_ping.o dns_client.o dns_server.o dns.o util.o tlog.o dns_conf.o dns_cache.o http_parse.o proxy.o timer.o +OBJS_LIB=$(patsubst %.c,%.o,$(wildcard lib/*.c)) +OBJS_MAIN=$(patsubst %.c,%.o,$(wildcard *.c)) OBJS=$(OBJS_MAIN) $(OBJS_LIB) # cflags @@ -26,13 +26,23 @@ ifndef CFLAGS 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 + CFLAGS +=-Wall -Wstrict-prototypes -fno-omit-frame-pointer -Wstrict-aliasing -funwind-tables -Wmissing-prototypes -Wshadow -Wextra -Wno-unused-parameter -Wno-implicit-fallthrough endif + override CFLAGS +=-Iinclude override CFLAGS += -DBASE_FILE_NAME='"$(notdir $<)"' override CFLAGS += $(EXTRA_CFLAGS) + ifdef VER -override CFLAGS += -DSMARTDNS_VERION='"$(VER)"' + override CFLAGS += -DSMARTDNS_VERION='"$(VER)"' +else + HAS_GIT := $(shell command -v git 2> /dev/null) + ifdef HAS_GIT + IS_GIT_REPO := $(shell git rev-parse --is-inside-work-tree 2>/dev/null) + ifdef IS_GIT_REPO + override CFLAGS += -DSMARTDNS_VERION='"$(shell git describe --tags --always --dirty)"' + endif + endif endif CXXFLAGS=-O2 -g -Wall -std=c++11 diff --git a/src/dns_server.c b/src/dns_server.c index ede1436..57522b7 100644 --- a/src/dns_server.c +++ b/src/dns_server.c @@ -7167,10 +7167,11 @@ static struct addrinfo *_dns_server_getaddr(const char *host, const char *port, const int s = getaddrinfo(host, port, &hints, &result); if (s != 0) { const char *error_str; - if (s == EAI_SYSTEM) + if (s == EAI_SYSTEM) { error_str = strerror(errno); - else + } else { error_str = gai_strerror(s); + } tlog(TLOG_ERROR, "get addr info failed. %s.\n", error_str); goto errout; } diff --git a/test/Makefile b/test/Makefile index 6898cc2..3ff6f5c 100644 --- a/test/Makefile +++ b/test/Makefile @@ -23,9 +23,9 @@ CXXFLAGS += -g CXXFLAGS += -DTEST CXXFLAGS += -I./ -I../src -I../src/include -SMARTDNS_OBJS = lib/rbtree.o lib/art.o lib/bitops.o lib/radix.o lib/conf.o lib/nftset.o lib/timer_wheel.o lib/idna.o -SMARTDNS_OBJS += smartdns.o fast_ping.o dns_client.o dns_server.o dns.o util.o tlog.o dns_conf.o dns_cache.o http_parse.o proxy.o timer.o -OBJS = $(addprefix ../src/, $(SMARTDNS_OBJS)) +OBJS_LIB=$(patsubst %.c,%.o,$(wildcard ../src/lib/*.c)) +OBJS_MAIN=$(patsubst %.c,%.o,$(wildcard ../src/*.c)) +OBJS = $(OBJS_LIB) $(OBJS_MAIN) TEST_SOURCES := $(wildcard *.cc) $(wildcard */*.cc) $(wildcard */*/*.cc) TEST_OBJECTS := $(patsubst %.cc, %.o, $(TEST_SOURCES))