1 # SPDX-License-Identifier: GPL-2.0 1 # SPDX-License-Identifier: GPL-2.0 2 # ============================================ 2 # ========================================================================== 3 # Building binaries on the host system 3 # Building binaries on the host system 4 # Binaries are not used during the compilation 4 # Binaries are not used during the compilation of the kernel, and intended 5 # to be build for target board, target board c 5 # to be build for target board, target board can be host of course. Added to 6 # build binaries to run not on host system. 6 # build binaries to run not on host system. 7 # 7 # 8 # Sample syntax 8 # Sample syntax 9 # tprogs-y := xsk_example 9 # tprogs-y := xsk_example 10 # Will compile xsk_example.c and create an exe 10 # Will compile xsk_example.c and create an executable named xsk_example 11 # 11 # 12 # tprogs-y := xdpsock 12 # tprogs-y := xdpsock 13 # xdpsock-objs := xdpsock_1.o xdpsock_2.o 13 # xdpsock-objs := xdpsock_1.o xdpsock_2.o 14 # Will compile xdpsock_1.c and xdpsock_2.c, an 14 # Will compile xdpsock_1.c and xdpsock_2.c, and then link the executable 15 # xdpsock, based on xdpsock_1.o and xdpsock_2. 15 # xdpsock, based on xdpsock_1.o and xdpsock_2.o 16 # 16 # 17 # Derived from scripts/Makefile.host 17 # Derived from scripts/Makefile.host 18 # 18 # 19 __tprogs := $(sort $(tprogs-y)) 19 __tprogs := $(sort $(tprogs-y)) 20 20 21 # C code 21 # C code 22 # Executables compiled from a single .c file 22 # Executables compiled from a single .c file 23 tprog-csingle := $(foreach m,$(__tprogs), \ 23 tprog-csingle := $(foreach m,$(__tprogs), \ 24 $(if $($(m)-objs),,$(m 24 $(if $($(m)-objs),,$(m))) 25 25 26 # C executables linked based on several .o fil 26 # C executables linked based on several .o files 27 tprog-cmulti := $(foreach m,$(__tprogs),\ 27 tprog-cmulti := $(foreach m,$(__tprogs),\ 28 $(if $($(m)-objs),$(m) 28 $(if $($(m)-objs),$(m))) 29 29 30 # Object (.o) files compiled from .c files 30 # Object (.o) files compiled from .c files 31 tprog-cobjs := $(sort $(foreach m,$(__tpro 31 tprog-cobjs := $(sort $(foreach m,$(__tprogs),$($(m)-objs))) 32 32 33 tprog-csingle := $(addprefix $(obj)/,$(tprog 33 tprog-csingle := $(addprefix $(obj)/,$(tprog-csingle)) 34 tprog-cmulti := $(addprefix $(obj)/,$(tprog 34 tprog-cmulti := $(addprefix $(obj)/,$(tprog-cmulti)) 35 tprog-cobjs := $(addprefix $(obj)/,$(tprog 35 tprog-cobjs := $(addprefix $(obj)/,$(tprog-cobjs)) 36 36 37 ##### 37 ##### 38 # Handle options to gcc. Support building with 38 # Handle options to gcc. Support building with separate output directory 39 39 40 _tprogc_flags = $(TPROGS_CFLAGS) \ 40 _tprogc_flags = $(TPROGS_CFLAGS) \ 41 $(TPROGCFLAGS_$(basetarget).o 41 $(TPROGCFLAGS_$(basetarget).o) 42 42 43 # $(objtree)/$(obj) for including generated he 43 # $(objtree)/$(obj) for including generated headers from checkin source files 44 ifeq ($(KBUILD_EXTMOD),) 44 ifeq ($(KBUILD_EXTMOD),) 45 ifdef building_out_of_srctree 45 ifdef building_out_of_srctree 46 _tprogc_flags += -I $(objtree)/$(obj) 46 _tprogc_flags += -I $(objtree)/$(obj) 47 endif 47 endif 48 endif 48 endif 49 49 50 tprogc_flags = -Wp,-MD,$(depfile) $(_tprogc 50 tprogc_flags = -Wp,-MD,$(depfile) $(_tprogc_flags) 51 51 52 # Create executable from a single .c file 52 # Create executable from a single .c file 53 # tprog-csingle -> Executable 53 # tprog-csingle -> Executable 54 quiet_cmd_tprog-csingle = CC $@ 54 quiet_cmd_tprog-csingle = CC $@ 55 cmd_tprog-csingle = $(CC) $(tprogc_flags 55 cmd_tprog-csingle = $(CC) $(tprogc_flags) $(TPROGS_LDFLAGS) -o $@ $< \ 56 $(TPROGS_LDLIBS) $(TPROGLDLIBS 56 $(TPROGS_LDLIBS) $(TPROGLDLIBS_$(@F)) 57 $(tprog-csingle): $(obj)/%: $(src)/%.c FORCE 57 $(tprog-csingle): $(obj)/%: $(src)/%.c FORCE 58 $(call if_changed_dep,tprog-csingle) 58 $(call if_changed_dep,tprog-csingle) 59 59 60 # Link an executable based on list of .o files 60 # Link an executable based on list of .o files, all plain c 61 # tprog-cmulti -> executable 61 # tprog-cmulti -> executable 62 quiet_cmd_tprog-cmulti = LD $@ 62 quiet_cmd_tprog-cmulti = LD $@ 63 cmd_tprog-cmulti = $(CC) $(tprogc_flags 63 cmd_tprog-cmulti = $(CC) $(tprogc_flags) $(TPROGS_LDFLAGS) -o $@ \ 64 $(addprefix $(obj)/, 64 $(addprefix $(obj)/,$($(@F)-objs)) \ 65 $(TPROGS_LDLIBS) $(T 65 $(TPROGS_LDLIBS) $(TPROGLDLIBS_$(@F)) 66 $(tprog-cmulti): $(tprog-cobjs) FORCE 66 $(tprog-cmulti): $(tprog-cobjs) FORCE 67 $(call if_changed,tprog-cmulti) 67 $(call if_changed,tprog-cmulti) 68 $(call multi_depend, $(tprog-cmulti), , -objs) 68 $(call multi_depend, $(tprog-cmulti), , -objs) 69 69 70 # Create .o file from a single .c file 70 # Create .o file from a single .c file 71 # tprog-cobjs -> .o 71 # tprog-cobjs -> .o 72 quiet_cmd_tprog-cobjs = CC $@ 72 quiet_cmd_tprog-cobjs = CC $@ 73 cmd_tprog-cobjs = $(CC) $(tprogc_flags 73 cmd_tprog-cobjs = $(CC) $(tprogc_flags) -c -o $@ $< 74 $(tprog-cobjs): $(obj)/%.o: $(src)/%.c FORCE 74 $(tprog-cobjs): $(obj)/%.o: $(src)/%.c FORCE 75 $(call if_changed_dep,tprog-cobjs) 75 $(call if_changed_dep,tprog-cobjs)
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.