forked from microsoft/opengcs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
81 lines (62 loc) · 2.06 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
GO:=go
GO_FLAGS:=-ldflags "-s -w" # strip Go binaries
GO_BUILD:=CGO_ENABLED=0 $(GO) build $(GO_FLAGS)
CFLAGS:=-O2
LDFLAGS:=-static -s # strip C binaries
SRCROOT=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
BASE:=base.tar.gz
# The link aliases for gcstools
GCS_TOOLS=\
tar2vhd \
vhd2tar \
exportSandbox \
netnscfg \
remotefs
.PHONY: all always rootfs test
all: out/initrd.img out/rootfs.tar.gz
test:
cd $(SRCROOT) && go test ./service/gcsutils/...
cd $(SRCROOT)/service/gcs && ginkgo -r -keepGoing
rootfs: .rootfs-done
.rootfs-done: init/init bin/vsockexec bin/gcs bin/gcstools Makefile
rm -rf rootfs
mkdir -p rootfs/bin/
cp $(SRCROOT)/init/init rootfs/
chmod 755 rootfs/init
cp bin/vsockexec rootfs/bin/
cp bin/gcs rootfs/bin/
cp bin/gcstools rootfs/bin/
for tool in $(GCS_TOOLS); do ln -s gcstools rootfs/bin/$$tool; done
git -C $(SRCROOT) rev-parse HEAD > rootfs/gcs.commit && \
git -C $(SRCROOT) rev-parse --abbrev-ref HEAD > rootfs/gcs.branch
touch .rootfs-done
out/rootfs.tar.gz: $(BASE) .rootfs-done
@mkdir -p out
# Append the added files to the base archive
bsdtar -C rootfs -zcf $@ @$(abspath $(BASE)) .
out/initrd.img: out/rootfs.tar.gz
# Convert from the rootfs tar to newc cpio
bsdtar -zcf $@ --format newc @out/rootfs.tar.gz
out/rootfs.vhd: out/rootfs.tar.gz bin/tar2vhd
@mkdir -p out
t=`mktemp` && zcat out/rootfs.tar.gz | bin/tar2vhd > "$$t" && mv $$t $@
bin/tar2vhd: bin/gcstools
ln -s gcstools $@
bin/gcs.always: always
@mkdir -p bin
$(GO_BUILD) -o $@ github.com/Microsoft/opengcs/service/gcs
bin/gcstools.always: always
@mkdir -p bin
$(GO_BUILD) -o $@ github.com/Microsoft/opengcs/service/gcsutils/gcstools
VPATH=$(SRCROOT)
bin/vsockexec: vsockexec/vsockexec.o
@mkdir -p bin
$(CC) $(LDFLAGS) -o $@ $<
%.o: %.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
# For programs are always rebuilt, so don't update the actual result file if the
# result of the compilation did not change.
%: %.always
@if ! cmp -s $@ $< ; then cp $< $@ ; fi
@rm $<