Back to home page

OSCL-LXR

 
 

    


0001 # SPDX-License-Identifier: GPL-2.0
0002 # ==========================================================================
0003 # Building binaries on the host system
0004 # Binaries are not used during the compilation of the kernel, and intended
0005 # to be build for target board, target board can be host of course. Added to
0006 # build binaries to run not on host system.
0007 #
0008 # Sample syntax
0009 # tprogs-y := xsk_example
0010 # Will compile xsk_example.c and create an executable named xsk_example
0011 #
0012 # tprogs-y    := xdpsock
0013 # xdpsock-objs := xdpsock_1.o xdpsock_2.o
0014 # Will compile xdpsock_1.c and xdpsock_2.c, and then link the executable
0015 # xdpsock, based on xdpsock_1.o and xdpsock_2.o
0016 #
0017 # Derived from scripts/Makefile.host
0018 #
0019 __tprogs := $(sort $(tprogs-y))
0020 
0021 # C code
0022 # Executables compiled from a single .c file
0023 tprog-csingle   := $(foreach m,$(__tprogs), \
0024                         $(if $($(m)-objs),,$(m)))
0025 
0026 # C executables linked based on several .o files
0027 tprog-cmulti    := $(foreach m,$(__tprogs),\
0028                         $(if $($(m)-objs),$(m)))
0029 
0030 # Object (.o) files compiled from .c files
0031 tprog-cobjs     := $(sort $(foreach m,$(__tprogs),$($(m)-objs)))
0032 
0033 tprog-csingle   := $(addprefix $(obj)/,$(tprog-csingle))
0034 tprog-cmulti    := $(addprefix $(obj)/,$(tprog-cmulti))
0035 tprog-cobjs     := $(addprefix $(obj)/,$(tprog-cobjs))
0036 
0037 #####
0038 # Handle options to gcc. Support building with separate output directory
0039 
0040 _tprogc_flags   = $(TPROGS_CFLAGS) \
0041                  $(TPROGCFLAGS_$(basetarget).o)
0042 
0043 # $(objtree)/$(obj) for including generated headers from checkin source files
0044 ifeq ($(KBUILD_EXTMOD),)
0045 ifdef building_out_of_srctree
0046 _tprogc_flags   += -I $(objtree)/$(obj)
0047 endif
0048 endif
0049 
0050 tprogc_flags    = -Wp,-MD,$(depfile) $(_tprogc_flags)
0051 
0052 # Create executable from a single .c file
0053 # tprog-csingle -> Executable
0054 quiet_cmd_tprog-csingle         = CC  $@
0055       cmd_tprog-csingle = $(CC) $(tprogc_flags) $(TPROGS_LDFLAGS) -o $@ $< \
0056                 $(TPROGS_LDLIBS) $(TPROGLDLIBS_$(@F))
0057 $(tprog-csingle): $(obj)/%: $(src)/%.c FORCE
0058         $(call if_changed_dep,tprog-csingle)
0059 
0060 # Link an executable based on list of .o files, all plain c
0061 # tprog-cmulti -> executable
0062 quiet_cmd_tprog-cmulti  = LD  $@
0063       cmd_tprog-cmulti  = $(CC) $(tprogc_flags) $(TPROGS_LDFLAGS) -o $@ \
0064                           $(addprefix $(obj)/,$($(@F)-objs)) \
0065                           $(TPROGS_LDLIBS) $(TPROGLDLIBS_$(@F))
0066 $(tprog-cmulti): $(tprog-cobjs) FORCE
0067         $(call if_changed,tprog-cmulti)
0068 $(call multi_depend, $(tprog-cmulti), , -objs)
0069 
0070 # Create .o file from a single .c file
0071 # tprog-cobjs -> .o
0072 quiet_cmd_tprog-cobjs   = CC  $@
0073       cmd_tprog-cobjs   = $(CC) $(tprogc_flags) -c -o $@ $<
0074 $(tprog-cobjs): $(obj)/%.o: $(src)/%.c FORCE
0075         $(call if_changed_dep,tprog-cobjs)