Makefile 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Copyright (C) 2018-2023 Ruilin Peng (Nick) <[email protected]>.
  2. #
  3. # smartdns is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # smartdns is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. BIN=smartdns
  16. OBJS_LIB=$(patsubst %.c,%.o,$(wildcard lib/*.c))
  17. OBJS_MAIN=$(patsubst %.c,%.o,$(wildcard *.c))
  18. OBJS=$(OBJS_MAIN) $(OBJS_LIB)
  19. # cflags
  20. ifndef CFLAGS
  21. ifdef DEBUG
  22. CFLAGS = -g -DDEBUG
  23. else
  24. CFLAGS = -O2
  25. endif
  26. CFLAGS +=-Wall -Wstrict-prototypes -fno-omit-frame-pointer -Wstrict-aliasing -funwind-tables -Wmissing-prototypes -Wshadow -Wextra -Wno-unused-parameter -Wno-implicit-fallthrough
  27. endif
  28. override CFLAGS +=-Iinclude
  29. override CFLAGS += -DBASE_FILE_NAME='"$(notdir $<)"'
  30. override CFLAGS += $(EXTRA_CFLAGS)
  31. ifdef VER
  32. override CFLAGS += -DSMARTDNS_VERION='"$(VER)"'
  33. else
  34. HAS_GIT := $(shell command -v git 2> /dev/null)
  35. ifdef HAS_GIT
  36. IS_GIT_REPO := $(shell git rev-parse --is-inside-work-tree 2>/dev/null)
  37. ifdef IS_GIT_REPO
  38. override CFLAGS += -DSMARTDNS_VERION='"$(shell git describe --tags --always --dirty)"'
  39. endif
  40. endif
  41. endif
  42. CXXFLAGS=-O2 -g -Wall -std=c++11
  43. override CXXFLAGS +=-Iinclude
  44. # ldflags
  45. ifeq ($(STATIC), yes)
  46. override LDFLAGS += -lssl -lcrypto -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -ldl -lm -static
  47. else ifeq ($(SSL_STATIC), yes)
  48. override LDFLAGS += -Wl,-Bstatic -lssl -lcrypto -Wl,-Bdynamic -lpthread -ldl -lm
  49. else
  50. override LDFLAGS += -lssl -lcrypto -lpthread -ldl -lm
  51. endif
  52. .PHONY: all clean
  53. all: $(BIN)
  54. $(BIN) : $(OBJS)
  55. $(CC) $(OBJS) -o $@ $(LDFLAGS)
  56. clang-tidy:
  57. clang-tidy -p=. $(OBJS_MAIN:.o=.c) -- $(CFLAGS)
  58. clean:
  59. $(RM) $(OBJS) $(BIN)