Makefile 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #!/usr/bin/make -f
  2. # SPDX-License-Identifier: MIT
  3. #
  4. # batman-adv helpers functions library
  5. #
  6. # Copyright (c) 2017, Sven Eckelmann <sven@narfation.org>
  7. #
  8. # Permission is hereby granted, free of charge, to any person obtaining a copy
  9. # of this software and associated documentation files (the "Software"), to deal
  10. # in the Software without restriction, including without limitation the rights
  11. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. # copies of the Software, and to permit persons to whom the Software is
  13. # furnished to do so, subject to the following conditions:
  14. #
  15. # The above copyright notice and this permission notice shall be included in
  16. # all copies or substantial portions of the Software.
  17. #
  18. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. # THE SOFTWARE.
  25. # libbatadv build
  26. BINARY_NAME = libbatadv.so
  27. OBJ += batadv-genl.o
  28. # headers to install
  29. HEADER += batadv-genl.h
  30. HEADER += batman_adv.h
  31. # libbatadv flags and options
  32. CFLAGS += -pedantic -Wall -W -MD -MP
  33. CFLAGS += -fPIC -fvisibility=hidden
  34. CPPFLAGS += -D_GNU_SOURCE
  35. LDLIBS +=
  36. LDFLAGS += -shared -Wl,-export-dynamic
  37. # disable verbose output
  38. ifneq ($(findstring $(MAKEFLAGS),s),s)
  39. ifndef V
  40. Q_CC = @echo ' ' CC $@;
  41. Q_LD = @echo ' ' LD $@;
  42. export Q_CC
  43. export Q_LD
  44. endif
  45. endif
  46. ifeq ($(origin PKG_CONFIG), undefined)
  47. PKG_CONFIG = pkg-config
  48. ifeq ($(shell which $(PKG_CONFIG) 2>/dev/null),)
  49. $(error $(PKG_CONFIG) not found)
  50. endif
  51. endif
  52. ifeq ($(origin LIBNL_CFLAGS) $(origin LIBNL_LDLIBS), undefined undefined)
  53. LIBNL_NAME ?= libnl-3.0
  54. ifeq ($(shell $(PKG_CONFIG) --modversion $(LIBNL_NAME) 2>/dev/null),)
  55. $(error No $(LIBNL_NAME) development libraries found!)
  56. endif
  57. LIBNL_CFLAGS += $(shell $(PKG_CONFIG) --cflags $(LIBNL_NAME))
  58. LIBNL_LDLIBS += $(shell $(PKG_CONFIG) --libs $(LIBNL_NAME))
  59. endif
  60. CFLAGS += $(LIBNL_CFLAGS)
  61. LDLIBS += $(LIBNL_LDLIBS)
  62. ifeq ($(origin LIBNL_GENL_CFLAGS) $(origin LIBNL_GENL_LDLIBS), undefined undefined)
  63. LIBNL_GENL_NAME ?= libnl-genl-3.0
  64. ifeq ($(shell $(PKG_CONFIG) --modversion $(LIBNL_GENL_NAME) 2>/dev/null),)
  65. $(error No $(LIBNL_GENL_NAME) development libraries found!)
  66. endif
  67. LIBNL_GENL_CFLAGS += $(shell $(PKG_CONFIG) --cflags $(LIBNL_GENL_NAME))
  68. LIBNL_GENL_LDLIBS += $(shell $(PKG_CONFIG) --libs $(LIBNL_GENL_NAME))
  69. endif
  70. CFLAGS += $(LIBNL_GENL_CFLAGS)
  71. LDLIBS += $(LIBNL_GENL_LDLIBS)
  72. # standard build tools
  73. CC ?= gcc
  74. RM ?= rm -f
  75. INSTALL ?= install
  76. MKDIR ?= mkdir -p
  77. COMPILE.c = $(Q_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
  78. LINK.o = $(Q_LD)$(CC) $(CFLAGS) $(LDFLAGS) $(TARGET_ARCH)
  79. # standard install paths
  80. PREFIX = /usr/local
  81. INCLUDEDIR = $(PREFIX)/include
  82. LIBDIR = $(PREFIX)/lib
  83. # default target
  84. all: $(BINARY_NAME)
  85. # standard build rules
  86. .SUFFIXES: .o .c
  87. .c.o:
  88. $(COMPILE.c) -o $@ $<
  89. $(BINARY_NAME): $(OBJ)
  90. $(LINK.o) $^ $(LDLIBS) -o $@
  91. clean:
  92. $(RM) $(BINARY_NAME) $(OBJ) $(DEP)
  93. install: $(BINARY_NAME)
  94. $(MKDIR) $(DESTDIR)$(LIBDIR)
  95. $(MKDIR) $(DESTDIR)$(INCLUDEDIR)
  96. $(INSTALL) -m 0755 $(BINARY_NAME) $(DESTDIR)$(LIBDIR)
  97. $(INSTALL) -m 0644 $(HEADER) $(DESTDIR)$(INCLUDEDIR)
  98. # load dependencies
  99. DEP = $(OBJ:.o=.d)
  100. -include $(DEP)
  101. .PHONY: all clean install
  102. .DELETE_ON_ERROR:
  103. .DEFAULT_GOAL := all