Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 407 lines (355 sloc) 12.677 kb
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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
#
# Copyright (c) 2012, Joyent, Inc. All rights reserved.
#

include Makefile.defs

#
# ROOT is used only when building and running the below tools.
#
ROOT = $(PWD)/..
JSSTYLE = $(ROOT)/tools/jsstyle/jsstyle
JSLINT = $(ROOT)/tools/javascriptlint/build/install/jsl
CSTYLE = $(ROOT)/tools/cstyle

#
# Tool options
#
JSSTYLE_OPTS = -o indent=4,strict-indent=1,doxygen,unparenthesized-return=0,continuation-at-front=1,leading-right-paren-ok=1

#
# Installation configuration. Note that DESTDIR in particular is also
# assumed to contain various build tools, headers, libraries, and other
# artifacts of the platform build from which we incorporate runtime
# dependency information. The default DESTDIR is for standalone builds
# only (i.e., without the rest of the platform) and is unlikely to work
# without extra effort; it is overridden when make is invoked in this
# subdirectory.
#
DESTDIR = ../proto

#
# DESTNAME is used for the manifest target. We set it to something
# obvious here so that if it's not set, the manifest target doesn't do
# bad things.
#
DESTNAME = live.manifest

SMARTDCBINDIR = $(DESTDIR)/smartdc/bin
SMARTDCLIBDIR = $(DESTDIR)/smartdc/lib

#
# Per-target variable definitions go here. See Makefile.defs and the targets
# below and in Makefile.targ to see what's useful to append to or override.
# If you need to create your own target anyway, you can either modify
# variables here or incorporate your changes directly into the target; we
# prefer modifying the generic variable to the extent that the change fits
# naturally with an existing one so that we can pick up general changes in
# Makefile.defs even for custom targets.
#
bootparams : LIBS += -ldevinfo
bootparams : WARN_FLAGS += -Wno-unused
diskinfo : LIBS += -ldladm -ldiskmgt -lnvpair
zfs_recv : LIBS += -lsocket
zfs_send : LIBS += -lsocket
vmbundle : CPPFLAGS += -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
sdc-on-tty : CFLAGS += $(OPT_FLAG)
zoneevent : LIBS += -lnvpair -lsysevent

