forked from vmware/photon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
245 lines (200 loc) · 8.27 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#
# Copyright VMware, Inc 2015
#
SRCROOT := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
MAKEROOT=$(SRCROOT)/support/make
# do not build these targets as '%'
$(MAKEROOT)/makedefs.mk: ;
Makefile: ;
include $(MAKEROOT)/makedefs.mk
ifdef PHOTON_CACHE_PATH
PHOTON_PACKAGES := packages-cached
else
PHOTON_PACKAGES := packages
endif
ifdef PHOTON_SOURCES_PATH
PHOTON_SOURCES := sources-cached
else
PHOTON_SOURCES := sources
endif
ifdef PHOTON_PUBLISH_RPMS_PATH
PHOTON_PUBLISH_RPMS := publish-rpms-cached
else
PHOTON_PUBLISH_RPMS := publish-rpms
endif
.PHONY : all iso clean toolchain toolchain-minimal photon-build-machine photon-vagrant-build photon-vagrant-local \
check check-bison check-g++ check-gawk check-createrepo check-vagrant check-packer check-packer-ovf-plugin check-package-list \
clean-install clean-chroot
all: iso
iso: check $(PHOTON_STAGE) $(PHOTON_PACKAGES) $(PHOTON_TOOLCHAIN_MINIMAL)
@echo "Building Photon ISO..."
@cd $(PHOTON_INSTALLER_DIR) && \
$(PHOTON_INSTALLER) -i $(PHOTON_STAGE)/photon.iso \
-w $(PHOTON_STAGE)/photon_iso \
-t $(PHOTON_STAGE) \
-p $(PHOTON_INSTALLER_PACKAGE_LIST) \
-f > \
$(PHOTON_LOGS_DIR)/installer.log 2>&1
packages: check $(PHOTON_PUBLISH_RPMS) $(PHOTON_SOURCES)
@echo "Building all RPMS..."
@cd $(PHOTON_PKG_BUILDER_DIR) && \
$(PHOTON_PACKAGE_BUILDER) -o full \
-s $(PHOTON_SPECS_DIR) \
-r $(PHOTON_RPMS_DIR) \
-x $(PHOTON_SRCS_DIR) \
-b $(PHOTON_STAGE) \
-l $(PHOTON_LOGS_DIR) \
-p $(PHOTON_PUBLISH_RPMS_DIR) \
-j $(PHOTON_PACKAGE_LIST)
packages-cached:
@echo "Using cached RPMS..."
@$(RM) -f $(PHOTON_RPMS_DIR_NOARCH)/* && \
$(RM) -f $(PHOTON_RPMS_DIR_X86_64)/* && \
$(CP) -f $(PHOTON_CACHE_PATH)/RPMS/noarch/* $(PHOTON_RPMS_DIR_NOARCH)/ && \
$(CP) -f $(PHOTON_CACHE_PATH)/RPMS/x86_64/* $(PHOTON_RPMS_DIR_X86_64)/
sources:
@echo "Pulling sources from bintray..."
@$(MKDIR) -p $(PHOTON_SRCS_DIR) && \
cd $(PHOTON_PULL_SOURCES_DIR) && \
$(PHOTON_PULL_SOURCES) -c $(PHOTON_BINTRAY_CONFIG) $(PHOTON_SRCS_DIR)
sources-cached:
@echo "Using cached SOURCES..."
@$(MKDIR) -p $(PHOTON_SRCS_DIR) && \
$(CP) -rf $(PHOTON_SOURCES_PATH)/* $(PHOTON_SRCS_DIR)/
publish-rpms:
@echo "Pulling publish rpms from bintray..."
@cd $(PHOTON_PULL_PUBLISH_RPMS_DIR) && \
$(PHOTON_PULL_PUBLISH_RPMS) $(PHOTON_PUBLISH_RPMS_DIR)
publish-rpms-cached:
@echo "Using cached publish rpms..."
@$(MKDIR) -p $(PHOTON_PUBLISH_RPMS_DIR) && \
$(CP) -rf $(PHOTON_PUBLISH_RPMS_PATH)/* $(PHOTON_PUBLISH_RPMS_DIR)/
toolchain-minimal : $(PHOTON_TOOLCHAIN_MINIMAL)
$(PHOTON_TOOLCHAIN_MIN_LIST): ;
$(PHOTON_TOOLCHAIN_MINIMAL) : $(PHOTON_TOOLCHAIN) $(PHOTON_TOOLCHAIN_MIN_LIST)
echo "Building minimal toolchain..."
@$(RMDIR) $(PHOTON_TOOLS_DIR) && \
cd $(PHOTON_STAGE) && \
$(TAR) xvf $(PHOTON_TOOLCHAIN) > $(PHOTON_LOGS_DIR)/toolchain-minimal.log 2>&1 && \
$(TAR) cvfz \
$@ \
-T $(PHOTON_TOOLCHAIN_MIN_LIST) >> \
$(PHOTON_LOGS_DIR)/toolchain-minimal.log 2>&1 && \
$(RMDIR) $(PHOTON_TOOLS_DIR)
toolchain : $(PHOTON_TOOLCHAIN)
ifdef PHOTON_CACHE_PATH
$(PHOTON_TOOLCHAIN): check $(PHOTON_STAGE)
@echo "Using cached toolchain..."
@$(RM) -f $(PHOTON_TOOLCHAIN) && \
$(CP) -f $(PHOTON_CACHE_PATH)/tools-build.tar $(PHOTON_TOOLCHAIN)
else
$(PHOTON_TOOLCHAIN): $(PHOTON_STAGE) $(PHOTON_SOURCES)
@if [ -f $(PHOTON_TOOLCHAIN) ] ; then \
echo "Using already built toolchain"; \
else \
echo "Building toolchain..."; \
cd $(PHOTON_TOOLCHAIN_DIR) && \
$(PHOTON_TOOLCHAIN_BUILDER) \
$(PHOTON_SRCS_DIR) \
$(PHOTON_SPECS_DIR) \
$(PHOTON_LOGS_DIR) \
$(PHOTON_STAGE) ;\
fi
endif
$(PHOTON_STAGE):
@echo "Creating staging folder..."
$(MKDIR) -p $(PHOTON_STAGE)
@echo "Creating chroot path..."
$(MKDIR) -p $(PHOTON_CHROOT_PATH)
@echo "Building RPMS folders..."
@test -d $(PHOTON_RPMS_DIR_NOARCH) || $(MKDIR) -p $(PHOTON_RPMS_DIR_NOARCH)
@test -d $(PHOTON_RPMS_DIR_X86_64) || $(MKDIR) -p $(PHOTON_RPMS_DIR_X86_64)
@echo "Building SOURCES folder..."
@test -d $(PHOTON_SRCS_DIR) || $(MKDIR) -p $(PHOTON_SRCS_DIR)
@echo "Building LOGS folder..."
@test -d $(PHOTON_LOGS_DIR) || $(MKDIR) -p $(PHOTON_LOGS_DIR)
clean: clean-install clean-chroot
@echo "Deleting Photon ISO..."
@$(RM) -f $(PHOTON_STAGE)/photon.iso
@echo "Deleting stage dir..."
@$(RMDIR) $(PHOTON_STAGE)
@echo "Deleting chroot path..."
@$(RMDIR) $(PHOTON_CHROOT_PATH)
clean-install:
@echo "Cleaning installer working directory..."
@if [ -d $(PHOTON_STAGE)/photon_iso ]; then \
cd $(PHOTON_INSTALLER_DIR) && \
$(PHOTON_INSTALLER_DIR)/mk-unmount-disk.sh -w $(PHOTON_STAGE)/photon_iso && \
$(RMDIR) $(PHOTON_STAGE)/photon_iso; \
fi
clean-chroot:
@echo "Cleaning chroot path..."
@if [ -d $(PHOTON_CHROOT_PATH) ]; then \
cd $(PHOTON_PKG_BUILDER_DIR) && \
$(PHOTON_CHROOT_CLEANER) $(PHOTON_CHROOT_PATH); \
fi
photon-build-machine: check-packer check-vagrant
@echo "Building photon-build-machine with Packer..."
@cd $(PHOTON_PACKER_TEMPLATES) && \
$(PACKER) build photon-build-machine.json
@echo "Adding box to Vagrant boxes..."
@$(VAGRANT) box add $(PHOTON_PACKER_TEMPLATES)/photon-build-machine.box --name photon-build-machine --force && \
$(RM) $(PHOTON_PACKER_TEMPLATES)/photon-build-machine.box
photon-vagrant-build: check-vagrant
@echo "Starting Photon build using Vagrant..."
@cd $(SRCROOT) && \
$(VAGRANT) up && \
$(VAGRANT) destroy -f
ifeq ($(VAGRANT_BUILD),all)
PACKER_ARGS=""
else
PACKER_ARGS="-only=$(VAGRANT_BUILD)"
endif
photon-vagrant-local: check-packer check-vagrant
@echo "Building a Photon Vagrant box with Packer..."
@if [ -e $(PHOTON_STAGE)/photon.iso ]; then \
cd $(PHOTON_PACKER_TEMPLATES) && \
$(SED) -i "" -e "s#\"iso_checksum_value\":.*#\"iso_checksum_value\": \"$$($(SHASUM) ../../stage/photon.iso | cut -f 1 -d ' ')\",#" photon.json && \
$(PACKER) build $(PACKER_ARGS) photon.json && \
$(SED) -i "" -e "s#\"iso_checksum_value\":.*#\"iso_checksum_value\": \"\",#" photon.json; \
echo "Moving boxes to $(PHOTON_STAGE)..." && \
$(MV) *.box $(PHOTON_STAGE); \
else \
echo "Unable to find $(PHOTON_STAGE)/photon.iso ... aborting build"; \
fi
check: check-bison check-g++ check-gawk check-createrepo check-texinfo check-package-list
check-bison:
@command -v bison >/dev/null 2>&1 || { echo "Package bison not installed. Aborting." >&2; exit 1; }
check-texinfo:
@command -v makeinfo >/dev/null 2>&1 || { echo "Package texinfo not installed. Aborting." >&2; exit 1; }
check-g++:
@command -v g++ >/dev/null 2>&1 || { echo "Package g++ not installed. Aborting." >&2; exit 1; }
check-gawk:
@command -v gawk >/dev/null 2>&1 || { echo "Package gawk not installed. Aborting." >&2; exit 1; }
check-createrepo:
@command -v createrepo >/dev/null 2>&1 || { echo "Package createrepo not installed. Aborting." >&2; exit 1; }
check-vagrant: check-packer
@command -v $(VAGRANT) >/dev/null 2>&1 || { echo "Vagrant not installed or wrong path, expecting $(VAGRANT). Aborting" >&2; exit 1; }
check-package-list:
json_pp -t null < installer/package_list.json >/dev/null 2>&1 || { echo "Invalid installer/package_list.json. Aborting" >&2; exit 1; }
ifeq ($(VAGRANT_BUILD),vcloudair)
check-packer: check-packer-ovf-plugin
else ifeq ($(VAGRANT_BUILD),all)
check-packer: check-packer-ovf-plugin
else
check-packer:
endif
@command -v $(PACKER) >/dev/null 2>&1 || { echo "Packer not installed or wrong path, expecting $(PACKER). Aborting" >&2; exit 1; }
check-packer-ovf-plugin:
@[[ -e ~/.packer.d/plugins/packer-post-processor-vagrant-vmware-ovf ]] || { echo "Packer OVF post processor not installed. Aborting" >&2; exit 1; }
%: check $(PHOTON_PUBLISH_RPMS) $(PHOTON_SOURCES)
$(eval PKG_NAME = $@)
@echo "Building package $(PKG_NAME) ..."
@cd $(PHOTON_PKG_BUILDER_DIR) && \
$(PHOTON_PACKAGE_BUILDER) -i $(PKG_NAME)\
-b $(PHOTON_CHROOT_PATH) \
-s $(PHOTON_SPECS_DIR) \
-r $(PHOTON_RPMS_DIR) \
-x $(PHOTON_SRCS_DIR) \
-p $(PHOTON_PUBLISH_RPMS_DIR) \
-l $(PHOTON_LOGS_DIR)