|
root / base / usr / src / tools / env / hammerhead-oibuild.sh
hammerhead-oibuild.sh Bash 350 lines 13.2 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
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright 2012 Joshua M. Clulow <josh@sysmgr.org>
# Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
# Copyright 2015, OmniTI Computer Consulting, Inc. All rights reserved.
# Copyright 2016 RackTop Systems.
# Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
# Copyright 2020 Joyent, Inc.
# Copyright 2024 Bill Sommerfeld <sommerfeld@hamachi.org>
# Copyright 2026 Zygaena Project - Hammerhead Build System
#
# Hammerhead Build Environment for Zygaena (OpenIndiana cross-build host)
#
# For building on an OpenIndiana VM with OI-packaged GCC 14 and tools.
# For building on a native Hammerhead/Zygaena host, use hammerhead.sh instead.
#
# - This file is sourced by "hh-env" (bldenv) and "hh-build" and
#   should not be executed directly.
# - This script is only interpreted by ksh93 and explicitly allows the
#   use of ksh93 language extensions.


# -----------------------------------------------------------------------------
# Parameters you are likely to want to change
# -----------------------------------------------------------------------------

# Hammerhead NIGHTLY_OPTIONS:
#   -F    Do NOT do a non-DEBUG build (DEBUG only)
#   -n    Do not bringover from parent (use local sources)
#   -C    Run 'make check' (cstyle/hdrchk)
#   -D    Do a DEBUG build
#   -A    Check for ABI discrepancies
#   -m    Send mail on completion
#   -r    Check ELF runpaths
#   -t    Build and use workspace tools
#
# Note: -p (package creation) removed - Hammerhead uses Coral packaging
export NIGHTLY_OPTIONS='-FnCDAmrt'

# Some scripts optionally send mail messages to MAILTO.
#export MAILTO=

# CODEMGR_WS - where is your workspace at
# Hammerhead repo structure: git root contains hammerhead/ subdirectory with source
# If CODEMGR_WS not set, detect from git root + /hammerhead
if [[ -z "$CODEMGR_WS" ]]; then
    _gitroot=$(git rev-parse --show-toplevel 2>/dev/null)
    if [[ -d "$_gitroot/base/usr/src" ]]; then
        # Nested structure: repo/hammerhead/usr/src
        export CODEMGR_WS="$_gitroot/base"
    elif [[ -d "$_gitroot/usr/src" ]]; then
        # Flat structure: repo/usr/src
        export CODEMGR_WS="$_gitroot"
    else
        echo "Error: Cannot find usr/src directory" >&2
        return 1
    fi
    unset _gitroot
else
    export CODEMGR_WS
fi

# -----------------------------------------------------------------------------
# Compiler Configuration
# -----------------------------------------------------------------------------
#
# Hammerhead uses GCC 14 exclusively - no shadow compilation
#
# Each entry has the form <name>,<path to binary>,<style> where name is a
# free-form name (possibly used in the makefiles to guard options), path is
# the path to the executable.  style is the 'style' of command line taken by
# the compiler, currently either gnu (or gcc) or sun (or cc).
#
export GNUC_ROOT=/usr/gcc/14
export PRIMARY_CC=gcc14,$GNUC_ROOT/bin/gcc,gnu
export PRIMARY_CCC=gcc14,$GNUC_ROOT/bin/g++,gnu

# OI's patched GCC 14 supports -msave-args for mdb stack debugging.
# Stock upstream GCC does not. Set here so OI builds get this feature.
export SAVEARGS='-msave-args'

# Shadow compilation disabled - single compiler only
export SHADOW_CCS=
export SHADOW_CCCS=

# Smatch disabled (simplifies build)
#export ENABLE_SMATCH=1

# Hammerhead: CUPS not in base OS — SMB printing disabled
# export ENABLE_SMB_PRINTING=

# -----------------------------------------------------------------------------
# Perl/Python Configuration
# -----------------------------------------------------------------------------

# If your distro uses certain versions of Perl, make sure either Makefile.master
# contains your new defaults OR your .env file sets them.
#export PERL_VERSION=5.28
#export PERL_VARIANT=-thread-multi
#export PERL_PKGVERS=

# Hammerhead: 64-bit only - disable 32-bit perl modules
export BUILDPERL32='#'
#export BUILDPERL64='#'

# If your distro uses certain versions of Python, make sure either
# Makefile.master contains your new defaults OR your .env file sets them.
#export PYTHON3_VERSION=3.9
#export PYTHON3_PKGVERS=-39
#export PYTHON3_SUFFIX=

