xref: /linux/tools/lib/subcmd/Makefile (revision 891e8abed532423d3b918b0c445dc8919bc445b5)
1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
24b6ab94eSJosh Poimboeufinclude ../../scripts/Makefile.include
3ca70c24fSArnaldo Carvalho de Meloinclude ../../scripts/utilities.mak		# QUIET_CLEAN
44b6ab94eSJosh Poimboeuf
54b6ab94eSJosh Poimboeufifeq ($(srctree),)
6e19b7ceeSUwe Kleine-Königsrctree := $(patsubst %/,%,$(dir $(CURDIR)))
74b6ab94eSJosh Poimboeufsrctree := $(patsubst %/,%,$(dir $(srctree)))
84b6ab94eSJosh Poimboeufsrctree := $(patsubst %/,%,$(dir $(srctree)))
94b6ab94eSJosh Poimboeuf#$(info Determined 'srctree' to be $(srctree))
104b6ab94eSJosh Poimboeufendif
114b6ab94eSJosh Poimboeuf
12c1d45c3aSJosh PoimboeufCC ?= $(CROSS_COMPILE)gcc
13c1d45c3aSJosh PoimboeufLD ?= $(CROSS_COMPILE)ld
14c1d45c3aSJosh PoimboeufAR ?= $(CROSS_COMPILE)ar
15c1d45c3aSJosh Poimboeuf
164b6ab94eSJosh PoimboeufRM = rm -f
174b6ab94eSJosh Poimboeuf
184b6ab94eSJosh PoimboeufMAKEFLAGS += --no-print-directory
194b6ab94eSJosh Poimboeuf
20630ae80eSIan RogersINSTALL = install
21630ae80eSIan Rogers
22630ae80eSIan Rogers# Use DESTDIR for installing into a different root directory.
23630ae80eSIan Rogers# This is useful for building a package. The program will be
24630ae80eSIan Rogers# installed in this directory as if it was the root directory.
25630ae80eSIan Rogers# Then the build tool can move it later.
26630ae80eSIan RogersDESTDIR ?=
27630ae80eSIan RogersDESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
28630ae80eSIan Rogers
294b6ab94eSJosh PoimboeufLIBFILE = $(OUTPUT)libsubcmd.a
304b6ab94eSJosh Poimboeuf
31d894967fSJames ClarkCFLAGS := -ggdb3 -Wall -Wextra -std=gnu99 -fPIC
324b0b2b09SIan Rogers
334b0b2b09SIan Rogersifeq ($(DEBUG),0)
344b0b2b09SIan Rogers  ifeq ($(feature-fortify-source), 1)
354b0b2b09SIan Rogers    CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
364b0b2b09SIan Rogers  endif
374b0b2b09SIan Rogersendif
3849b3cd30SArnaldo Carvalho de Melo
3922bd8f1bSJames Clarkifeq ($(DEBUG),1)
4022bd8f1bSJames Clark  CFLAGS += -O0
4149b3cd30SArnaldo Carvalho de Meloelse
42*eb9b9a6fSSam James  CFLAGS += -O3
4349b3cd30SArnaldo Carvalho de Meloendif
44fd01d06aSChris Phlipot
45fd01d06aSChris Phlipot# Treat warnings as errors unless directed not to
46fd01d06aSChris Phlipotifneq ($(WERROR),0)
47fd01d06aSChris Phlipot  CFLAGS += -Werror
48fd01d06aSChris Phlipotendif
49fd01d06aSChris Phlipot
504b6ab94eSJosh PoimboeufCFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
514b6ab94eSJosh Poimboeuf
524b6ab94eSJosh PoimboeufCFLAGS += -I$(srctree)/tools/include/
534b6ab94eSJosh Poimboeuf
54d894967fSJames ClarkCFLAGS += $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
55d894967fSJames Clark
564b6ab94eSJosh PoimboeufSUBCMD_IN := $(OUTPUT)libsubcmd-in.o
574b6ab94eSJosh Poimboeuf
58630ae80eSIan Rogersifeq ($(LP64), 1)
59630ae80eSIan Rogers  libdir_relative = lib64
60630ae80eSIan Rogerselse
61630ae80eSIan Rogers  libdir_relative = lib
62630ae80eSIan Rogersendif
63630ae80eSIan Rogers
64630ae80eSIan Rogersprefix ?=
65630ae80eSIan Rogerslibdir = $(prefix)/$(libdir_relative)
66630ae80eSIan Rogers
67630ae80eSIan Rogers# Shell quotes
68630ae80eSIan Rogerslibdir_SQ = $(subst ','\'',$(libdir))
69630ae80eSIan Rogers
704b6ab94eSJosh Poimboeufall:
714b6ab94eSJosh Poimboeuf
724b6ab94eSJosh Poimboeufexport srctree OUTPUT CC LD CFLAGS V
734b6ab94eSJosh Poimboeufinclude $(srctree)/tools/build/Makefile.include
744b6ab94eSJosh Poimboeuf
754b6ab94eSJosh Poimboeufall: fixdep $(LIBFILE)
764b6ab94eSJosh Poimboeuf
7796f30c8fSBrian Norris$(SUBCMD_IN): fixdep FORCE
784b6ab94eSJosh Poimboeuf	@$(MAKE) $(build)=libsubcmd
794b6ab94eSJosh Poimboeuf
804b6ab94eSJosh Poimboeuf$(LIBFILE): $(SUBCMD_IN)
814b6ab94eSJosh Poimboeuf	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(SUBCMD_IN)
824b6ab94eSJosh Poimboeuf
83630ae80eSIan Rogersdefine do_install_mkdir
84630ae80eSIan Rogers	if [ ! -d '$(DESTDIR_SQ)$1' ]; then             \
85630ae80eSIan Rogers		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
86630ae80eSIan Rogers	fi
87630ae80eSIan Rogersendef
88630ae80eSIan Rogers
89630ae80eSIan Rogersdefine do_install
905d890591SIan Rogers	if [ ! -d '$2' ]; then             \
915d890591SIan Rogers		$(INSTALL) -d -m 755 '$2'; \
92630ae80eSIan Rogers	fi;                                             \
935d890591SIan Rogers	$(INSTALL) $1 $(if $3,-m $3,) '$2'
94630ae80eSIan Rogersendef
95630ae80eSIan Rogers
96630ae80eSIan Rogersinstall_lib: $(LIBFILE)
97630ae80eSIan Rogers	$(call QUIET_INSTALL, $(LIBFILE)) \
98630ae80eSIan Rogers		$(call do_install_mkdir,$(libdir_SQ)); \
99630ae80eSIan Rogers		cp -fpR $(LIBFILE) $(DESTDIR)$(libdir_SQ)
100630ae80eSIan Rogers
1015d890591SIan RogersHDRS := exec-cmd.h help.h pager.h parse-options.h run-command.h
1025d890591SIan RogersINSTALL_HDRS_PFX := $(DESTDIR)$(prefix)/include/subcmd
1035d890591SIan RogersINSTALL_HDRS := $(addprefix $(INSTALL_HDRS_PFX)/, $(HDRS))
1045d890591SIan Rogers
1055d890591SIan Rogers$(INSTALL_HDRS): $(INSTALL_HDRS_PFX)/%.h: %.h
1065d890591SIan Rogers	$(call QUIET_INSTALL, $@) \
1075d890591SIan Rogers		$(call do_install,$<,$(INSTALL_HDRS_PFX)/,644)
1085d890591SIan Rogers
1095d890591SIan Rogersinstall_headers: $(INSTALL_HDRS)
1105d890591SIan Rogers	$(call QUIET_INSTALL, libsubcmd_headers)
111630ae80eSIan Rogers
112630ae80eSIan Rogersinstall: install_lib install_headers
113630ae80eSIan Rogers
1144b6ab94eSJosh Poimboeufclean:
1154b6ab94eSJosh Poimboeuf	$(call QUIET_CLEAN, libsubcmd) $(RM) $(LIBFILE); \
1165c816641SMasahiro Yamada	find $(or $(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM)
1174b6ab94eSJosh Poimboeuf
1184b6ab94eSJosh PoimboeufFORCE:
1194b6ab94eSJosh Poimboeuf
1204b6ab94eSJosh Poimboeuf.PHONY: clean FORCE
121