|
root / base / env.sh
env.sh Bash 112 lines 3.5 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
#!/bin/bash
#
# Hammerhead Build Environment Setup
#
# Source this file before building:
#   cd hammerhead && source env.sh
#
# Required for:
#   - Building tools: gmake bldtools
#   - Building libraries: gmake -C lib
#   - Full build: gmake setup && gmake install
#

# Detect the workspace root (where this script lives)
if [[ -n "$BASH_SOURCE" ]]; then
    CODEMGR_WS="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
else
    CODEMGR_WS="$(pwd)"
fi

# Core workspace paths (required by Makefiles)
export CODEMGR_WS
export SRCTOP="$CODEMGR_WS"
export SRC="$CODEMGR_WS/usr/src"

# Architecture settings - Hammerhead is amd64-only
# MACH = platform (i386 for x86) - this is what Makefiles use for SUBDIRS_$(MACH)
# MACH64 = 64-bit ABI (amd64) - this is what we actually build
# BUILD32='#' below disables 32-bit builds, so we only build $(MACH64)
export MACH=i386
export MACH64=amd64

# Proto area for installed files (non-debug build)
# Use MACH64 for the proto directory since we only build 64-bit
export ROOT="$CODEMGR_WS/proto/root_${MACH64}-nd"

# ADJUNCT_PROTO - used by Makefiles to find headers/libraries from proto area
# This allows libraries that depend on other libraries' headers to find them
export ADJUNCT_PROTO="$ROOT"

# Build tools location
# Use locally built tools if available, otherwise fall back to system /opt/onbld
# Tools proto uses MACH (i386) for directory name, and binaries are also in MACH subdir
TOOLS_PROTO="$SRC/tools/proto/root_${MACH}-nd"
if [[ -d "$TOOLS_PROTO/opt/onbld/bin/$MACH" ]]; then
    export ONBLD_TOOLS="$TOOLS_PROTO/opt/onbld"
    export BUILD_TOOLS="$TOOLS_PROTO/opt"
else
    export BUILD_TOOLS=/opt
    export ONBLD_TOOLS="${BUILD_TOOLS}/onbld"
fi

# Compiler settings - GCC 14
# Auto-detect: OI uses /usr/gcc/14, self-hosted Hammerhead uses /usr
if [[ -x /usr/gcc/14/bin/gcc ]]; then
    export GNUC_ROOT=/usr/gcc/14
else
    export GNUC_ROOT=/usr
fi
export GCC="${GNUC_ROOT}/bin/gcc"
export GXX="${GNUC_ROOT}/bin/g++"
export GCC_ROOT="$GNUC_ROOT"
export PRIMARY_CC=gcc14,$GNUC_ROOT/bin/gcc,gnu
export PRIMARY_CCC=gcc14,$GNUC_ROOT/bin/g++,gnu

# Disable shadow compilation (Hammerhead is GCC-only)
export CW_NO_SHADOW=1
export SHADOW_CCS=
export SHADOW_CCCS=

# Disable smatch (has compatibility issues)
export ENABLE_SMATCH=

# Disable 32-bit builds
export BUILD32='#'

# GNU Make is required (not dmake)
export MAKE=gmake

# Parallel build jobs (adjust to your CPU count)
# NOTE: Do NOT put -j in MAKEFLAGS - it breaks job server coordination
# and causes exponential process spawning. Pass -j on command line instead.
export DMAKE_MAX_JOBS=4
# export MAKEFLAGS="-j4"  # DON'T DO THIS - causes runaway processes

# PATH - ensure GNU tools are available
# Add local onbld tools to PATH if using local build (tools are 64-bit)
if [[ "$BUILD_TOOLS" == "$TOOLS_PROTO/opt" ]]; then
    export PATH="$ONBLD_TOOLS/bin/$MACH64:$GNUC_ROOT/bin:/usr/gnu/bin:$PATH"
else
    export PATH="$GNUC_ROOT/bin:/usr/gnu/bin:$PATH"
fi

# Create proto area
mkdir -p "${ROOT}" 2>/dev/null

echo "Hammerhead build environment set:"
echo "  CODEMGR_WS=$CODEMGR_WS"
echo "  SRCTOP=$SRCTOP"
echo "  SRC=$SRC"
echo "  ROOT=$ROOT"
echo "  ADJUNCT_PROTO=$ADJUNCT_PROTO"
echo "  MACH=$MACH (platform), MACH64=$MACH64 (64-bit only)"
echo "  GCC=$GCC"
echo "  ONBLD_TOOLS=$ONBLD_TOOLS"
echo ""
echo "Build commands:"
echo "  cd \$SRC && gmake -j4 bldtools  # Build tools first"
echo "  cd \$SRC && gmake -j4 setup     # Tools + headers + mapfiles"
echo "  cd \$SRC && gmake -j4 all       # Build everything"
echo "  cd \$SRC && gmake clobber       # Clean (run without -j)"