# -----------------------------------------------------------------------------
# Console/Display Configuration
# -----------------------------------------------------------------------------

# Set console color scheme either by build type:
#
#export RELEASE_CONSOLE_COLOR="-DDEFAULT_ANSI_FOREGROUND=ANSI_COLOR_BLACK \
#	-DDEFAULT_ANSI_BACKGROUND=ANSI_COLOR_WHITE"
#
#export DEBUG_CONSOLE_COLOR="-DDEFAULT_ANSI_FOREGROUND=ANSI_COLOR_RED \
#	-DDEFAULT_ANSI_BACKGROUND=ANSI_COLOR_WHITE"
#
# or just one for any build type:
#
#export DEFAULT_CONSOLE_COLOR="-DDEFAULT_ANSI_FOREGROUND=ANSI_COLOR_BLACK \
#	-DDEFAULT_ANSI_BACKGROUND=ANSI_COLOR_WHITE"

# Skip Java 11 builds on distributions that don't support it
#export BLD_JAVA_11=

# POST_NIGHTLY can be any command to be run at the end of the build.
# See hh-build for interactions between environment variables and this command.
#POST_NIGHTLY=

# Populates /etc/versions/build on each build run
export BUILDVERSION_EXEC="git describe --all --long --dirty"

# -----------------------------------------------------------------------------
# Source Control / Bringover Configuration
# -----------------------------------------------------------------------------
#
# When the 'n' option is not present in NIGHTLY_OPTIONS, hh-build updates
# the build workspace from the sources identified by the following variables.
# Defaults are set in hh-build if the environment file leaves them unset.
#

# SCM in use.  Defaults to "git"
#export BRINGOVER_SCM="git"

# URL or pathname to source workspace.
#export BRINGOVER_WS="${CLONE_WS}"

# Branch within BRINGOVER_WS; must be specified if BRINGOVER_WS is a URL
#export BRINGOVER_BRANCH=""

# Short name to use within CODEMGR_WS for BRINGOVER_WS (git-specific)
#export BRINGOVER_REMOTE=nightly_bringover_ws

# Command-line options to add to the clone operation
#export CLONE_OPTIONS=""

# -----------------------------------------------------------------------------
# Build System Configuration
# -----------------------------------------------------------------------------

# Maximum number of parallel make jobs, set to NCPUS.
# GNU Make's job server keeps all CPUs busy without needing extra padding.
function maxjobs
{
	nameref maxjobs=$1
	integer ncpu
	integer -r min_mem_per_job=512 # minimum amount of memory for a job

	ncpu=$(builtin getconf ; getconf 'NPROCESSORS_ONLN')
	(( maxjobs=ncpu ))

	# Throttle number of parallel jobs to a value which guarantees that
	# all jobs have enough memory. This was added to avoid excessive
	# paging/swapping in cases of virtual machine installations which
	# have lots of CPUs but not enough memory assigned.
	if [[ $(/usr/sbin/prtconf 2>'/dev/null') == ~(E)Memory\ size:\ ([[:digit:]]+)\ Megabytes ]] ; then
		integer max_jobs_per_memory # parallel jobs which fit into physical memory
		integer physical_memory # physical memory installed

		# The array ".sh.match" contains the contents of capturing
		# brackets in the last regex, .sh.match[1] will contain
		# the value matched by ([[:digit:]]+), i.e. the amount of
		# memory installed
		physical_memory="10#${.sh.match[1]}"

		((
			max_jobs_per_memory=round(physical_memory/min_mem_per_job) ,
			maxjobs=fmax(2, fmin(maxjobs, max_jobs_per_memory))
		))
	fi

	return 0
}

# Hammerhead: parallelism control for GNU Make builds
# Reduced to -j4 for stability. Full parallelism (-j NCPU) exposes race
# conditions in kernel ctfmerge, _msg preprocessing, and locale data
# generation. Revisit after adding proper ordering constraints.
GMAKE_MAX_JOBS=4
export GMAKE_MAX_JOBS

# path to onbld tool binaries
ONBLD_BIN='/opt/onbld/bin'

# PARENT_WS is used to determine the parent of this workspace. This is
# for the options that deal with the parent workspace (such as where the
# proto area will go).
export PARENT_WS="${PARENT_WS:-}"

# CLONE_WS is the workspace hh-build should do a bringover from.
# The bringover, if any, is done as STAFFER.
export CLONE_WS="${CLONE_WS:-}"

