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) 34 CFLAGS += -O3 35endif 36 37ifeq ($(DEBUG),0) 38 CFLAGS += -D_FORTIFY_SOURCE 39endif 40 41# Treat warnings as errors unless directed not to 42ifneq ($(WERROR),0) 43 CFLAGS += -Werror 44endif 45 46CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 47 48CFLAGS += -I$(srctree)/tools/lib 49CFLAGS += -I$(srctree)/tools/include 50 51RM = rm -f 52 53SYMBOL_IN := $(OUTPUT)libsymbol-in.o 54 55ifeq ($(LP64), 1) 56 libdir_relative = lib64 57else 58 libdir_relative = lib 59endif 60 61prefix ?= 62libdir = $(prefix)/$(libdir_relative) 63 64# Shell quotes 65libdir_SQ = $(subst ','\'',$(libdir)) 66 67all: 68 69export srctree OUTPUT CC LD CFLAGS V 70include $(srctree)/tools/build/Makefile.include 71include $(srctree)/tools/scripts/Makefile.include 72 73all: fixdep $(LIBFILE) 74 75$(SYMBOL_IN): FORCE 76 @$(MAKE) $(build)=libsymbol 77 78$(LIBFILE): $(SYMBOL_IN) 79 $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(SYMBOL_IN) 80 81define do_install_mkdir 82 if [ ! -d '$(DESTDIR_SQ)$1' ]; then \ 83 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \ 84 fi 85endef 86 87define do_install 88 if [ ! -d '$2' ]; then \ 89 $(INSTALL) -d -m 755 '$2'; \ 90 fi; \ 91 $(INSTALL) $1 $(if $3,-m $3,) '$2' 92endef 93 94install_lib: $(LIBFILE) 95 $(call QUIET_INSTALL, $(LIBFILE)) \ 96 $(call do_install_mkdir,$(libdir_SQ)); \ 97 cp -fpR $(LIBFILE) $(DESTDIR)$(libdir_SQ) 98 99HDRS := kallsyms.h 100INSTALL_HDRS_PFX := $(DESTDIR)$(prefix)/include/symbol 101INSTALL_HDRS := $(addprefix $(INSTALL_HDRS_PFX)/, $(HDRS)) 102 103$(INSTALL_HDRS): $(INSTALL_HDRS_PFX)/%.h: %.h 104 $(call QUIET_INSTALL, $@) \ 105 $(call do_install,$<,$(INSTALL_HDRS_PFX)/,644) 106 107install_headers: $(INSTALL_HDRS) 108 $(call QUIET_INSTALL, libsymbol_headers) 109 110install: install_lib install_headers 111 112clean: 113 $(call QUIET_CLEAN, libsymbol) $(RM) $(LIBFILE); \ 114 find $(or $(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM) 115 116FORCE: 117 118.PHONY: clean FORCE 119