-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
142 lines (107 loc) · 4.88 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
# if Makefile.local exists, include it
ifneq ("$(wildcard Makefile.local)", "")
include Makefile.local
endif
PACKER_VERSION = $(shell packer --version | sed 's/^.* //g' | sed 's/^.//')
ifneq (0.5.0, $(word 1, $(sort 0.5.0 $(PACKER_VERSION))))
$(error Packer version less than 0.5.x, please upgrade)
endif
CENTOS65_X86_64 ?= http://mirrors.kernel.org/centos/6.5/isos/x86_64/CentOS-6.5-x86_64-bin-DVD1.iso
BOX_VERSION ?= $(shell cat VERSION)
BOX_SUFFIX ?= -$(BOX_VERSION).box
PACKER_VARS := -var 'headless=$(HEADLESS)' -var 'update=$(UPDATE)' -var 'version=$(BOX_VERSION)'
ifdef PACKER_DEBUG
PACKER := PACKER_LOG=1 packer --debug
else
PACKER := packer
endif
BUILDER_TYPES := vmware virtualbox parallels
TEMPLATE_FILENAMES := $(wildcard *.json)
BOX_FILENAMES := $(TEMPLATE_FILENAMES:.json=$(BOX_SUFFIX))
BOX_FILES := $(foreach builder, $(BUILDER_TYPES), $(foreach box_filename, $(BOX_FILENAMES), box/$(builder)/$(box_filename)))
TEST_BOX_FILES := $(foreach builder, $(BUILDER_TYPES), $(foreach box_filename, $(BOX_FILENAMES), test-box/$(builder)/$(box_filename)))
VMWARE_BOX_DIR := box/vmware
VIRTUALBOX_BOX_DIR := box/virtualbox
PARALLELS_BOX_DIR := box/parallels
VMWARE_OUTPUT := output-vmware-iso
VIRTUALBOX_OUTPUT := output-virtualbox-iso
PARALLELS_OUTPUT := output-parallels-iso
VMWARE_BUILDER := vmware-iso
VIRTUALBOX_BUILDER := virtualbox-iso
PARALLELS_BUILDER := parallels-iso
CURRENT_DIR = $(shell pwd)
SOURCES := $(wildcard script/*.sh) $(http/*.cfg)
.PHONY: list
all: $(BOX_FILES)
test: $(TEST_BOX_FILES)
###############################################################################
# Target shortcuts
define SHORTCUT
vmware/$(1): $(VMWARE_BOX_DIR)/$(1)$(BOX_SUFFIX)
test-vmware/$(1): test-$(VMWARE_BOX_DIR)/$(1)$(BOX_SUFFIX)
ssh-vmware/$(1): ssh-$(VMWARE_BOX_DIR)/$(1)$(BOX_SUFFIX)
virtualbox/$(1): $(VIRTUALBOX_BOX_DIR)/$(1)$(BOX_SUFFIX)
test-virtualbox/$(1): test-$(VIRTUALBOX_BOX_DIR)/$(1)$(BOX_SUFFIX)
ssh-virtualbox/$(1): ssh-$(VIRTUALBOX_BOX_DIR)/$(1)$(BOX_SUFFIX)
parallels/$(1): $(PARALLELS_BOX_DIR)/$(1)$(BOX_SUFFIX)
test-parallels/$(1): test-$(PARALLELS_BOX_DIR)/$(1)$(BOX_SUFFIX)
ssh-parallels/$(1): ssh-$(PARALLELS_BOX_DIR)/$(1)$(BOX_SUFFIX)
$(1): vmware/$(1) virtualbox/$(1) parallels/$(1)
test-$(1): test-vmware/$(1) test-virtualbox/$(1) test-parallels/$(1)
endef
SHORTCUT_TARGETS := centos65
$(foreach i,$(SHORTCUT_TARGETS),$(eval $(call SHORTCUT,$(i))))
###############################################################################
$(VMWARE_BOX_DIR)/centos65$(BOX_SUFFIX): centos65.json $(SOURCES)
rm -rf $(VMWARE_OUTPUT)
mkdir -p $(VMWARE_BOX_DIR)
$(PACKER) build -only=$(VMWARE_BUILDER) $(PACKER_VARS) -var "iso_url=$(CENTOS65_X86_64)" $<
$(VIRTUALBOX_BOX_DIR)/centos65$(BOX_SUFFIX): centos65.json $(SOURCES)
rm -rf $(VIRTUALBOX_OUTPUT)
mkdir -p $(VIRTUALBOX_BOX_DIR)
$(PACKER) build -only=$(VIRTUALBOX_BUILDER) $(PACKER_VARS) -var "iso_url=$(CENTOS65_X86_64)" $<
$(PARALLELS_BOX_DIR)/centos65$(BOX_SUFFIX): centos65.json $(SOURCES)
rm -rf $(PARALLELS_OUTPUT)
mkdir -p $(PARALLELS_BOX_DIR)
$(PACKER) build -only=$(PARALLELS_BUILDER) $(PACKER_VARS) -var "iso_url=$(CENTOS65_X86_64)" $<
list:
@echo "Prepend 'vmware/', 'virtualbox/' or 'parallels/' to build only one target platform:"
@echo " make vmware/centos65"
@echo ""
@echo "Targets:"
@for shortcut_target in $(SHORTCUT_TARGETS) ; do \
echo $$shortcut_target ; \
done
validate:
@for template_filename in $(TEMPLATE_FILENAMES) ; do \
echo Checking $$template_filename ; \
packer validate $$template_filename ; \
done
clean: clean-builders clean-output clean-packer-cache
clean-builders:
@for builder in $(BUILDER_TYPES) ; do \
if test -d box/$$builder ; then \
echo Deleting box/$$builder/*.box ; \
find box/$$builder -maxdepth 1 -type f -name "*.box" ! -name .gitignore -exec rm '{}' \; ; \
fi ; \
done
clean-output:
@for builder in $(BUILDER_TYPES) ; do \
echo Deleting output-$$builder-iso ; \
echo rm -rf output-$$builder-iso ; \
done
clean-packer-cache:
echo Deleting packer_cache
rm -rf packer_cache
test-$(VMWARE_BOX_DIR)/%$(BOX_SUFFIX): $(VMWARE_BOX_DIR)/%$(BOX_SUFFIX)
bin/test-box.sh $< vmware_desktop vmware_fusion $(CURRENT_DIR)/test/*_spec.rb || exit
test-$(VIRTUALBOX_BOX_DIR)/%$(BOX_SUFFIX): $(VIRTUALBOX_BOX_DIR)/%$(BOX_SUFFIX)
bin/test-box.sh $< virtualbox virtualbox $(CURRENT_DIR)/test/*_spec.rb || exit
test-$(PARALLELS_BOX_DIR)/%$(BOX_SUFFIX): $(PARALLELS_BOX_DIR)/%$(BOX_SUFFIX)
bin/test-box.sh $< parallels parallels $(CURRENT_DIR)/test/*_spec.rb || exit
ssh-$(VMWARE_BOX_DIR)/%$(BOX_SUFFIX): $(VMWARE_BOX_DIR)/%$(BOX_SUFFIX)
bin/ssh-box.sh $< vmware_desktop vmware_fusion $(CURRENT_DIR)/test/*_spec.rb
ssh-$(VIRTUALBOX_BOX_DIR)/%$(BOX_SUFFIX): $(VIRTUALBOX_BOX_DIR)/%$(BOX_SUFFIX)
bin/ssh-box.sh $< virtualbox virtualbox $(CURRENT_DIR)/test/*_spec.rb
ssh-$(PARALLELS_BOX_DIR)/%$(BOX_SUFFIX): $(PARALLELS_BOX_DIR)/%$(BOX_SUFFIX)
bin/ssh-box.sh $< parallels parallels $(CURRENT_DIR)/test/*_spec.rb