github.com/blixtra/rkt@v0.8.1-0.20160204105720-ab0d1add1a43/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  # a clean file for removing solibs in both the ACI rootfs and the tmp
     9  # lib dir.
    10  $(call setup-clean-file,STAGE1_FSD_SOLIBS_CLEANMK,/$(STAGE1_FSD_FLAVOR)-solibs)
    11  
    12  # temporary directory
    13  $(call setup-tmp-dir,STAGE1_FSD_TMPDIR)
    14  
    15  # This is where libraries from host are copied too, so we can prepare
    16  # an exact filelist of what was copied.
    17  STAGE1_FSD_LIBSDIR := $(STAGE1_FSD_TMPDIR)/libs-$(STAGE1_FSD_FLAVOR)
    18  
    19  # main stamp that makes sure that libs were copied and dependencies
    20  # and cleanfiles were generated
    21  $(call setup-stamp-file,STAGE1_FSD_STAMP,$(STAGE1_FSD_FLAVOR))
    22  # this stamp makes sure that libs were copied
    23  $(call setup-stamp-file,STAGE1_FSD_COPY_STAMP,/$(STAGE1_FSD_FLAVOR)-fsd_copy)
    24  # this stamp makes sure that clean file was generated
    25  $(call setup-stamp-file,STAGE1_FSD_CLEAN_STAMP,/$(STAGE1_FSD_FLAVOR)-fsd_clean)
    26  # filelist of all copied libs
    27  $(call setup-filelist-file,STAGE1_FSD_FILELIST,/$(STAGE1_FSD_FLAVOR)-fsd)
    28  
    29  # the ACI rootfs for given flavor
    30  STAGE1_FSD_ACIROOTFSDIR := $(STAGE1_ACIROOTFSDIR_$(STAGE1_FSD_FLAVOR))
    31  # this is to get all stamps to make sure that the copying is done
    32  # after everything was put into the ACI rootfs and just before running
    33  # actool to create the ACI
    34  STAGE1_FSD_ALL_STAMPS := $(STAGE1_ALL_STAMPS_$(STAGE1_FSD_FLAVOR))
    35  
    36  # additions to LD_LIBRARY_PATH environment variable
    37  # TODO: we should somehow query the ACI which libdirs it uses -
    38  # on fedora these would be /usr/lib and /usr/lib64, but on debian it
    39  # is probably /usr/lib and /usr/lib/x86_64 or something
    40  STAGE1_FSD_LD_LIBRARY_PATH := $(STAGE1_FSD_ACIROOTFSDIR)/lib:$(STAGE1_FSD_ACIROOTFSDIR)/lib64:$(STAGE1_FSD_ACIROOTFSDIR)/usr/lib:$(STAGE1_FSD_ACIROOTFSDIR)/usr/lib64
    41  
    42  ifneq ($(LD_LIBRARY_PATH),)
    43  
    44  # the LD_LIBRARY_PATH environment variable is not empty, so append its
    45  # path to ours
    46  
    47  STAGE1_FSD_LD_LIBRARY_PATH := $(STAGE1_FSD_LD_LIBRARY_PATH):$(LD_LIBRARY_PATH)
    48  
    49  endif
    50  
    51  INSTALL_DIRS += $(STAGE1_FSD_LIBSDIR):-
    52  
    53  # this makes sure that everything is done
    54  $(call generate-stamp-rule,$(STAGE1_FSD_STAMP),$(STAGE1_FSD_COPY_STAMP) $(STAGE1_FSD_CLEAN_STAMP))
    55  
    56  # this detects which libs need to be copied and copies them into two
    57  # places - the libdirs in the ACI rootfs and a temporary directory at
    58  # the same time.
    59  $(call generate-stamp-rule,$(STAGE1_FSD_COPY_STAMP),$(STAGE1_FSD_ALL_STAMPS),$(STAGE1_FSD_LIBSDIR), \
    60  	$(call vb,vt,FIND SO DEPS,$(STAGE1_FSD_FLAVOR)) \
    61  	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); \
    62  	for f in $$$${all_libs}; do \
    63  		$(INSTALL) -D "$$$${f}" "$(STAGE1_FSD_ACIROOTFSDIR)$$$${f}"; \
    64  		$(INSTALL) -D "$$$${f}" "$(STAGE1_FSD_LIBSDIR)$$$${f}"; \
    65  	done)
    66  
    67  # This filelist can be generated only after the files were copied.
    68  $(STAGE1_FSD_FILELIST): $(STAGE1_FSD_COPY_STAMP)
    69  $(call generate-deep-filelist,$(STAGE1_FSD_FILELIST),$(STAGE1_FSD_LIBSDIR))
    70  
    71  # Generate clean.mk file cleaning libraries copied from the host to
    72  # both the temporary directory and the ACI rootfs directory.
    73  $(call generate-clean-mk,$(STAGE1_FSD_CLEAN_STAMP),$(STAGE1_FSD_SOLIBS_CLEANMK),$(STAGE1_FSD_FILELIST),$(STAGE1_FSD_LIBSDIR) $(STAGE1_FSD_ACIROOTFSDIR))
    74  
    75  # STAGE1_FSD_STAMP is deliberately not cleared - it will be used in
    76  # stage1.mk to create the stage1.aci dependency on the stamp.
    77  $(call undefine-namespaces,STAGE1_FSD _STAGE1_FSD,STAGE1_FSD_STAMP)