github.com/stackdocker/rkt@v0.10.1-0.20151109095037-1aa827478248/stage1/stage1.mk (about)

     1  # Prepare some variables, this might look strange so here goes: let's
     2  # assume we are going to build two flavors - coreos and kvm. The
     3  # following code is going to initialize some variables to some initial
     4  # values. The name of the variable depends on the flavor:
     5  # STAGE1_COPY_SO_DEPS_coreos, STAGE1_USR_STAMPS_coreos,
     6  # STAGE1_APP_STAMPS_coreos and so on for the coreos flavor. For the
     7  # kvm flavor the names would be STAGE1_COPY_SO_DEPS_kvm,
     8  # STAGE1_USR_STAMPS_kvm, STAGE1_APP_STAMPS_kvm and so on.
     9  #
    10  # STAGE1_COPY_SO_DEPS_$(flavor) tells whether a given flavor wants to
    11  # get missing libraries from build host before building an ACI.
    12  #
    13  # STAGE1_USR_STAMPS_$(flavor) is a list of stamps that say whether the
    14  # initial /usr contents of ACI are prepared.
    15  #
    16  # STAGE1_SECONDARY_STAMPS_$(flavor) is a list of stamps that say
    17  # whether the additional stuff was copied to the ACI rootfs (init,
    18  # enter, units, net config and so on). Usually the dependencies of
    19  # these stamps depend in turn on the stamps from
    20  # STAGE1_USR_STAMPS_$(flavor) - which means that the additional stuff
    21  # is copied to the ACI rootfs only after the initial /usr contents are
    22  # already there.
    23  #
    24  # STAGE1_ACIDIR_$(flavor) tells where is the ACI directory for a given
    25  # flavor. Note that this is the toplevel directory (where manifest is
    26  # stored). Most of the time you will want the
    27  # STAGE1_ACIROOTFSDIR_$(flavor) variable.
    28  #
    29  # STAGE1_ACIROOTFSDIR_$(flavor) tells where is the ACI rootfs
    30  # directory for a given flavor.
    31  #
    32  # STAGE1_ACI_IMAGE_$(flavor) tells where in the build directory the
    33  # final ACI image is going to be built.
    34  #
    35  # STAGE1_INSTALL_FILES_$(flavor) - a list of files that can be
    36  # installed only after all the stamps in STAGE1_USR_STAMPS_$(flavor)
    37  # are created.
    38  #
    39  # STAGE1_INSTALL_SYMLINKS_$(flavor) - a list of symlinks that can be
    40  # installed only after all the stamps in STAGE1_USR_STAMPS_$(flavor)
    41  # are created.
    42  #
    43  # STAGE1_INSTALL_DIRS_$(flavor) - a list of directories that can be
    44  # installed only after all the stamps in STAGE1_USR_STAMPS_$(flavor)
    45  # are created.
    46  #
    47  # STAGE1_CREATE_DIRS_$(flavor) - a list of files that can be installed
    48  # only after all the stamps in STAGE1_USR_STAMPS_$(flavor) are
    49  # created. (This is less restrictive than INSTALL_DIRS counterpart,
    50  # because an entry in CREATE_DIRS does not require the parent
    51  # directory to exist). Please consider this as deprecated in favor of
    52  # INSTALL_DIRS + dir-chain function.
    53  #
    54  # STAGE1_ENTER_CMD_$(flavor) - an enter command in stage1 to be used
    55  # for the "rkt enter" command.
    56  STAGE1_FLAVORS := $(call commas-to-spaces,$(RKT_STAGE1_ALL_FLAVORS))
    57  STAGE1_BUILT_FLAVORS := $(call commas-to-spaces,$(RKT_STAGE1_FLAVORS))
    58  $(foreach f,$(STAGE1_FLAVORS), \
    59  	$(eval STAGE1_COPY_SO_DEPS_$f :=) \
    60  	$(eval STAGE1_USR_STAMPS_$f :=) \
    61  	$(eval STAGE1_SECONDARY_STAMPS_$f :=) \
    62  	$(eval STAGE1_ACIDIR_$f := $(BUILDDIR)/aci-for-$f-flavor) \
    63  	$(eval STAGE1_ACIROOTFSDIR_$f := $(STAGE1_ACIDIR_$f)/rootfs) \
    64  	$(eval STAGE1_ACI_IMAGE_$f := $(BINDIR)/stage1-$f.aci) \
    65  	$(eval STAGE1_INSTALL_FILES_$f :=) \
    66  	$(eval STAGE1_INSTALL_SYMLINKS_$f :=) \
    67  	$(eval STAGE1_INSTALL_DIRS_$f :=) \
    68  	$(eval STAGE1_CREATE_DIRS_$f :=) \
    69  	$(eval STAGE1_ENTER_CMD_$f :=))
    70  
    71  # Main stamp that tells whether all the ACI images have been built.
    72  $(call setup-stamp-file,_STAGE1_BUILT_ACI_STAMP_,built_aci)
    73  
    74  # List of all the ACI images that the build system will build
    75  _STAGE1_ALL_ACI_ := $(foreach f,$(STAGE1_FLAVORS),$(STAGE1_ACI_IMAGE_$f))
    76  _STAGE1_BUILT_ACI_ := $(foreach f,$(STAGE1_BUILT_FLAVORS),$(STAGE1_ACI_IMAGE_$f))
    77  
    78  # The rootfs.mk file takes care of preparing the initial /usr contents
    79  # of the ACI rootfs of a specific flavor. Basically fills
    80  # STAGE1_USR_STAMPS_$(flavor) variables. Might add something to the
    81  # STAGE1_SECONDARY_STAMPS_$(flavor) or the STAGE1_INSTALL_* variables
    82  # too.
    83  $(foreach flavor,$(STAGE1_FLAVORS), \
    84  	$(eval S1_RF_FLAVOR := $(flavor)) \
    85  	$(call inc-one,rootfs.mk))
    86  
    87  # secondary-stuff.mk takes care of putting additional stuff into
    88  # the ACI rootfs for each flavor. Basically fills the
    89  # STAGE1_SECONDARY_STAMPS_$(flavor) and the STAGE1_INSTALL_*
    90  # variables.
    91  $(call inc-one,secondary-stuff.mk)
    92  
    93  TOPLEVEL_STAMPS += $(_STAGE1_BUILT_ACI_STAMP_)
    94  CLEAN_FILES += $(_STAGE1_ALL_ACI_)
    95  
    96  $(call generate-stamp-rule,$(_STAGE1_BUILT_ACI_STAMP_),$(_STAGE1_BUILT_ACI_))
    97  
    98  # A rule template for building an ACI image. To build the ACI image we
    99  # need to have the /usr contents prepared and the additional stuff in
   100  # place as well. If a flavor wants to have missing libraries copied it
   101  # is done here too.
   102  #
   103  # 1 - flavor
   104  define _STAGE1_ACI_RULE_
   105  
   106  STAGE1_ALL_STAMPS_$1 := $$(STAGE1_USR_STAMPS_$1) $$(STAGE1_SECONDARY_STAMPS_$1)
   107  
   108  $$(STAGE1_SECONDARY_STAMPS_$1): $$(STAGE1_USR_STAMPS_$1)
   109  
   110  ifeq ($$(STAGE1_COPY_SO_DEPS_$1),)
   111  
   112  # The flavor needs no libraries from the host
   113  
   114  $$(STAGE1_ACI_IMAGE_$1): $$(STAGE1_ALL_STAMPS_$1)
   115  
   116  else
   117  
   118  # The flavor requires libraries from the host, so depend on the stamp
   119  # generated by find-so-deps.mk, which in turn will depend on the usr
   120  # and the secondary stamps.
   121  
   122  STAGE1_FSD_FLAVOR := $1
   123  
   124  $$(call inc-one,find-so-deps.mk)
   125  
   126  $$(STAGE1_ACI_IMAGE_$1): $$(STAGE1_FSD_STAMP)
   127  
   128  endif
   129  
   130  # The actual rule that builds the ACI image. Additional dependencies
   131  # are above.
   132  $$(call forward-vars,$$(STAGE1_ACI_IMAGE_$1), \
   133  	ACTOOL STAGE1_ACIDIR_$1)
   134  $$(STAGE1_ACI_IMAGE_$1): $$(ACTOOL_STAMP) | $$(BINDIR)
   135  	$(VQ) \
   136  	$(call vb,vt,ACTOOL,$$(call vsp,$$@)) \
   137  	"$$(ACTOOL)" build --overwrite --owner-root "$$(STAGE1_ACIDIR_$1)" "$$@"
   138  
   139  endef
   140  
   141  $(foreach f,$(STAGE1_FLAVORS), \
   142  	$(eval $(call _STAGE1_ACI_RULE_,$f)))
   143  
   144  
   145  # The following piece of wizardry takes the variables
   146  # STAGE1_INSTALL_FILES_$(flavor), STAGE1_INSTALL_SYMLINKS_$(flavor),
   147  # STAGE1_INSTALL_DIRS_$(flavor) and STAGE1_CREATE_DIRS_$(flavor),
   148  # makes their contents to depend on STAGE1_USR_STAMPS_$(flavor) and
   149  # appends their contents to, respectively, INSTALL_FILES,
   150  # INSTALL_SYMLINKS, INSTALL_DIRS and CREATE_DIRS. This is to make sure
   151  # that all the additional stuff will be installed only after the
   152  # initial /usr contents in the ACI rootfs are prepared.
   153  
   154  
   155  # Three fields:
   156  # 1 - base variable name (e.g. INSTALL_FILES)
   157  # 2 - whether it has to be split to get the created entry (elements in
   158  # INSTALL_FILES have to be split, because the created entry is between
   159  # source entry and mode, like src_file:created_entry:mode, elements in
   160  # the CREATE_DIRS variable do not need to be split)
   161  # 3 - if it has to be split, then which item is the created entry
   162  # (index starting from 1)
   163  _STAGE1_FILE_VARS_ := \
   164  	INSTALL_FILES:y:2 \
   165  	INSTALL_SYMLINKS:y:2 \
   166  	INSTALL_DIRS:y:1 \
   167  	CREATE_DIRS:n
   168  
   169  # Generates dependency of a created entry on
   170  # STAGE1_USR_STAMPS_$(flavor)
   171  # 1 - item(s)
   172  # 2 - flavor
   173  define _STAGE1_GEN_DEP_
   174  $(call add-dependency,$1,$(STAGE1_USR_STAMPS_$2))
   175  endef
   176  
   177  # The actual fixup - appending and "dependencing".
   178  $(foreach v,$(_STAGE1_FILE_VARS_), \
   179  	$(eval _S1_FX_VAR_LIST_ := $(subst :, ,$v)) \
   180  	$(eval _S1_FX_NAME_ := $(word 1,$(_S1_FX_VAR_LIST_))) \
   181  	$(eval _S1_FX_SPLIT_ := $(word 2,$(_S1_FX_VAR_LIST_))) \
   182  	$(eval _S1_FX_IDX_ := $(word 3,$(_S1_FX_VAR_LIST_))) \
   183  	$(foreach f,$(STAGE1_FLAVORS), \
   184  		$(eval _S1_FX_VAR_NAME_ := STAGE1_$(_S1_FX_NAME_)_$f) \
   185  		$(eval $(_S1_FX_NAME_) += $($(_S1_FX_VAR_NAME_))) \
   186  		$(eval $(foreach i,$($(_S1_FX_VAR_NAME_)), \
   187  			$(if $(filter y,$(_S1_FX_SPLIT_)), \
   188  				$(eval _S1_FX_LIST_ := $(subst :, ,$i)) \
   189  				$(eval _S1_FX_ITEM_ := $(word $(_S1_FX_IDX_),$(_S1_FX_LIST_))) \
   190  				$(call _STAGE1_GEN_DEP_,$(_S1_FX_ITEM_),$f), \
   191  				$(call _STAGE1_GEN_DEP_,$i,$f))))) \
   192  	$(call undefine-namespaces,_S1_FX))
   193  
   194  $(call undefine-namespaces,STAGE1 _STAGE1)