# These files will get run through jsstyle and jslint on 'make check'
JS_CHECK_TARGETS=\
node_modules/{system,onlyif}.js \
vm/sbin/*.js \
vm/node_modules/{qmp,VM,dladm}.js \
img/node_modules/*.js \
img/sbin/imgadm

# These files will get run through cstyle on 'make check'
C_CHECK_TARGETS=\
qemu-exec.c \
vmunbundle.c \
zfs_recv.c \
zfs_send.c \
zoneevent.c

#
# Generic flags we apply by default to everything.
#
CFLAGS += $(WARN_FLAGS)
CXXFLAGS = $(CFLAGS)

#
# Node native add-on patterns. For add-ons with a single source file in the
# root of the add-on tree and no headers of its own, follow the EXPAT.NODE
# pattern here and below in the targets. More complex examples (source
# subdirectory, headers, multiple C++ sources) follow; see associated comments
# if you are looking for a pattern to copy.
#
EXPAT_OBJDIR = node-expat/build/Release
EXPAT.NODE = $(EXPAT_OBJDIR)/node-expat.node

$(EXPAT.NODE) : WARN_FLAGS += -Wno-unused
$(EXPAT.NODE) : CPPFLAGS += $(NODE_CPPFLAGS)
$(EXPAT.NODE) : CXXFLAGS += $(NODE_CFLAGS)
$(EXPAT.NODE) : LDFLAGS += $(NODE_LDFLAGS)
$(EXPAT.NODE) : LIBS += -lexpat

#
# The kstat Node add-on follows the same pattern as EXPAT.NODE.
#
KSTAT_OBJDIR = node-kstat/build/Release
KSTAT.NODE = $(KSTAT_OBJDIR)/kstat.node

$(KSTAT.NODE) : WARN_FLAGS += -Wno-unused -Wno-write-strings -Wno-sign-compare
$(KSTAT.NODE) : CPPFLAGS += $(NODE_CPPFLAGS)
$(KSTAT.NODE) : CXXFLAGS += $(NODE_CFLAGS)
$(KSTAT.NODE) : LDFLAGS += $(NODE_LDFLAGS)
$(KSTAT.NODE) : LIBS += -lkstat

#
# Likewise the syslog add-on.
#
SYSLOG_OBJDIR = node-syslog/build/Release
SYSLOG.NODE = $(SYSLOG_OBJDIR)/syslog.node

$(SYSLOG.NODE) : WARN_FLAGS += -Wno-unused
$(SYSLOG.NODE) : CPPFLAGS += $(NODE_CPPFLAGS)
$(SYSLOG.NODE) : CXXFLAGS += $(NODE_CFLAGS)
$(SYSLOG.NODE) : LDFLAGS += $(NODE_LDFLAGS)

#
# The sqlite3 add-on uses a combination of C + C++ files in multiple
# directories, and has multiple header directories as well.
#
SQLITE3_OBJDIR = node-sqlite3/build/Release
SQLITE3_SRCDIR = node-sqlite3/src
SQLITE3_LIBSRCDIR = node-sqlite3/deps/sqlite3
SQLITE3_BINDINGS.NODE = $(SQLITE3_OBJDIR)/node_sqlite3.node

SQLITE3_SRCS += \
database.cc \
node_sqlite3.cc \
statement.cc

SQLITE3_LIBSRCS += sqlite3.c

SQLITE3_NODEHDRS += \
async.h \
macros.h \
statement.h \
threading.h

SQLITE3_LIBHDRS += \
sqlite3.h \
sqlite3ext.h

SQLITE3_OBJS = \
$(SQLITE3_SRCS:%.cc=$(SQLITE3_OBJDIR)/%.o) \
$(SQLITE3_LIBSRCS:%.c=$(SQLITE3_OBJDIR)/%.o)
SQLITE3_HDRS = \
$(SQLITE3_NODEHDRS:%=$(SQLITE3_SRCDIR)/%) \
$(SQLITE3_LIBHDRS:%=$(SQLITE3_LIBSRCDIR)/%)
CLEANFILES += $(SQLITE3_OBJS)

SQLITE3_FLAGS = \
-fdata-sections \
-ffunction-sections \
-fno-omit-frame-pointer \
-fno-strict-aliasing \
-fno-exceptions

$(SQLITE3_BINDINGS.NODE) : WARN_FLAGS = -Wall -Werror
$(SQLITE3_BINDINGS.NODE) : CPPFLAGS += \
$(NODE_CPPFLAGS) \
-I$(SQLITE3_LIBSRCDIR) \
-D_SQLITE_THREADSAFE=1 \
-D_SQLITE_ENABLE_FTS3 \
-D_SQLITE_ENABLE_RTREE \
-D_LARGEFILE_SOURCE \
-D_FILE_OFFSET_BITS=64 \
-D_REENTRANT \
-D_NDEBUG \
-D_POSIX_PTHREAD_SEMANTICS
$(SQLITE3_BINDINGS.NODE) : CFLAGS += \
$(NODE_CFLAGS) \
$(SQLITE3_FLAGS)
$(SQLITE3_BINDINGS.NODE) : LDFLAGS += \
$(NODE_LDFLAGS) \
-Wl,-soname=node_sqlite3.node
$(SQLITE3_BINDINGS.NODE) : LIBS += -lpthread

#
# The zsock add-on places its single source file in a subdirectory.
#
ZSOCK_OBJDIR = node-zsock/build/Release
ZSOCK_SRCDIR = node-zsock/src
ZSOCK_BINDINGS.NODE = $(ZSOCK_OBJDIR)/zsock_bindings.node

$(ZSOCK_BINDINGS.NODE) : WARN_FLAGS = -Wall -Werror
$(ZSOCK_BINDINGS.NODE) : CPPFLAGS += \
$(NODE_CPPFLAGS) \
-D_REENTRANT \
-D_POSIX_PTHREAD_SEMANTICS \
-D_XOPEN_SOURCE_EXTENDED=1 \
-D__EXTENSIONS__ \
-DSunOS
$(ZSOCK_BINDINGS.NODE) : CXXFLAGS += \
$(NODE_CFLAGS) \
-std=c++98
$(ZSOCK_BINDINGS.NODE) : LDFLAGS += $(NODE_LDFLAGS)
$(ZSOCK_BINDINGS.NODE) : LIBS += -lsocket -lnsl -lcontract

#
# The zutil add-on places its multiple source files in a subdirectory, and
# builds them against some headers that it also supplies and needs to depend on.
# Because we must build intermediate object files, this requires a
# different target pattern as well; see below.
#
ZUTIL_OBJDIR = node-zutil/build/Release
ZUTIL_SRCDIR = node-zutil/src
ZUTIL_BINDINGS.NODE = $(ZUTIL_OBJDIR)/zutil_bindings.node

ZUTIL_SRCS += \
zone.cc \
zonecfg.cc \
zutil_bindings.cc

ZUTIL_HDRS += \
zone.h \
zonecfg.h \
zutil_common.h

ZUTIL_BINDINGS_OBJS = $(ZUTIL_SRCS:%.cc=$(ZUTIL_OBJDIR)/%.o)
ZUTIL_BINDINGS_HDRS = $(ZUTIL_HDRS:%=$(ZUTIL_SRCDIR)/%)
CLEANFILES += $(ZUTIL_BINDINGS_OBJS)

$(ZUTIL_BINDINGS.NODE) : WARN_FLAGS += -Wno-unused
$(ZUTIL_BINDINGS.NODE) : CPPFLAGS += $(NODE_CPPFLAGS) -DSunOS
$(ZUTIL_BINDINGS.NODE) : CXXFLAGS += $(NODE_CFLAGS)
$(ZUTIL_BINDINGS.NODE) : LDFLAGS += $(NODE_LDFLAGS)
$(ZUTIL_BINDINGS.NODE) : LIBS += -lzonecfg

#
# List of targets. TARGETS, SMARTDC_TARGETS, and SMARTDC_LIB_TARGETS must
# include only those files that are safe to remove when the clean target is
# built.
#
TARGETS = \
bootparams \
diskinfo \
disklist \
disk_size \
removable_disk \
vmunbundle \
zfs_recv \
zfs_send \
zoneevent \
$(EXPAT.NODE) \
$(KSTAT.NODE) \
$(SYSLOG.NODE) \
$(SQLITE3_BINDINGS.NODE) \
$(ZSOCK_BINDINGS.NODE) \
$(ZUTIL_BINDINGS.NODE)

SMARTDC_TARGETS = \
qemu-exec

SMARTDC_LIB_TARGETS = \
sdc-on-tty

all: $(TARGETS) sysinfo $(SMARTDC_TARGETS) $(SMARTDC_LIB_TARGETS)

install: all
mkdir -p $(DESTDIR)/usr/bin
cp -p $(TARGETS) sysinfo $(DESTDIR)/usr/bin
mkdir -p $(DESTDIR)/smartdc/bin
cp -p $(SMARTDC_TARGETS) $(DESTDIR)/smartdc/bin
mkdir -p $(DESTDIR)/smartdc/lib
cp -p $(SMARTDC_LIB_TARGETS) $(DESTDIR)/smartdc/lib
mkdir -m 0755 -p $(PREFIX_NODE)/node_modules
cp -Pr node_modules/* $(PREFIX_NODE)/node_modules
cp $(KSTAT.NODE) $(PREFIX_NODE)/node_modules/
cp $(SYSLOG.NODE) $(PREFIX_NODE)/node_modules/syslog.node
rm -rf $(DESTDIR)/usr/vm
cp -PR vm $(DESTDIR)/usr/
mkdir -m 0755 -p $(DESTDIR)/usr/vm/node_modules
mkdir -p $(PREFIX_NODE)/node_modules/{zsock,zutil}/build/Release
mkdir -p $(DESTDIR)/usr/vm/test/tests
cp -Pr vm/common $(DESTDIR)/usr/vm/test/
cp -Pr vm/node-tap $(DESTDIR)/usr/vm/test/
cp -Pr vm/tests $(DESTDIR)/usr/vm/test/
cp vm/runtest $(DESTDIR)/usr/vm/test/
cp vm/runtests $(DESTDIR)/usr/vm/test/
cp -Pr node-zsock/{package.json,lib} \
$(PREFIX_NODE)/node_modules/zsock
cp -Pr node-zutil/{package.json,lib} \
$(PREFIX_NODE)/node_modules/zutil
cp $(SQLITE3_BINDINGS.NODE) \
$(PREFIX_NODE)/node_modules
(sed -e "s|var sqlite3.*;|var sqlite3 = module.exports = exports = require('./node_sqlite3');|" | \
sed -e "s|var trace = require.*;|var trace = require('./sqlite3_trace')|") \
< node-sqlite3/lib/sqlite3.js \
> $(PREFIX_NODE)/node_modules/sqlite3.js
cp node-sqlite3/lib/trace.js $(PREFIX_NODE)/node_modules/sqlite3_trace.js
cp $(ZSOCK_BINDINGS.NODE) \
$(PREFIX_NODE)/node_modules/zsock/build/Release
cp $(ZUTIL_BINDINGS.NODE) \
$(PREFIX_NODE)/node_modules/zutil/build/Release
cp $(EXPAT.NODE) $(PREFIX_NODE)/node_modules/expat_binding.node
sed -e "s|var expat.*;|var expat = require('./expat_binding');|" \
< node-expat/lib/node-expat.js \
> $(PREFIX_NODE)/node_modules/node-expat.js
cp zoneevent $(DESTDIR)/usr/vm/sbin/zoneevent
cp zfs_send $(DESTDIR)/usr/vm/sbin/zfs_send
cp zfs_recv $(DESTDIR)/usr/vm/sbin/zfs_recv
cp vmunbundle $(DESTDIR)/usr/vm/sbin/vmunbundle
mkdir -p $(DESTDIR)/lib/svc/manifest/system
cp vm/smf/system-vmadmd.xml \
$(DESTDIR)/lib/svc/manifest/system/system-vmadmd.xml
cp vm/smf/system-metadata.xml \
$(DESTDIR)/lib/svc/manifest/system/system-metadata.xml
mv $(DESTDIR)/usr/vm/sbin/vmadmd.js $(DESTDIR)/usr/vm/sbin/vmadmd
mv $(DESTDIR)/usr/vm/sbin/vmadm.js $(DESTDIR)/usr/vm/sbin/vmadm
mv $(DESTDIR)/usr/vm/sbin/add-userscript.js \
$(DESTDIR)/usr/vm/sbin/add-userscript
mv $(DESTDIR)/usr/vm/sbin/metadata.js $(DESTDIR)/usr/vm/sbin/metadata
cp -PR img $(DESTDIR)/usr/
mkdir -m 0755 -p $(DESTDIR)/var/db/imgadm

check: $(JSLINT)
@echo "==> Running cstyle..."
@# cstyle doesn't echo as it goes so we add an echo to each line below
@(for file in $(C_CHECK_TARGETS); do \
echo $(PWD)/$$file; \
$(CSTYLE) $$file; \
done)
@printf "\nC files ok!\n"
@printf "\n==> Running JavaScriptLint...\n"
@$(JSLINT) --nologo --conf=$(ROOT)/tools/jsl.node.conf \
$(JS_CHECK_TARGETS)
@printf "\n==> Running jsstyle...\n"
@# jsstyle doesn't echo as it goes so we add an echo to each line below
@(for file in $(JS_CHECK_TARGETS); do \
echo $(PWD)/$$file; \
$(JSSTYLE) $(JSSTYLE_OPTS) $$file; \
[[ $$? == "0" ]] || exit 1; \
done)
@printf "\nJS style ok!\n"

.PHONY: manifest
manifest:
(cat manifest && cd vm && \
echo "# list of tests is autogenerated by smartos-live/src/Makefile" && \
find tests/ -type f -exec echo "{}" "0444 root bin" \;) \
| sed -e "s|^tests/|f usr/vm/test/tests/|" \
> $(DESTDIR)/$(DESTNAME) \

$(JSLINT):
(cd $(ROOT); $(MAKE) jsl)

clean:
-rm -f $(TARGETS) $(SMARTDC_TARGETS) $(SMARTDC_LIB_TARGETS) *.o \
$(CLEANFILES)
-rm -rf node-sqlite3/build

include Makefile.targ

#
# Custom rules for building our various real targets follow. Generic rules
# belong in Makefile.targ.
#
disklist:
cp disklist.sh disklist
chmod 0755 disklist

sysinfo:
touch sysinfo

#
# Node native add-on target patterns. Follow these patterns when adding a new
# add-on and see the comment and definitions for EXPAT.NODE above as well.
#
$(EXPAT.NODE): node-expat/node-expat.cc
@mkdir -p $(EXPAT_OBJDIR)
$(GXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ $< $(LIBS)

$(KSTAT.NODE): node-kstat/kstat.cc
@mkdir -p $(KSTAT_OBJDIR)
$(GXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ $< $(LIBS)

$(SYSLOG.NODE): node-syslog/syslog.cc
@mkdir -p $(SYSLOG_OBJDIR)
$(GXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ $< $(LIBS)

$(SQLITE3_OBJDIR)/%.o: $(SQLITE3_SRCDIR)/%.cc $(SQLITE3_HDRS)
@mkdir -p $(SQLITE3_OBJDIR)
$(GXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ -c $<

$(SQLITE3_OBJDIR)/%.o: $(SQLITE3_LIBSRCDIR)/%.c $(SQLITE3_HDRS)
@mkdir -p $(SQLITE3_OBJDIR)
$(GCC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $<

$(SQLITE3_BINDINGS.NODE): $(SQLITE3_OBJS)
$(GXX) $(LDFLAGS) -o $@ $(SQLITE3_OBJS) $(LIBS)

$(ZSOCK_BINDINGS.NODE): $(ZSOCK_SRCDIR)/zsock.cc
@mkdir -p $(ZSOCK_OBJDIR)
$(GXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ $< $(LIBS)

#
# The zutil add-on requires a slightly more complex 2-phase build.
#
$(ZUTIL_OBJDIR)/%.o: $(ZUTIL_SRCDIR)/%.cc $(ZUTIL_BINDINGS_HDRS)
@mkdir -p $(ZUTIL_OBJDIR)
$(GXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ -c $<

$(ZUTIL_BINDINGS.NODE): $(ZUTIL_BINDINGS_OBJS)
$(GXX) $(LDFLAGS) -o $@ $(ZUTIL_BINDINGS_OBJS) $(LIBS)
Something went wrong with that request. Please try again.