1 #
2 # Copyright (c) 2013, Joyent, Inc. All rights reserved.
3 #
4
5 ROOT = $(PWD)
6 PROTO = $(ROOT)/proto
7 STRAP_PROTO = $(ROOT)/proto.strap
8 MPROTO = $(ROOT)/manifest.d
9 BOOT_MPROTO = $(ROOT)/boot.manifest.d
10 BOOT_PROTO = $(ROOT)/proto.boot
11
12 # On Darwin/OS X we support running 'make check'
13 ifeq ($(shell uname -s),Darwin)
14 PATH = /bin:/usr/bin:/usr/sbin:/sbin:/opt/local/bin
15 else
16 PATH = /usr/bin:/usr/sbin:/sbin:/opt/local/bin
17 endif
18
19 LOCAL_SUBDIRS := $(shell ls projects/local)
20 OVERLAYS := $(shell cat overlay/order)
21 PKGSRC = $(ROOT)/pkgsrc
22 MANIFEST = manifest.gen
23 BOOT_MANIFEST = boot.manifest.gen
24 JSSTYLE = $(ROOT)/tools/jsstyle/jsstyle
25 JSLINT = $(ROOT)/tools/javascriptlint/build/install/jsl
26 CSTYLE = $(ROOT)/tools/cstyle
27
28 ADJUNCT_TARBALL := $(shell ls `pwd`/illumos-adjunct*.tgz 2>/dev/null \
29 | tail -n1 && echo $?)
30
31 STAMPFILE := $(ROOT)/proto/buildstamp
32
33 WORLD_MANIFESTS := \
34 $(MPROTO)/illumos.manifest \
35 $(MPROTO)/live.manifest \
36 $(MPROTO)/illumos-extra.manifest
37
38 BOOT_MANIFESTS := \
39 $(BOOT_MPROTO)/illumos.manifest
40
41 SUBDIR_MANIFESTS := $(LOCAL_SUBDIRS:%=$(MPROTO)/%.sd.manifest)
42 OVERLAY_MANIFESTS := $(OVERLAYS:$(ROOT)/overlay/%=$(MPROTO)/%.ov.manifest)
43
44 BOOT_VERSION := boot-$(shell [[ -f $(ROOT)/configure-buildver ]] && \
45 echo $$(head -n1 $(ROOT)/configure-buildver)-)$(shell head -n1 $(STAMPFILE))
46 BOOT_TARBALL := output/$(BOOT_VERSION).tgz
47
48 world: 0-extra-stamp 0-illumos-stamp 1-extra-stamp 0-livesrc-stamp \
49 0-local-stamp 0-tools-stamp 0-man-stamp 0-devpro-stamp
50
51 live: world manifest boot
52 @echo $(OVERLAY_MANIFESTS)
53 @echo $(SUBDIR_MANIFESTS)
54 mkdir -p ${ROOT}/log
55 (cd $(ROOT) && \
56 pfexec ./tools/build_live $(ROOT)/$(MANIFEST) $(ROOT)/output \
57 $(OVERLAYS) $(ROOT)/proto $(ROOT)/man/man)
58
59 boot: $(BOOT_TARBALL)
60
61 .PHONY: pkgsrc
62 pkgsrc:
63 cd $(PKGSRC) && gmake install
64
65 $(BOOT_TARBALL): world manifest
66 pfexec rm -rf $(BOOT_PROTO)
67 mkdir -p $(BOOT_PROTO)
68 mkdir -p $(ROOT)/output
69 pfexec ./tools/builder/builder $(ROOT)/$(BOOT_MANIFEST) \
70 $(BOOT_PROTO) $(ROOT)/proto
71 (cd $(BOOT_PROTO) && pfexec gtar czf $(ROOT)/$@ .)
72
73 #
74 # Manifest construction. There are 5 sources for manifests we need to collect
75 # in $(MPROTO) before running the manifest tool. One each comes from
76 # illumos, illumos-extra, and the root of live (covering mainly what's in src).
77 # Additional manifests come from each of $(LOCAL_SUBDIRS), which may choose
78 # to construct them programmatically, and $(OVERLAYS), which must be static.
79 # These all end up in $(MPROTO), where we tell tools/build_manifest to look;
80 # it will pick up every file in that directory and treat it as a manifest.
81 #
82 # In addition, a separate manifest is generated in similar manner for the
83 # boot tarball.
84 #
85 # Look ma, no for loops in these shell fragments!
86 #
87 manifest: $(MANIFEST) $(BOOT_MANIFEST)
88
89 $(MPROTO) $(BOOT_MPROTO):
90 mkdir -p $@
91
92 $(MPROTO)/live.manifest: src/manifest | $(MPROTO)
93 gmake DESTDIR=$(MPROTO) DESTNAME=live.manifest \
94 -C src manifest
95
96 $(MPROTO)/illumos.manifest: projects/illumos/manifest | $(MPROTO)
97 cp projects/illumos/manifest $(MPROTO)/illumos.manifest
98
99 $(BOOT_MPROTO)/illumos.manifest: projects/illumos/manifest | $(BOOT_MPROTO)
100 cp projects/illumos/boot.manifest $(BOOT_MPROTO)/illumos.manifest
101
102 $(MPROTO)/illumos-extra.manifest: 1-extra-stamp | $(MPROTO)
103 gmake DESTDIR=$(MPROTO) DESTNAME=illumos-extra.manifest \
104 -C projects/illumos-extra manifest; \
105
106 .PHONY: $(MPROTO)/%.sd.manifest
107 $(MPROTO)/%.sd.manifest:
108 cd $(ROOT)/projects/local/$* && \
109 if [[ -f Makefile.joyent ]]; then \
110 gmake DESTDIR=$(MPROTO) DESTNAME=$*.sd.manifest \
111 -f Makefile.joyent manifest; \
112 else \
113 gmake DESTDIR=$(MPROTO) DESTNAME=$*.sd.manifest \
114 manifest; \
115 fi
116
117 $(MPROTO)/%.ov.manifest: $(MPROTO) $(ROOT)/overlay/%/manifest
118 cp $(ROOT)/overlay/$*/manifest $@
119
120 $(MANIFEST): $(WORLD_MANIFESTS) $(SUBDIR_MANIFESTS) $(OVERLAY_MANIFESTS)
121 -rm -f $@
122 ./tools/build_manifest $(MPROTO) | ./tools/sorter > $@
123
124 $(BOOT_MANIFEST): $(BOOT_MANIFESTS)
125 -rm -f $@
126 ./tools/build_manifest $(BOOT_MPROTO) | ./tools/sorter > $@
127
128 #
129 # Update source code from parent repositories. We do this for each local
130 # project as well as for illumos, illumos-extra, and illumos-live via the
131 # update_base tool.
132 #
133 update: update-base $(LOCAL_SUBDIRS:%=%.update)
134 -rm -f 0-local-stamp
135
136 .PHONY: update-base
137 update-base:
138 ./tools/update_base
139
140 .PHONY: %.update
141 %.update:
142 cd $(ROOT)/projects/local/$* && \
143 if [[ -f Makefile.joyent ]]; then \
144 gmake -f Makefile.joyent update; \
145 else \
146 gmake update; \
147 fi
148 -rm -f 0-subdir-$*-stamp
149
150 0-local-stamp: $(LOCAL_SUBDIRS:%=0-subdir-%-stamp)
151 touch $@
152
153 0-subdir-%-stamp:
154 cd "$(ROOT)/projects/local/$*" && \
155 if [[ -f Makefile.joyent ]]; then \
156 gmake -f Makefile.joyent DESTDIR=$(PROTO) world install; \
157 else \
158 gmake DESTDIR=$(PROTO) world install; \
159 fi
160 touch $@
161
162 0-devpro-stamp:
163 [ ! -d projects/devpro ] || \
164 (cd projects/devpro && gmake DESTDIR=$(PROTO) install)
165 touch $@
166
167 0-illumos-stamp: 0-extra-stamp
168 (cd $(ROOT) && ./tools/build_illumos)
169 touch $@
170
171 0-extra-stamp:
172 (cd $(ROOT)/projects/illumos-extra && \
173 gmake STRAP=strap DESTDIR=$(STRAP_PROTO) install_strap)
174 (cd $(STRAP_PROTO) && gtar xzf $(ADJUNCT_TARBALL))
175 touch $@
176
177 1-extra-stamp: 0-illumos-stamp
178 (cd $(ROOT)/projects/illumos-extra && \
179 gmake DESTDIR=$(PROTO) install)
180 touch $@
181
182 0-livesrc-stamp: src/bootparams.c
183 (cd $(ROOT)/src && \
184 gmake DESTDIR=$(PROTO) && \
185 gmake DESTDIR=$(PROTO) install)
186 touch $@
187
188 0-man-stamp:
189 (cd $(ROOT)/man/src && gmake clean && gmake)
190 touch $@
191
192 0-tools-stamp: 0-builder-stamp 0-pwgen-stamp tools/cryptpass
193 (cp ${ROOT}/tools/cryptpass $(PROTO)/usr/lib)
194 touch $@
195
196 0-builder-stamp:
197 (cd $(ROOT)/tools/builder && gmake builder)
198 touch $@
199
200 0-pwgen-stamp:
201 (cd ${ROOT}/tools/pwgen-* && autoconf && ./configure && \
202 make && cp pwgen ${ROOT}/tools)
203 touch $@
204
205 tools/cryptpass: tools/cryptpass.c
206 (cd ${ROOT}/tools && gcc -Wall -W -O2 -o cryptpass cryptpass.c)
207
208 jsl: $(JSLINT)
209
210 $(JSLINT):
211 @(cd $(ROOT)/tools/javascriptlint; make CC=gcc install)
212
213 check: $(JSLINT)
214 @(cd $(ROOT)/src && make check)
215
216 clean:
217 rm -f $(MANIFEST)
218 rm -rf $(ROOT)/$(MPROTO)/*
219 (cd $(ROOT)/src && gmake clean)
220 [ ! -d $(ROOT)/projects/illumos-extra ] || \
221 (cd $(ROOT)/projects/illumos-extra && gmake clean)
222 [ ! -d projects/local ] || for dir in $(LOCAL_SUBDIRS); do \
223 cd $(ROOT)/projects/local/$${dir} && \
224 if [[ -f Makefile.joyent ]]; then \
225 gmake -f Makefile.joyent clean; \
226 else \
227 gmake clean; \
228 fi; \
229 done
230 (cd $(PKGSRC) && gmake clean)
231 (cd $(ROOT) && rm -rf $(PROTO))
232 (cd $(ROOT) && rm -rf $(STRAP_PROTO))
233 (cd $(ROOT) && rm -rf $(BOOT_PROTO))
234 (cd $(ROOT) && mkdir -p $(PROTO) $(STRAP_PROTO) $(BOOT_PROTO))
235 rm -f 0-*-stamp 1-*-stamp
236
237 .PHONY: manifest check jsl