1 # SPDX-License-Identifier: GPL-2.0 1 # SPDX-License-Identifier: GPL-2.0 2 include ../../scripts/Makefile.include 2 include ../../scripts/Makefile.include 3 include ../../scripts/utilities.mak 3 include ../../scripts/utilities.mak # QUIET_CLEAN 4 4 5 ifeq ($(srctree),) 5 ifeq ($(srctree),) 6 srctree := $(patsubst %/,%,$(dir $(CURDIR))) 6 srctree := $(patsubst %/,%,$(dir $(CURDIR))) 7 srctree := $(patsubst %/,%,$(dir $(srctree))) 7 srctree := $(patsubst %/,%,$(dir $(srctree))) 8 srctree := $(patsubst %/,%,$(dir $(srctree))) 8 srctree := $(patsubst %/,%,$(dir $(srctree))) 9 #$(info Determined 'srctree' to be $(srctree)) 9 #$(info Determined 'srctree' to be $(srctree)) 10 endif 10 endif 11 11 12 CC ?= $(CROSS_COMPILE)gcc 12 CC ?= $(CROSS_COMPILE)gcc 13 AR ?= $(CROSS_COMPILE)ar 13 AR ?= $(CROSS_COMPILE)ar 14 LD ?= $(CROSS_COMPILE)ld 14 LD ?= $(CROSS_COMPILE)ld 15 15 16 MAKEFLAGS += --no-print-directory 16 MAKEFLAGS += --no-print-directory 17 17 18 INSTALL = install 18 INSTALL = install 19 19 20 20 21 # Use DESTDIR for installing into a different 21 # Use DESTDIR for installing into a different root directory. 22 # This is useful for building a package. The p 22 # This is useful for building a package. The program will be 23 # installed in this directory as if it was the 23 # installed in this directory as if it was the root directory. 24 # Then the build tool can move it later. 24 # Then the build tool can move it later. 25 DESTDIR ?= 25 DESTDIR ?= 26 DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))' 26 DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))' 27 27 28 LIBFILE = $(OUTPUT)libapi.a 28 LIBFILE = $(OUTPUT)libapi.a 29 29 30 CFLAGS := $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) 30 CFLAGS := $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) 31 CFLAGS += -ggdb3 -Wall -Wextra -std=gnu99 -U_F 31 CFLAGS += -ggdb3 -Wall -Wextra -std=gnu99 -U_FORTIFY_SOURCE -fPIC 32 32 33 ifeq ($(DEBUG),0) 33 ifeq ($(DEBUG),0) >> 34 ifeq ($(CC_NO_CLANG), 0) 34 CFLAGS += -O3 35 CFLAGS += -O3 >> 36 else >> 37 CFLAGS += -O6 >> 38 endif 35 endif 39 endif 36 40 37 ifeq ($(DEBUG),0) 41 ifeq ($(DEBUG),0) 38 CFLAGS += -D_FORTIFY_SOURCE 42 CFLAGS += -D_FORTIFY_SOURCE 39 endif 43 endif 40 44 41 # Treat warnings as errors unless directed not 45 # Treat warnings as errors unless directed not to 42 ifneq ($(WERROR),0) 46 ifneq ($(WERROR),0) 43 CFLAGS += -Werror 47 CFLAGS += -Werror 44 endif 48 endif 45 49 46 CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET 50 CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 47 CFLAGS += -I$(srctree)/tools/lib/api 51 CFLAGS += -I$(srctree)/tools/lib/api 48 CFLAGS += -I$(srctree)/tools/include 52 CFLAGS += -I$(srctree)/tools/include 49 53 50 RM = rm -f 54 RM = rm -f 51 55 52 API_IN := $(OUTPUT)libapi-in.o 56 API_IN := $(OUTPUT)libapi-in.o 53 57 54 ifeq ($(LP64), 1) 58 ifeq ($(LP64), 1) 55 libdir_relative = lib64 59 libdir_relative = lib64 56 else 60 else 57 libdir_relative = lib 61 libdir_relative = lib 58 endif 62 endif 59 63 60 prefix ?= 64 prefix ?= 61 libdir = $(prefix)/$(libdir_relative) 65 libdir = $(prefix)/$(libdir_relative) 62 66 63 # Shell quotes 67 # Shell quotes 64 libdir_SQ = $(subst ','\'',$(libdir)) 68 libdir_SQ = $(subst ','\'',$(libdir)) 65 69 66 all: 70 all: 67 71 68 export srctree OUTPUT CC LD CFLAGS V 72 export srctree OUTPUT CC LD CFLAGS V 69 include $(srctree)/tools/build/Makefile.includ 73 include $(srctree)/tools/build/Makefile.include 70 include $(srctree)/tools/scripts/Makefile.incl 74 include $(srctree)/tools/scripts/Makefile.include 71 75 72 all: fixdep $(LIBFILE) 76 all: fixdep $(LIBFILE) 73 77 74 $(API_IN): FORCE 78 $(API_IN): FORCE 75 @$(MAKE) $(build)=libapi 79 @$(MAKE) $(build)=libapi 76 80 77 $(LIBFILE): $(API_IN) 81 $(LIBFILE): $(API_IN) 78 $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $( 82 $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(API_IN) 79 83 80 define do_install_mkdir 84 define do_install_mkdir 81 if [ ! -d '$(DESTDIR_SQ)$1' ]; then 85 if [ ! -d '$(DESTDIR_SQ)$1' ]; then \ 82 $(INSTALL) -d -m 755 '$(DESTDI 86 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \ 83 fi 87 fi 84 endef 88 endef 85 89 86 define do_install 90 define do_install 87 if [ ! -d '$2' ]; then \ 91 if [ ! -d '$2' ]; then \ 88 $(INSTALL) -d -m 755 '$2'; \ 92 $(INSTALL) -d -m 755 '$2'; \ 89 fi; \ 93 fi; \ 90 $(INSTALL) $1 $(if $3,-m $3,) '$2' 94 $(INSTALL) $1 $(if $3,-m $3,) '$2' 91 endef 95 endef 92 96 93 install_lib: $(LIBFILE) 97 install_lib: $(LIBFILE) 94 $(call QUIET_INSTALL, $(LIBFILE)) \ 98 $(call QUIET_INSTALL, $(LIBFILE)) \ 95 $(call do_install_mkdir,$(libd 99 $(call do_install_mkdir,$(libdir_SQ)); \ 96 cp -fpR $(LIBFILE) $(DESTDIR)$ 100 cp -fpR $(LIBFILE) $(DESTDIR)$(libdir_SQ) 97 101 98 HDRS := cpu.h debug.h io.h 102 HDRS := cpu.h debug.h io.h 99 FD_HDRS := fd/array.h 103 FD_HDRS := fd/array.h 100 FS_HDRS := fs/fs.h fs/tracing_path.h 104 FS_HDRS := fs/fs.h fs/tracing_path.h 101 INSTALL_HDRS_PFX := $(DESTDIR)$(prefix)/includ 105 INSTALL_HDRS_PFX := $(DESTDIR)$(prefix)/include/api 102 INSTALL_HDRS := $(addprefix $(INSTALL_HDRS_PFX 106 INSTALL_HDRS := $(addprefix $(INSTALL_HDRS_PFX)/, $(HDRS)) 103 INSTALL_FD_HDRS := $(addprefix $(INSTALL_HDRS_ 107 INSTALL_FD_HDRS := $(addprefix $(INSTALL_HDRS_PFX)/, $(FD_HDRS)) 104 INSTALL_FS_HDRS := $(addprefix $(INSTALL_HDRS_ 108 INSTALL_FS_HDRS := $(addprefix $(INSTALL_HDRS_PFX)/, $(FS_HDRS)) 105 109 106 $(INSTALL_HDRS): $(INSTALL_HDRS_PFX)/%.h: %.h 110 $(INSTALL_HDRS): $(INSTALL_HDRS_PFX)/%.h: %.h 107 $(call QUIET_INSTALL, $@) \ 111 $(call QUIET_INSTALL, $@) \ 108 $(call do_install,$<,$(INSTALL 112 $(call do_install,$<,$(INSTALL_HDRS_PFX)/,644) 109 113 110 $(INSTALL_FD_HDRS): $(INSTALL_HDRS_PFX)/fd/%.h 114 $(INSTALL_FD_HDRS): $(INSTALL_HDRS_PFX)/fd/%.h: fd/%.h 111 $(call QUIET_INSTALL, $@) \ 115 $(call QUIET_INSTALL, $@) \ 112 $(call do_install,$<,$(INSTALL 116 $(call do_install,$<,$(INSTALL_HDRS_PFX)/fd/,644) 113 117 114 $(INSTALL_FS_HDRS): $(INSTALL_HDRS_PFX)/fs/%.h 118 $(INSTALL_FS_HDRS): $(INSTALL_HDRS_PFX)/fs/%.h: fs/%.h 115 $(call QUIET_INSTALL, $@) \ 119 $(call QUIET_INSTALL, $@) \ 116 $(call do_install,$<,$(INSTALL 120 $(call do_install,$<,$(INSTALL_HDRS_PFX)/fs/,644) 117 121 118 install_headers: $(INSTALL_HDRS) $(INSTALL_FD_ 122 install_headers: $(INSTALL_HDRS) $(INSTALL_FD_HDRS) $(INSTALL_FS_HDRS) 119 $(call QUIET_INSTALL, libapi_headers) 123 $(call QUIET_INSTALL, libapi_headers) 120 124 121 install: install_lib install_headers 125 install: install_lib install_headers 122 126 123 clean: 127 clean: 124 $(call QUIET_CLEAN, libapi) $(RM) $(LI 128 $(call QUIET_CLEAN, libapi) $(RM) $(LIBFILE); \ 125 find $(or $(OUTPUT),.) -name \*.o -or 129 find $(or $(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM) 126 130 127 FORCE: 131 FORCE: 128 132 129 .PHONY: clean FORCE 133 .PHONY: clean FORCE
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.