C Utils for Yzena
https://docs.yzena.com/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
347 lines
6.5 KiB
347 lines
6.5 KiB
#! /bin/sh |
|
# |
|
# ***** BEGIN LICENSE BLOCK ***** |
|
# |
|
# Copyright 2017-2022 Yzena Tech |
|
# |
|
# Licensed under the Yzena Viral User License, Version 0.1 (the "Yzena Viral |
|
# User License" or "YVUL"), the GNU Affero General Public License (the "GNU |
|
# AGPL"), Version 3.0, and the Server Side Public License (the "SSPL"), |
|
# Version 1. You may not use this file except in compliance with all of those |
|
# licenses. |
|
# |
|
# You may obtain a copy of the Yzena Viral User License at |
|
# |
|
# https://yzena.com/yzena-viral-user-license/ |
|
# |
|
# Unless required by applicable law or agreed to in writing, software |
|
# distributed under the Yzena Viral User License is distributed under the |
|
# following disclaimer: |
|
# |
|
# As far as the law allows, this software comes as is, without any |
|
# warranty or condition, and no contributor will be liable to anyone for |
|
# any damages related to this software or this license, under any kind of |
|
# legal claim. |
|
# |
|
# You may obtain a copy of the GNU Affero General Public License at |
|
# |
|
# https://www.gnu.org/licenses/agpl-3.0.html |
|
# |
|
# Unless required by applicable law or agreed to in writing, software |
|
# distributed under the GNU Affero General Public License is distributed under |
|
# the following disclaimer: |
|
# |
|
# This software is distributed in the hope that it will be useful, but |
|
# WITHOUT ANY WARRANTY; without even the implied warranty of |
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero |
|
# General Public License for more details. |
|
# |
|
# You may obtain a copy of the Server Side Public License at |
|
# |
|
# https://www.mongodb.com/licensing/server-side-public-license |
|
# |
|
# Unless required by applicable law or agreed to in writing, software |
|
# distributed under the Server Side Public License is distributed under the |
|
# following disclaimer: |
|
# |
|
# This software is distributed in the hope that it will be useful, but |
|
# WITHOUT ANY WARRANTY; without even the implied warranty of |
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Server |
|
# Side Public License for more details. |
|
# |
|
# ****** END LICENSE BLOCK ****** |
|
# |
|
|
|
set -e |
|
|
|
scriptdir=$(dirname "$0") |
|
|
|
cd "$scriptdir" |
|
|
|
mkdir -p bootstrap/ |
|
|
|
rm -rf bootstrap/* |
|
|
|
stage0="bootstrap/stage0" |
|
stage1="bootstrap/stage1" |
|
stage2="bootstrap/stage2" |
|
|
|
mkdir "$stage0" |
|
mkdir "$stage1" |
|
mkdir "$stage2" |
|
|
|
if [ -z "$CC" ]; then |
|
CC="clang" |
|
fi |
|
|
|
# This is in case we run with valgrind. |
|
vg="valgrind --error-exitcode=100 --leak-check=full --show-leak-kinds=all" |
|
vg="$vg --errors-for-leak-kinds=all --num-callers=500 --child-silent-after-fork=yes" |
|
|
|
integrity=0 |
|
slam=0 |
|
st=0 |
|
valgrind=0 |
|
|
|
plat=$(uname -s) |
|
|
|
if [ "$plat" = "Darwin" ]; then |
|
|
|
darwin="1" |
|
|
|
CPPFLAGS="-D_BSD_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_DARWIN_C_SOURCE" |
|
CPPFLAGS="$CPPFLAGS -fsanitize=address -mmacosx-version-min=10.12" |
|
|
|
ncores=$(sysctl -n hw.ncpu) |
|
use_make=1 |
|
|
|
else |
|
|
|
darwin="0" |
|
CPPFLAGS="-D_BSD_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_DARWIN_C_SOURCE" |
|
|
|
if [ "$plat" = "Linux" ]; then |
|
ncores=$(getconf _NPROCESSORS_ONLN) |
|
use_make=1 |
|
CPPFLAGS="$CPPFLAGS -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 " |
|
elif [ "$plat" = "FreeBSD" ] || [ "$plat" = "OpenBSD" ] || \ |
|
[ "$plat" = "NetBSD" ]; then |
|
ncores=$(sysctl -n hw.ncpu) |
|
use_make=1 |
|
CPPFLAGS="$CPPFLAGS -DYC_NO_POSIX_SPAWN -fsanitize=address" |
|
else |
|
ncores=1 |
|
use_make=0 |
|
fi |
|
|
|
fi |
|
|
|
# Process command-line arguments. |
|
while getopts "irsv" opt; do |
|
|
|
case "$opt" in |
|
i) integrity=1 ; shift ;; |
|
r) slam=1 ; shift ;; |
|
s) st=1 ; shift ;; |
|
v) valgrind=1 ; shift ;; |
|
?) usage "Invalid option: $opt" ;; |
|
esac |
|
|
|
done |
|
|
|
files=$(find src -name "*.c" | sort) |
|
|
|
objs="" |
|
|
|
printf '.POSIX:\n\nall: rig\n\n' > Makefile |
|
|
|
if [ "$use_make" -ne 0 ]; then |
|
|
|
printf 'Building stage0...' |
|
|
|
for f in $files; do |
|
|
|
if [ "${f#*windows}" != "$f" ]; then |
|
continue |
|
fi |
|
|
|
if [ "${f#*/yao/python/}" != "$f" ]; then |
|
continue |
|
fi |
|
|
|
if [ "${f#*/time/}" != "$f" ]; then |
|
continue |
|
fi |
|
|
|
if [ "${f#*/stdio.c}" != "$f" ]; then |
|
continue |
|
fi |
|
|
|
if [ "${f#*/container/ntree.c}" != "$f" ]; then |
|
continue |
|
fi |
|
|
|
if [ "$darwin" -ne 0 ]; then |
|
|
|
if [ "${f#*/concurrency/os/posix/semaphore.c}" != "$f" ]; then |
|
continue |
|
fi |
|
|
|
else |
|
|
|
if [ "${f#*darwin}" != "$f" ]; then |
|
continue |
|
fi |
|
|
|
fi |
|
|
|
base=$(basename "$f" ".c") |
|
dir=$(dirname "$f") |
|
|
|
obj="$stage0/${dir}/${base}.o" |
|
|
|
dirobj=$(dirname "$obj") |
|
|
|
printf '%s:\n\t@mkdir -p "%s"\n\t@"%s" %s %s "-Iinclude/" -c -o "%s" "%s"\n' \ |
|
"$obj" "$dirobj" "$CC" "$CFLAGS" "$CPPFLAGS" "$obj" "$f" >> Makefile |
|
|
|
objs="$objs $obj" |
|
|
|
done |
|
|
|
printf 'rig: %s\n\t@"%s" %s %s -o %s %s -lpthread\n' "$objs" "$CC" \ |
|
"$CFLAGS" "$CPPFLAGS" "$stage0/rig" "$objs" >> Makefile |
|
|
|
make -j$ncores |
|
|
|
printf '\n' |
|
|
|
else |
|
|
|
for f in $files; do |
|
|
|
if [ "${f#*windows}" != "$f" ]; then |
|
continue |
|
fi |
|
|
|
if [ "${f#*/yao/python/}" != "$f" ]; then |
|
continue |
|
fi |
|
|
|
if [ "${f#*/time/}" != "$f" ]; then |
|
continue |
|
fi |
|
|
|
if [ "${f#*/stdio.c}" != "$f" ]; then |
|
continue |
|
fi |
|
|
|
if [ "${f#*/container/ntree.c}" != "$f" ]; then |
|
continue |
|
fi |
|
|
|
if [ "$darwin" -ne 0 ]; then |
|
|
|
if [ "${f#*/concurrency/os/posix/semaphore.c}" != "$f" ]; then |
|
continue |
|
fi |
|
|
|
else |
|
|
|
if [ "${f#*darwin}" != "$f" ]; then |
|
continue |
|
fi |
|
|
|
fi |
|
|
|
base=$(basename "$f" ".c") |
|
dir=$(dirname "$f") |
|
|
|
obj="$stage0/${dir}/${base}.o" |
|
|
|
mkdir -p $(dirname "$obj") |
|
|
|
printf 'Building stage0 %s...' "$f" |
|
|
|
"$CC" $CFLAGS $CPPFLAGS "-Iinclude/" -c -o "$obj" "$f" |
|
|
|
objs="$objs $obj" |
|
|
|
printf '\n' |
|
|
|
done |
|
|
|
printf 'Building stage0 rig...' |
|
|
|
"$CC" $CLAGS $CPPFLAGS -o "$stage0/rig" $objs -lpthread |
|
|
|
fi |
|
|
|
cd "$stage0" |
|
|
|
ln -sf ./rig rigc |
|
|
|
printf '\n' |
|
|
|
cd ../stage1 |
|
|
|
printf 'Configuring stage1...' |
|
|
|
if [ "$valgrind" -ne 0 ]; then |
|
$vg ../stage0/rigc ../../ |
|
else |
|
../stage0/rigc ../../ |
|
fi |
|
|
|
printf '\nBuilding stage1...\n\n' |
|
|
|
if [ "$valgrind" -ne 0 ]; then |
|
$vg ../stage0/rig |
|
else |
|
../stage0/rig |
|
fi |
|
|
|
cd ../stage2 |
|
|
|
printf '\nConfiguring stage2...' |
|
|
|
if [ "$valgrind" -ne 0 ]; then |
|
$vg ../stage1/rigc ../../ |
|
err=$? |
|
else |
|
../stage1/rigc ../../ |
|
err=$? |
|
fi |
|
|
|
if [ "$err" -ne 0 ]; then |
|
exit "$err" |
|
fi |
|
|
|
if [ "$slam" -ne 0 ]; then |
|
|
|
if [ "$valgrind" -ne 0 ]; then |
|
|
|
if [ "$st" -ne 0 ]; then |
|
../../tools/rig_slam.sh -v -s ../stage0/rig |
|
else |
|
../../tools/rig_slam.sh -v ../stage0/rig |
|
fi |
|
|
|
elif [ "$st" -ne 0 ]; then |
|
../../tools/rig_slam.sh -s ../stage0/rig |
|
else |
|
../../tools/rig_slam.sh ../stage0/rig |
|
fi |
|
|
|
else |
|
|
|
printf '\nBuilding stage2...\n\n' |
|
|
|
if [ "$valgrind" -ne 0 ]; then |
|
$vg ../stage1/rig |
|
err=$? |
|
else |
|
../stage1/rig |
|
err=$? |
|
fi |
|
|
|
if [ "$err" -ne 0 ]; then |
|
exit "$err" |
|
fi |
|
|
|
if [ "$integrity" -ne 0 ]; then |
|
|
|
printf '\nChecking bootstrap for integrity...\n' |
|
|
|
diff ../stage1/rig ./rig |
|
err=$? |
|
|
|
if [ "$err" -ne 0 ]; then |
|
exit "$err" |
|
fi |
|
|
|
fi |
|
|
|
fi |
|
|
|
printf 'Done!\n'
|
|
|