xref: /linux/tools/lib/symbol/Makefile (revision 473f6c8f437b049f8ec015d57cd59bb983b1d85c)
1# SPDX-License-Identifier: GPL-2.0
2include ../../scripts/Makefile.include
3include ../../scripts/utilities.mak		# QUIET_CLEAN
4
5ifeq ($(srctree),)
6srctree := $(patsubst %/,%,$(dir $(CURDIR)))
7srctree := $(patsubst %/,%,$(dir $(srctree)))
8srctree := $(patsubst %/,%,$(dir $(srctree)))
9#$(info Determined 'srctree' to be $(srctree))
10endif
11
12MAKEFLAGS += --no-print-directory
13
14INSTALL = install
15
16
17# Use DESTDIR for installing into a different root directory.
18# This is useful for building a package. The program will be
19# installed in this directory as if it was the root directory.
20# Then the build tool can move it later.
21DESTDIR ?=
22DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
23
24LIBFILE = $(OUTPUT)libsymbol.a
25
26CFLAGS := $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
27CFLAGS += -ggdb3 -Wall -Wextra -std=gnu11 -U_FORTIFY_SOURCE -fPIC
28
29ifeq ($(DEBUG),0)
30  CFLAGS += -O3
31endif
32
33ifeq ($(DEBUG),0)
34  CFLAGS += -D_FORTIFY_SOURCE
35endif
36
37# Treat warnings as errors unless directed not to
38ifneq ($(WERROR),0)
39  CFLAGS += -Werror
40endif
41
42CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
43
44CFLAGS += -I$(srctree)/tools/lib
45CFLAGS += -I$(srctree)/tools/include
46
47RM = rm -f
48
49SYMBOL_IN := $(OUTPUT)libsymbol-in.o
50
51ifeq ($(LP64), 1)
52  libdir_relative = lib64
53else
54  libdir_relative = lib
55endif
56
57prefix ?=
58libdir = $(prefix)/$(libdir_relative)
59
60# Shell quotes
61libdir_SQ = $(subst ','\'',$(libdir))
62
63all:
64
65export srctree OUTPUT CC LD CFLAGS V
66include $(srctree)/tools/build/Makefile.include
67include $(srctree)/tools/scripts/Makefile.include
68
69all: fixdep $(LIBFILE)
70
71$(SYMBOL_IN): FORCE
72	@$(MAKE) $(build)=libsymbol
73
74$(LIBFILE): $(SYMBOL_IN)
75	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(SYMBOL_IN)
76
77define do_install_mkdir
78	if [ ! -d '$(DESTDIR_SQ)$1' ]; then             \
79		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
80	fi
81endef
82
83define do_install
84	if [ ! -d '$2' ]; then             \
85		$(INSTALL) -d -m 755 '$2'; \
86	fi;                                \
87	$(INSTALL) $1 $(if $3,-m $3,) '$2'
88endef
89
90install_lib: $(LIBFILE)
91	$(call QUIET_INSTALL, $(LIBFILE)) \
92		$(call do_install_mkdir,$(libdir_SQ)); \
93		cp -fpR $(LIBFILE) $(DESTDIR)$(libdir_SQ)
94
95HDRS := kallsyms.h
96INSTALL_HDRS_PFX := $(DESTDIR)$(prefix)/include/symbol
97INSTALL_HDRS := $(addprefix $(INSTALL_HDRS_PFX)/, $(HDRS))
98
99$(INSTALL_HDRS): $(INSTALL_HDRS_PFX)/%.h: %.h
100	$(call QUIET_INSTALL, $@) \
101		$(call do_install,$<,$(INSTALL_HDRS_PFX)/,644)
102
103install_headers: $(INSTALL_HDRS)
104	$(call QUIET_INSTALL, libsymbol_headers)
105
106install: install_lib install_headers
107
108clean:
109	$(call QUIET_CLEAN, libsymbol) $(RM) $(LIBFILE); \
110	find $(or $(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM)
111
112FORCE:
113
114.PHONY: clean FORCE
115