1 # SPDX-License-Identifier: GPL-2.0
2 include ../../scripts/Makefile.include
3 include ../../scripts/utilities.mak # QUIET_CLEAN
6 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
7 srctree := $(patsubst %/,%,$(dir $(srctree)))
8 srctree := $(patsubst %/,%,$(dir $(srctree)))
9 #$(info Determined 'srctree' to be $(srctree))
12 CC ?= $(CROSS_COMPILE)gcc
13 LD ?= $(CROSS_COMPILE)ld
14 AR ?= $(CROSS_COMPILE)ar
18 MAKEFLAGS += --no-print-directory
22 # Use DESTDIR for installing into a different root directory.
23 # This is useful for building a package. The program will be
24 # installed in this directory as if it was the root directory.
25 # Then the build tool can move it later.
27 DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
29 LIBFILE = $(OUTPUT)libsubcmd.a
31 CFLAGS := -ggdb3 -Wall -Wextra -std=gnu99 -fPIC
34 ifeq ($(feature-fortify-source), 1)
35 CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
41 else ifeq ($(CC_NO_CLANG), 0)
47 # Treat warnings as errors unless directed not to
52 CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
54 CFLAGS += -I$(srctree)/tools/include/
56 CFLAGS += $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
58 SUBCMD_IN := $(OUTPUT)libsubcmd-in.o
61 libdir_relative = lib64
67 libdir = $(prefix)/$(libdir_relative)
70 libdir_SQ = $(subst ','\'',$(libdir))
74 export srctree OUTPUT CC LD CFLAGS V
75 include $(srctree)/tools/build/Makefile.include
77 all: fixdep $(LIBFILE)
80 @$(MAKE) $(build)=libsubcmd
82 $(LIBFILE): $(SUBCMD_IN)
83 $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(SUBCMD_IN)
85 define do_install_mkdir
86 if [ ! -d '$(DESTDIR_SQ)$1' ]; then \
87 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
92 if [ ! -d '$2' ]; then \
93 $(INSTALL) -d -m 755 '$2'; \
95 $(INSTALL) $1 $(if $3,-m $3,) '$2'
98 install_lib: $(LIBFILE)
99 $(call QUIET_INSTALL, $(LIBFILE)) \
100 $(call do_install_mkdir,$(libdir_SQ)); \
101 cp -fpR $(LIBFILE) $(DESTDIR)$(libdir_SQ)
103 HDRS := exec-cmd.h help.h pager.h parse-options.h run-command.h
104 INSTALL_HDRS_PFX := $(DESTDIR)$(prefix)/include/subcmd
105 INSTALL_HDRS := $(addprefix $(INSTALL_HDRS_PFX)/, $(HDRS))
107 $(INSTALL_HDRS): $(INSTALL_HDRS_PFX)/%.h: %.h
108 $(call QUIET_INSTALL, $@) \
109 $(call do_install,$<,$(INSTALL_HDRS_PFX)/,644)
111 install_headers: $(INSTALL_HDRS)
112 $(call QUIET_INSTALL, libsubcmd_headers)
114 install: install_lib install_headers
117 $(call QUIET_CLEAN, libsubcmd) $(RM) $(LIBFILE); \
118 find $(or $(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM)