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