# Set STAFFER to your own login as gatekeeper or developer
# The point is to use group "staff" and avoid referencing the parent
# workspace as root.
export STAFFER="$LOGNAME"
export MAILTO="${MAILTO:-$STAFFER}"

# If you wish the mail messages to be From: an arbitrary address, export
# MAILFROM.
#export MAILFROM="user@example.com"

# The project (see project(5)) under which to run this build.  If not
# specified, the build is simply run in a new task in the current project.
export BUILD_PROJECT=''

# -----------------------------------------------------------------------------
# Architecture Configuration - Hammerhead is amd64-only
# -----------------------------------------------------------------------------
#
# MACH=i386 represents the x86 CPU family (used for Makefile directory selection)
# MACH64=amd64 is the actual 64-bit architecture we build
# BUILD32 is set to $(POUND_SIGN) in Makefile.master to disable 32-bit builds
#
export MACH=i386
export MACH64=amd64

# -----------------------------------------------------------------------------
# Path Configuration
# -----------------------------------------------------------------------------

export ATLOG="$CODEMGR_WS/log"
export LOGFILE="$ATLOG/build.log"

# Proto area - use MACH64 (amd64) since Hammerhead is 64-bit only
export ROOT="$CODEMGR_WS/proto/root_${MACH64}"
export SRC="$CODEMGR_WS/usr/src"
export MULTI_PROTO="no"

# REF_PROTO_LIST - for comparing the list of stuff in your proto area
# with. Generally this should be left alone, since you want to see differences
# from your parent (the gate).
export REF_PROTO_LIST="$PARENT_WS/usr/src/proto_list_${MACH64}"

# Proto area in parent for optionally depositing a copy of headers and
# libraries corresponding to the protolibs target
export PARENT_ROOT="$PARENT_WS/proto/root_${MACH64}"
export PARENT_TOOLS_ROOT="$PARENT_WS/usr/src/tools/proto/root_$MACH-nd"

# -----------------------------------------------------------------------------
# Version Configuration
# -----------------------------------------------------------------------------

# Build version (YYYYMMDD-NN format, auto-generated by hh-build/bldenv).
# NOT exported as VERSION to avoid polluting sub-builds (e.g. zsh autotools).
#export HAMMERHEAD_VERSION="20260301-01"

# The RELEASE and RELEASE_DATE variables are set in Makefile.master;
# there might be special reasons to override them here, but that
# should not be the case in general
# export RELEASE='5.11'
# export RELEASE_DATE='October 2007'

# -----------------------------------------------------------------------------
# Package Configuration (IPS - disabled for Hammerhead)
# -----------------------------------------------------------------------------
#
# Hammerhead uses Coral packaging instead of IPS.
# These variables are kept for compatibility but -p is not in NIGHTLY_OPTIONS.
#
# PKGARCHIVE determines where the repository will be created.
# PKGPUBLISHER_REDIST controls the publisher setting for the repository.
#
export PKGARCHIVE="${CODEMGR_WS}/packages/${MACH64}/build"
# export PKGPUBLISHER_REDIST='on-redist'

# Package manifest format version.
export PKGFMT_OUTPUT='v2'

# -----------------------------------------------------------------------------
# Make Configuration
# -----------------------------------------------------------------------------

# We want make to do as much as it can, just in case there's more than
# one problem.
# We also must set e in MAKEFLAGS as the makefiles depend on importing
# the environment variables set here.
export MAKEFLAGS='ke'

# Hammerhead: Use GNU Make instead of dmake
export MAKE=gmake

# -----------------------------------------------------------------------------
# Build Tools Configuration
# -----------------------------------------------------------------------------

# Build tools - don't change these unless you know what you're doing.  These
# variables allows you to get the compilers and onbld files locally.
# Set BUILD_TOOLS to pull everything from one location.
# Alternately, you can set ONBLD_TOOLS to where you keep the contents of
# SUNWonbld.
export BUILD_TOOLS='/opt'
#export ONBLD_TOOLS='/opt/onbld'

# Set this flag to 'n' to disable the use of 'checkpaths'.  The default,
# if the 'N' option is not specified, is to run this test.
#CHECK_PATHS='y'

# Smatch integration (disabled by default in Hammerhead)
if [[ "$ENABLE_SMATCH" == "1" ]]; then
	SMATCHBIN=$CODEMGR_WS/usr/src/tools/proto/root_$MACH-nd/opt/onbld/bin/$MACH/smatch
	export SHADOW_CCS="$SHADOW_CCS smatch,$SMATCHBIN,smatch"
fi