forked from nanovms/nanos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
198 lines (152 loc) · 6.03 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
SUBDIR= contgen mkfs boot stage3 test
# runtime tests / ready-to-use targets
TARGET= webg
ifneq ($(NANOS_TARGET_ROOT),)
TARGET_ROOT_OPT= -r $(NANOS_TARGET_ROOT)
endif
MKFS= $(OUTDIR)/mkfs/bin/mkfs
BOOTIMG= $(OUTDIR)/boot/boot.img
STAGE3= $(OUTDIR)/stage3/bin/stage3.img
IMAGE= $(OUTDIR)/image/disk.raw
CLEANFILES+= $(IMAGE)
CLEANDIRS+= $(OUTDIR)/image
LWIPDIR= $(VENDORDIR)/lwip
GITFLAGS+= --depth 1 https://github.com/nanovms/lwip.git -b STABLE-2_1_2_RELEASE
# GCE
GCLOUD= gcloud
GSUTIL= gsutil
GCE_PROJECT= prod-1033
GCE_BUCKET= nanos-test/gce-images
GCE_IMAGE= nanos-$(TARGET)
GCE_INSTANCE= nanos-$(TARGET)
# AWS
AWS= aws
JQ= jq
PRINTF= printf
CLEAR_LINE= [1K\r
AWS_S3_BUCKET= nanos-test
AWS_AMI_IMAGE= nanos-$(TARGET)
all: image
include rules.mk
.PHONY: image release contgen mkfs boot stage3 target stage distclean
image: mkfs boot stage3 target
@ echo "MKFS $@"
@ $(MKDIR) $(dir $(IMAGE))
$(Q) $(MKFS) $(TARGET_ROOT_OPT) -b $(BOOTIMG) $(IMAGE) <test/runtime/$(TARGET).manifest
release: mkfs boot stage3
$(Q) $(RM) -r release
$(Q) $(MKDIR) release
$(CP) $(MKFS) release
$(CP) $(BOOTIMG) release
$(CP) $(STAGE3) release
cd release && $(TAR) -czvf nanos-release-$(REL_OS)-${version}.tar.gz *
contgen:
$(Q) $(MAKE) -C $@
mkfs boot: contgen
$(Q) $(MAKE) -C $@
stage3: $(LWIPDIR)/.vendored contgen
$(Q) $(MAKE) -C $@
target: contgen
$(Q) $(MAKE) -C test/runtime $(TARGET)
stage: mkfs boot stage3
$(Q) $(MKDIR) .staging
$(Q) $(CP) -a $(MKFS) .staging/mkfs
$(Q) $(CP) -a $(BOOTIMG) .staging/boot.img
$(Q) $(CP) -a $(STAGE3) .staging/stage3.img
distclean: clean
$(Q) $(RM) -rf $(VENDORDIR)
##############################################################################
# tests
.PHONY: test-all test test-noaccel
test-all:
$(Q) $(MAKE) -C test
test test-noaccel: mkfs boot stage3
$(Q) $(MAKE) -C test test
$(Q) $(MAKE) runtime-tests$(subst test,,$@)
RUNTIME_TESTS= creat epoll eventfd fcntl fst getdents getrandom hw hws mkdir mmap pipe readv rename sendfile signal socketpair time unlink vsyscall write writev
.PHONY: runtime-tests runtime-tests-noaccel
runtime-tests runtime-tests-noaccel:
$(foreach t,$(RUNTIME_TESTS),$(call execute_command,$(Q) $(MAKE) run$(subst runtime-tests,,$@) TARGET=$t))
##############################################################################
# run
.PHONY: run run-bridge run-nokvm
QEMU= qemu-system-x86_64
DISPLAY= none
STORAGE= virtio-scsi
QEMU_MEMORY= -m 2G
ifeq ($(DISPLAY),none)
QEMU_DISPLAY= -display none
else ifeq ($(DISPLAY),vga)
QEMU_DISPLAY=
else
$(error Unsupported DISPLAY=$(DISPLAY))
endif
QEMU_SERIAL= -serial stdio
QEMU_STORAGE= -drive if=none,id=hd0,format=raw,file=$(IMAGE)
ifeq ($(STORAGE),virtio-scsi)
QEMU_STORAGE+= -device virtio-scsi-pci,id=scsi0 -device scsi-hd,bus=scsi0.0,drive=hd0
else ifeq ($(STORAGE),virtio-blk)
QEMU_STORAGE+= -device virtio-blk,drive=hd0
else ifeq ($(STORAGE),ide)
QEMU_STORAGE+= -device ide-hd,bus=ide.0,drive=hd0
else
$(error Unsupported STORAGE=$(STORAGE))
endif
QEMU_TAP= -netdev tap,id=n0,ifname=tap0,script=no,downscript=no
QEMU_NET= -device virtio-net,mac=7e:b8:7e:87:4a:ea,netdev=n0 $(QEMU_TAP)
QEMU_USERNET= -device virtio-net,netdev=n0 -netdev user,id=n0,hostfwd=tcp::8080-:8080,hostfwd=tcp::9090-:9090,hostfwd=udp::5309-:5309
QEMU_FLAGS=
QEMU_COMMON= $(QEMU_MEMORY) $(QEMU_DISPLAY) $(QEMU_SERIAL) $(QEMU_STORAGE) -device isa-debug-exit -no-reboot $(QEMU_FLAGS)
run: image
$(QEMU) $(QEMU_COMMON) $(QEMU_USERNET) $(QEMU_ACCEL) || exit $$(($$?>>1))
run-bridge: image
$(QEMU) $(QEMU_COMMON) $(QEMU_NET) $(QEMU_ACCEL) || exit $$(($$?>>1))
run-noaccel: image
$(QEMU) $(QEMU_COMMON) $(QEMU_USERNET) || exit $$(($$?>>1))
##############################################################################
# GCE
.PHONY: upload-gce-image gce-image delete-gce-image
.PHONY: run-gce delete-gce gce-console
CLEANFILES+= $(OUTDIR)/image/*-image.tar.gz
upload-gce-image: image
$(Q) cd $(dir $(IMAGE)) && $(GNUTAR) cfz $(GCE_IMAGE)-image.tar.gz $(notdir $(IMAGE))
$(Q) $(GSUTIL) cp $(dir $(IMAGE))$(GCE_IMAGE)-image.tar.gz gs://$(GCE_BUCKET)/$(GCE_IMAGE)-image.tar.gz
gce-image: upload-gce-image delete-gce-image
$(Q) $(GCLOUD) compute --project=$(GCE_PROJECT) images create $(GCE_IMAGE) --source-uri=https://storage.googleapis.com/$(GCE_BUCKET)/$(GCE_IMAGE)-image.tar.gz
delete-gce-image:
- $(Q) $(GCLOUD) compute --project=$(GCE_PROJECT) images delete $(GCE_IMAGE) --quiet
run-gce: delete-gce
$(Q) $(GCLOUD) compute --project=$(GCE_PROJECT) instances create $(GCE_INSTANCE) --machine-type=custom-1-2048 --image=nanos-$(TARGET) --image-project=$(GCE_PROJECT) --tags=nanos
$(Q) $(MAKE) gce-console
delete-gce:
- $(Q) $(GCLOUD) compute --project=$(GCE_PROJECT) instances delete $(GCE_INSTANCE) --quiet
gce-console:
$(Q) $(GCLOUD) compute --project=$(GCE_PROJECT) instances tail-serial-port-output $(GCE_INSTANCE)
##############################################################################
# AWS
.PHONY: upload-ec2-image create-ec2-snapshot
upload-ec2-image:
$(Q) $(AWS) s3 cp $(IMAGE) s3://$(AWS_S3_BUCKET)/$(AWS_AMI_IMAGE).raw
create-ec2-snapshot: upload-ec2-image
$(Q) json=`$(AWS) ec2 import-snapshot --disk-container "Description=NanoVMs Test,Format=raw,UserBucket={S3Bucket=$(AWS_S3_BUCKET),S3Key=$(AWS_AMI_IMAGE).raw}"` && \
import_task_id=`$(ECHO) "$$json" | $(JQ) -r .ImportTaskId` && \
while :; do \
json=`$(AWS) ec2 describe-import-snapshot-tasks --import-task-ids $$import_task_id`; \
status=`$(ECHO) "$$json" | $(JQ) -r ".ImportSnapshotTasks[0].SnapshotTaskDetail.Status"`; \
if [ x"$$status" = x"completed" ]; then \
$(PRINTF) "$(CLEAR_LINE)Task $$import_task_id: $$status\n"; \
break; \
fi; \
progress=`$(ECHO) "$$json" | $(JQ) -r ".ImportSnapshotTasks[0].SnapshotTaskDetail.Progress?"`; \
status_message=`$(ECHO) "$$json" | $(JQ) -r ".ImportSnapshotTasks[0].SnapshotTaskDetail.StatusMessage?"`; \
$(PRINTF) "$(CLEAR_LINE)Task $$import_task_id: $$status_message ($$progress%%)"; \
done
ifeq ($(UNAME_s),Darwin)
REL_OS= darwin
QEMU_ACCEL= -accel $(ACCEL) -cpu host
ACCEL?= hvf
# ACCEL=? hax
else
REL_OS= linux
QEMU_ACCEL= -enable-kvm -cpu host
endif