b24413180f560 (Greg Kroah-Hartman 2017-11-01 15:07:57 +0100 1) # SPDX-License-Identifier: GPL-2.0
cf8dfd15e5fb2 (Masahiro Yamada 2019-07-21 01:27:40 +0900 2)
cf8dfd15e5fb2 (Masahiro Yamada 2019-07-21 01:27:40 +0900 3) # LEX
cf8dfd15e5fb2 (Masahiro Yamada 2019-07-21 01:27:40 +0900 4) # ---------------------------------------------------------------------------
cf8dfd15e5fb2 (Masahiro Yamada 2019-07-21 01:27:40 +0900 5) quiet_cmd_flex = LEX $@
cf8dfd15e5fb2 (Masahiro Yamada 2019-07-21 01:27:40 +0900 6) cmd_flex = $(LEX) -o$@ -L $<
cf8dfd15e5fb2 (Masahiro Yamada 2019-07-21 01:27:40 +0900 7)
cf8dfd15e5fb2 (Masahiro Yamada 2019-07-21 01:27:40 +0900 8) $(obj)/%.lex.c: $(src)/%.l FORCE
cf8dfd15e5fb2 (Masahiro Yamada 2019-07-21 01:27:40 +0900 9) $(call if_changed,flex)
cf8dfd15e5fb2 (Masahiro Yamada 2019-07-21 01:27:40 +0900 10)
cf8dfd15e5fb2 (Masahiro Yamada 2019-07-21 01:27:40 +0900 11) # YACC
cf8dfd15e5fb2 (Masahiro Yamada 2019-07-21 01:27:40 +0900 12) # ---------------------------------------------------------------------------
cf8dfd15e5fb2 (Masahiro Yamada 2019-07-21 01:27:40 +0900 13) quiet_cmd_bison = YACC $(basename $@).[ch]
cf8dfd15e5fb2 (Masahiro Yamada 2019-07-21 01:27:40 +0900 14) cmd_bison = $(YACC) -o $(basename $@).c --defines=$(basename $@).h -t -l $<
cf8dfd15e5fb2 (Masahiro Yamada 2019-07-21 01:27:40 +0900 15)
cf8dfd15e5fb2 (Masahiro Yamada 2019-07-21 01:27:40 +0900 16) $(obj)/%.tab.c $(obj)/%.tab.h: $(src)/%.y FORCE
cf8dfd15e5fb2 (Masahiro Yamada 2019-07-21 01:27:40 +0900 17) $(call if_changed,bison)
cf8dfd15e5fb2 (Masahiro Yamada 2019-07-21 01:27:40 +0900 18)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 19) # ==========================================================================
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 20) # Building binaries on the host system
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 21) # Binaries are used during the compilation of the kernel, for example
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 22) # to preprocess a data file.
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 23) #
3156fd0529b52 (Robert P. J. Day 2008-02-18 04:48:20 -0500 24) # Both C and C++ are supported, but preferred language is C for such utilities.
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 25) #
cd238effefa28 (Mauro Carvalho Chehab 2019-06-12 14:52:48 -0300 26) # Sample syntax (see Documentation/kbuild/makefiles.rst for reference)
5f2fb52fac15a (Masahiro Yamada 2020-02-02 01:49:24 +0900 27) # hostprogs := bin2hex
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 28) # Will compile bin2hex.c and create an executable named bin2hex
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 29) #
5f2fb52fac15a (Masahiro Yamada 2020-02-02 01:49:24 +0900 30) # hostprogs := lxdialog
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 31) # lxdialog-objs := checklist.o lxdialog.o
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 32) # Will compile lxdialog.c and checklist.c, and then link the executable
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 33) # lxdialog, based on checklist.o and lxdialog.o
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 34) #
5f2fb52fac15a (Masahiro Yamada 2020-02-02 01:49:24 +0900 35) # hostprogs := qconf
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 36) # qconf-cxxobjs := qconf.o
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 37) # qconf-objs := menu.o
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 38) # Will compile qconf as a C++ program, and menu as a C program.
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 39) # They are linked as C++ code to the executable qconf
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 40)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 41) # C code
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 42) # Executables compiled from a single .c file
85569d19d0f57 (Masahiro Yamada 2020-07-29 12:15:37 +0900 43) host-csingle := $(foreach m,$(hostprogs), \
edb950c17de09 (Masahiro Yamada 2014-07-16 16:12:20 +0900 44) $(if $($(m)-objs)$($(m)-cxxobjs),,$(m)))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 45)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 46) # C executables linked based on several .o files
85569d19d0f57 (Masahiro Yamada 2020-07-29 12:15:37 +0900 47) host-cmulti := $(foreach m,$(hostprogs),\
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 48) $(if $($(m)-cxxobjs),,$(if $($(m)-objs),$(m))))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 49)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 50) # Object (.o) files compiled from .c files
85569d19d0f57 (Masahiro Yamada 2020-07-29 12:15:37 +0900 51) host-cobjs := $(sort $(foreach m,$(hostprogs),$($(m)-objs)))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 52)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 53) # C++ code
d8d9efe22709b (Masahiro Yamada 2014-07-16 16:12:19 +0900 54) # C++ executables compiled from at least one .cc file
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 55) # and zero or more .c files
85569d19d0f57 (Masahiro Yamada 2020-07-29 12:15:37 +0900 56) host-cxxmulti := $(foreach m,$(hostprogs),$(if $($(m)-cxxobjs),$(m)))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 57)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 58) # C++ Object (.o) files compiled from .cc files
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 59) host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 60)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 61) host-csingle := $(addprefix $(obj)/,$(host-csingle))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 62) host-cmulti := $(addprefix $(obj)/,$(host-cmulti))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 63) host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 64) host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 65) host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 66)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 67) #####
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 68) # Handle options to gcc. Support building with separate output directory
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 69)
96f14fe738b69 (Laura Abbott 2018-07-09 17:45:58 -0700 70) _hostc_flags = $(KBUILD_HOSTCFLAGS) $(HOST_EXTRACFLAGS) \
54b8ae66ae1a3 (Masahiro Yamada 2019-08-30 13:34:01 +0900 71) $(HOSTCFLAGS_$(target-stem).o)
10844aebf4485 (Laura Abbott 2018-07-09 17:45:59 -0700 72) _hostcxx_flags = $(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \
54b8ae66ae1a3 (Masahiro Yamada 2019-08-30 13:34:01 +0900 73) $(HOSTCXXFLAGS_$(target-stem).o)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 74)
cdd750bfb1f76 (Masahiro Yamada 2019-05-13 15:22:17 +0900 75) # $(objtree)/$(obj) for including generated headers from checkin source files
58156ba4468f1 (Masahiro Yamada 2019-01-16 11:56:40 +0900 76) ifeq ($(KBUILD_EXTMOD),)
051f278e9d81b (Masahiro Yamada 2019-07-06 12:07:12 +0900 77) ifdef building_out_of_srctree
cdd750bfb1f76 (Masahiro Yamada 2019-05-13 15:22:17 +0900 78) _hostc_flags += -I $(objtree)/$(obj)
cdd750bfb1f76 (Masahiro Yamada 2019-05-13 15:22:17 +0900 79) _hostcxx_flags += -I $(objtree)/$(obj)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 80) endif
58156ba4468f1 (Masahiro Yamada 2019-01-16 11:56:40 +0900 81) endif
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 82)
30a7729771731 (Masahiro Yamada 2020-04-23 23:23:53 +0900 83) hostc_flags = -Wp,-MMD,$(depfile) $(_hostc_flags)
30a7729771731 (Masahiro Yamada 2020-04-23 23:23:53 +0900 84) hostcxx_flags = -Wp,-MMD,$(depfile) $(_hostcxx_flags)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 85)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 86) #####
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 87) # Compile programs on the host
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 88)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 89) # Create executable from a single .c file
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 90) # host-csingle -> Executable
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 91) quiet_cmd_host-csingle = HOSTCC $@
b90a368000abe (Laura Abbott 2018-07-09 17:46:00 -0700 92) cmd_host-csingle = $(HOSTCC) $(hostc_flags) $(KBUILD_HOSTLDFLAGS) -o $@ $< \
54b8ae66ae1a3 (Masahiro Yamada 2019-08-30 13:34:01 +0900 93) $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(target-stem))
767e581d759fe (Sam Ravnborg 2007-05-06 09:23:45 +0200 94) $(host-csingle): $(obj)/%: $(src)/%.c FORCE
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 95) $(call if_changed_dep,host-csingle)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 96)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 97) # Link an executable based on list of .o files, all plain c
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 98) # host-cmulti -> executable
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 99) quiet_cmd_host-cmulti = HOSTLD $@
b90a368000abe (Laura Abbott 2018-07-09 17:46:00 -0700 100) cmd_host-cmulti = $(HOSTCC) $(KBUILD_HOSTLDFLAGS) -o $@ \
54b8ae66ae1a3 (Masahiro Yamada 2019-08-30 13:34:01 +0900 101) $(addprefix $(obj)/, $($(target-stem)-objs)) \
54b8ae66ae1a3 (Masahiro Yamada 2019-08-30 13:34:01 +0900 102) $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(target-stem))
97e3226e6e984 (Masahiro Yamada 2014-08-19 16:34:21 +0900 103) $(host-cmulti): FORCE
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 104) $(call if_changed,host-cmulti)
97e3226e6e984 (Masahiro Yamada 2014-08-19 16:34:21 +0900 105) $(call multi_depend, $(host-cmulti), , -objs)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 106)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 107) # Create .o file from a single .c file
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 108) # host-cobjs -> .o
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 109) quiet_cmd_host-cobjs = HOSTCC $@
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 110) cmd_host-cobjs = $(HOSTCC) $(hostc_flags) -c -o $@ $<
767e581d759fe (Sam Ravnborg 2007-05-06 09:23:45 +0200 111) $(host-cobjs): $(obj)/%.o: $(src)/%.c FORCE
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 112) $(call if_changed_dep,host-cobjs)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 113)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 114) # Link an executable based on list of .o files, a mixture of .c and .cc
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 115) # host-cxxmulti -> executable
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 116) quiet_cmd_host-cxxmulti = HOSTLD $@
b90a368000abe (Laura Abbott 2018-07-09 17:46:00 -0700 117) cmd_host-cxxmulti = $(HOSTCXX) $(KBUILD_HOSTLDFLAGS) -o $@ \
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 118) $(foreach o,objs cxxobjs,\
54b8ae66ae1a3 (Masahiro Yamada 2019-08-30 13:34:01 +0900 119) $(addprefix $(obj)/, $($(target-stem)-$(o)))) \
54b8ae66ae1a3 (Masahiro Yamada 2019-08-30 13:34:01 +0900 120) $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(target-stem))
97e3226e6e984 (Masahiro Yamada 2014-08-19 16:34:21 +0900 121) $(host-cxxmulti): FORCE
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 122) $(call if_changed,host-cxxmulti)
97e3226e6e984 (Masahiro Yamada 2014-08-19 16:34:21 +0900 123) $(call multi_depend, $(host-cxxmulti), , -objs -cxxobjs)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 124)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 125) # Create .o file from a single .cc (C++) file
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 126) quiet_cmd_host-cxxobjs = HOSTCXX $@
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 127) cmd_host-cxxobjs = $(HOSTCXX) $(hostcxx_flags) -c -o $@ $<
767e581d759fe (Sam Ravnborg 2007-05-06 09:23:45 +0200 128) $(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 129) $(call if_changed_dep,host-cxxobjs)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 130)
42640b134bf44 (Masahiro Yamada 2020-07-29 12:15:36 +0900 131) targets += $(host-csingle) $(host-cmulti) $(host-cobjs) \
42640b134bf44 (Masahiro Yamada 2020-07-29 12:15:36 +0900 132) $(host-cxxmulti) $(host-cxxobjs)