github.com/blixtra/rkt@v0.8.1-0.20160204105720-ab0d1add1a43/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 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 57 STAGE1_FLAVORS := $(call commas-to-spaces,$(RKT_STAGE1_ALL_FLAVORS)) 58 STAGE1_BUILT_FLAVORS := $(call commas-to-spaces,$(RKT_STAGE1_FLAVORS)) 59 # filter out the fly flavor - it is special 60 STAGE1_FLAVORS := $(filter-out fly,$(STAGE1_FLAVORS)) 61 STAGE1_BUILT_FLAVORS := $(filter-out fly,$(STAGE1_BUILT_FLAVORS)) 62 63 $(foreach f,$(STAGE1_FLAVORS), \ 64 $(eval STAGE1_COPY_SO_DEPS_$f :=) \ 65 $(eval STAGE1_USR_STAMPS_$f :=) \ 66 $(eval STAGE1_SECONDARY_STAMPS_$f :=) \ 67 $(eval STAGE1_ACIDIR_$f := $(BUILDDIR)/aci-for-$f-flavor) \ 68 $(eval STAGE1_ACIROOTFSDIR_$f := $(STAGE1_ACIDIR_$f)/rootfs) \ 69 $(eval STAGE1_ACI_IMAGE_$f := $(BINDIR)/stage1-$f.aci) \ 70 $(eval STAGE1_INSTALL_FILES_$f :=) \ 71 $(eval STAGE1_INSTALL_SYMLINKS_$f :=) \ 72 $(eval STAGE1_INSTALL_DIRS_$f :=) \ 73 $(eval STAGE1_CREATE_DIRS_$f :=) \ 74 $(eval STAGE1_ENTER_CMD_$f :=)) 75 76 # Main stamp that tells whether all the ACIs have been built. 77 $(call setup-stamp-file,_STAGE1_BUILT_ACI_STAMP_,built_aci) 78 79 # List of all the ACIs that the build system will build 80 _STAGE1_ALL_ACI_ := $(foreach f,$(STAGE1_FLAVORS),$(STAGE1_ACI_IMAGE_$f)) 81 _STAGE1_BUILT_ACI_ := $(foreach f,$(STAGE1_BUILT_FLAVORS),$(STAGE1_ACI_IMAGE_$f)) 82 83 # The rootfs.mk file takes care of preparing the initial /usr contents 84 # of the ACI rootfs of a specific flavor. Basically fills 85 # STAGE1_USR_STAMPS_$(flavor) variables. Might add something to the 86 # STAGE1_SECONDARY_STAMPS_$(flavor) or the STAGE1_INSTALL_* variables 87 # too. 88 $(foreach flavor,$(STAGE1_FLAVORS), \ 89 $(eval S1_RF_FLAVOR := $(flavor)) \ 90 $(call inc-one,rootfs.mk)) 91 92 # secondary-stuff.mk takes care of putting additional stuff into 93 # the ACI rootfs for each flavor. Basically fills the 94 # STAGE1_SECONDARY_STAMPS_$(flavor) and the STAGE1_INSTALL_* 95 # variables. 96 $(call inc-one,secondary-stuff.mk) 97 98 TOPLEVEL_STAMPS += $(_STAGE1_BUILT_ACI_STAMP_) 99 CLEAN_FILES += $(_STAGE1_ALL_ACI_) 100 101 $(call generate-stamp-rule,$(_STAGE1_BUILT_ACI_STAMP_),$(_STAGE1_BUILT_ACI_)) 102 103 # A rule template for building an ACI. To build the ACI we need to 104 # have the /usr contents prepared and the additional stuff in place as 105 # well. If a flavor wants to have missing libraries copied, it is done 106 # here too. 107 # 108 # 1 - flavor 109 define _STAGE1_ACI_RULE_ 110 111 STAGE1_ALL_STAMPS_$1 := $$(STAGE1_USR_STAMPS_$1) $$(STAGE1_SECONDARY_STAMPS_$1) 112 113 $$(STAGE1_SECONDARY_STAMPS_$1): $$(STAGE1_USR_STAMPS_$1) 114 115 ifeq ($$(STAGE1_COPY_SO_DEPS_$1),) 116 117 # The flavor needs no libraries from the host 118 119 $$(STAGE1_ACI_IMAGE_$1): $$(STAGE1_ALL_STAMPS_$1) 120 121 else 122 123 # The flavor requires libraries from the host, so depend on the stamp 124 # generated by find-so-deps.mk, which in turn will depend on the usr 125 # and the secondary stamps. 126 127 STAGE1_FSD_FLAVOR := $1 128 129 $$(call inc-one,find-so-deps.mk) 130 131 $$(STAGE1_ACI_IMAGE_$1): $$(STAGE1_FSD_STAMP) 132 133 endif 134 135 # The actual rule that builds the ACI. Additional dependencies are 136 # above. 137 $$(call forward-vars,$$(STAGE1_ACI_IMAGE_$1), \ 138 ACTOOL STAGE1_ACIDIR_$1) 139 $$(STAGE1_ACI_IMAGE_$1): $$(ACTOOL_STAMP) | $$(BINDIR) 140 $(VQ) \ 141 $(call vb,vt,ACTOOL,$$(call vsp,$$@)) \ 142 "$$(ACTOOL)" build --overwrite --owner-root "$$(STAGE1_ACIDIR_$1)" "$$@" 143 144 endef 145 146 $(foreach f,$(STAGE1_FLAVORS), \ 147 $(eval $(call _STAGE1_ACI_RULE_,$f))) 148 149 150 # The following piece of wizardry takes the variables 151 # STAGE1_INSTALL_FILES_$(flavor), STAGE1_INSTALL_SYMLINKS_$(flavor), 152 # STAGE1_INSTALL_DIRS_$(flavor) and STAGE1_CREATE_DIRS_$(flavor), 153 # makes their contents to depend on STAGE1_USR_STAMPS_$(flavor) and 154 # appends their contents to, respectively, INSTALL_FILES, 155 # INSTALL_SYMLINKS, INSTALL_DIRS and CREATE_DIRS. This is to make sure 156 # that all the additional stuff will be installed only after the 157 # initial /usr contents in the ACI rootfs are prepared. 158 159 160 # Three fields: 161 # 1 - base variable name (e.g. INSTALL_FILES) 162 # 2 - whether it has to be split to get the created entry (elements in 163 # INSTALL_FILES have to be split, because the created entry is between 164 # source entry and mode, like src_file:created_entry:mode, elements in 165 # the CREATE_DIRS variable do not need to be split) 166 # 3 - if it has to be split, then which item is the created entry 167 # (index starting from 1) 168 _STAGE1_FILE_VARS_ := \ 169 INSTALL_FILES:y:2 \ 170 INSTALL_SYMLINKS:y:2 \ 171 INSTALL_DIRS:y:1 \ 172 CREATE_DIRS:n 173 174 # Generates dependency of a created entry on 175 # STAGE1_USR_STAMPS_$(flavor) 176 # 1 - item(s) 177 # 2 - flavor 178 define _STAGE1_GEN_DEP_ 179 $(call add-dependency,$1,$(STAGE1_USR_STAMPS_$2)) 180 endef 181 182 # The actual fixup - appending and "dependencing". 183 $(foreach v,$(_STAGE1_FILE_VARS_), \ 184 $(eval _S1_FX_VAR_LIST_ := $(subst :, ,$v)) \ 185 $(eval _S1_FX_NAME_ := $(word 1,$(_S1_FX_VAR_LIST_))) \ 186 $(eval _S1_FX_SPLIT_ := $(word 2,$(_S1_FX_VAR_LIST_))) \ 187 $(eval _S1_FX_IDX_ := $(word 3,$(_S1_FX_VAR_LIST_))) \ 188 $(foreach f,$(STAGE1_FLAVORS), \ 189 $(eval _S1_FX_VAR_NAME_ := STAGE1_$(_S1_FX_NAME_)_$f) \ 190 $(eval $(_S1_FX_NAME_) += $($(_S1_FX_VAR_NAME_))) \ 191 $(eval $(foreach i,$($(_S1_FX_VAR_NAME_)), \ 192 $(if $(filter y,$(_S1_FX_SPLIT_)), \ 193 $(eval _S1_FX_LIST_ := $(subst :, ,$i)) \ 194 $(eval _S1_FX_ITEM_ := $(word $(_S1_FX_IDX_),$(_S1_FX_LIST_))) \ 195 $(call _STAGE1_GEN_DEP_,$(_S1_FX_ITEM_),$f), \ 196 $(call _STAGE1_GEN_DEP_,$i,$f))))) \ 197 $(call undefine-namespaces,_S1_FX)) 198 199 $(call undefine-namespaces,STAGE1 _STAGE1)