github.com/rkt/rkt@v1.30.1-0.20200224141603-171c416fac02/stage1/find-so-deps.mk (about)

     1  # This file copies the libraries from the host to the ACI rootfs
     2  # directory of a given flavor.
     3  #
     4  # Inputs:
     5  #
     6  # STAGE1_FSD_FLAVOR - a flavor which wants libraries from host
     7  
     8  SLD_FLAVOR := $(STAGE1_FSD_FLAVOR)
     9  $(call inc-one,stdlibdirs.mk)
    10  
    11  # temporary directory
    12  $(call setup-tmp-dir,STAGE1_FSD_TMPDIR)
    13  
    14  # This is where libraries from host are copied too, so we can prepare
    15  # an exact filelist of what was copied.
    16  STAGE1_FSD_LIBSDIR := $(STAGE1_FSD_TMPDIR)/libs-$(STAGE1_FSD_FLAVOR)
    17  
    18  # main stamp that makes sure that libs were copied and dependencies
    19  # and cleanfiles were generated
    20  $(call setup-stamp-file,STAGE1_FSD_STAMP,$(STAGE1_FSD_FLAVOR))
    21  # this stamp makes sure that libs were copied
    22  $(call setup-stamp-file,STAGE1_FSD_COPY_STAMP,/$(STAGE1_FSD_FLAVOR)-fsd_copy)
    23  
    24  # the ACI rootfs for given flavor
    25  STAGE1_FSD_ACIROOTFSDIR := $(STAGE1_ACIROOTFSDIR_$(STAGE1_FSD_FLAVOR))
    26  # this is to get all stamps to make sure that the copying is done
    27  # after everything was put into the ACI rootfs and just before running
    28  # actool to create the ACI
    29  STAGE1_FSD_ALL_STAMPS := $(STAGE1_ALL_STAMPS_$(STAGE1_FSD_FLAVOR))
    30  
    31  STAGE1_FSD_SPACE :=
    32  STAGE1_FSD_SPACE +=
    33  
    34  # additions to LD_LIBRARY_PATH environment variable
    35  STAGE1_FSD_LD_LIBRARY_PATH := $(subst $(STAGE1_FSD_SPACE),:,$(foreach l,$(SLD_LOCATIONS),$(STAGE1_FSD_ACIROOTFSDIR)/$l))
    36  
    37  ifneq ($(LD_LIBRARY_PATH),)
    38  
    39  # the LD_LIBRARY_PATH environment variable is not empty, so append its
    40  # path to ours
    41  
    42  STAGE1_FSD_LD_LIBRARY_PATH := $(STAGE1_FSD_LD_LIBRARY_PATH):$(LD_LIBRARY_PATH)
    43  
    44  endif
    45  
    46  INSTALL_DIRS += $(STAGE1_FSD_LIBSDIR):-
    47  
    48  # this makes sure that everything is done
    49  $(call generate-stamp-rule,$(STAGE1_FSD_STAMP),$(STAGE1_FSD_COPY_STAMP))
    50  
    51  # this detects which libs need to be copied and copies them into two
    52  # places - the libdirs in the ACI rootfs and a temporary directory at
    53  # the same time.
    54  $(call generate-stamp-rule,$(STAGE1_FSD_COPY_STAMP),$(STAGE1_FSD_ALL_STAMPS),$(STAGE1_FSD_LIBSDIR), \
    55  	$(call vb,vt,FIND SO DEPS,$(STAGE1_FSD_FLAVOR)) \
    56  	all_libs=$$$$(find "$(STAGE1_FSD_ACIROOTFSDIR)" -type f | xargs file | grep ELF | cut -f1 -d: | LD_LIBRARY_PATH="$(STAGE1_FSD_LD_LIBRARY_PATH)" xargs ldd | grep -v '^[^[:space:]]' | grep '/' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*(0x[0-9a-fA-F]*)//' -e 's/.*=>[[:space:]]*//' | grep -Fve "$(STAGE1_FSD_ACIROOTFSDIR)" | sort -u); \
    57  	for f in $$$${all_libs}; do \
    58  		$(INSTALL) -D "$$$${f}" "$(STAGE1_FSD_ACIROOTFSDIR)$$$${f}"; \
    59  		$(INSTALL) -D "$$$${f}" "$(STAGE1_FSD_LIBSDIR)$$$${f}"; \
    60  	done)
    61  
    62  # Generate clean file cleaning libraries copied from the host to both
    63  # the temporary directory and the ACI rootfs directory. Can happen
    64  # only after the files were copied.
    65  $(call generate-clean-mk-simple, \
    66  	$(STAGE1_FSD_STAMP), \
    67  	$(STAGE1_FSD_LIBSDIR), \
    68  	$(STAGE1_FSD_LIBSDIR) $(STAGE1_FSD_ACIROOTFSDIR), \
    69  	$(STAGE1_FSD_COPY_STAMP), \
    70  	libs-cleanup)
    71  
    72  # STAGE1_FSD_STAMP is deliberately not cleared - it will be used in
    73  # stage1.mk to create the stage1.aci dependency on the stamp.
    74  $(call undefine-namespaces,STAGE1_FSD _STAGE1_FSD,STAGE1_FSD_STAMP)