This repository was archived by the owner on Feb 8, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·127 lines (103 loc) · 3.82 KB
/
build.sh
File metadata and controls
executable file
·127 lines (103 loc) · 3.82 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
#!/usr/bin/env bash
#
# Copyright 2025 Erdem Ersoy (eersoy93)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -euo pipefail
# Build erdemOS init as a simple Linux userspace program and create initramfs
ROOT_DIR=$(cd "$(dirname "$0")" && pwd)
cd "$ROOT_DIR"
# Configuration
CC=${CC:-gcc}
SRC_DIR=src
OUTPUT_DIR=output
INITRAMFS_DIR="$OUTPUT_DIR/initramfs"
CFLAGS="-Wall -Wextra -O2 -static"
# Outputs
OUTPUT_INIT="$OUTPUT_DIR/init"
OUTPUT_ERSH="$OUTPUT_DIR/ersh"
OUTPUT_POWEROFF="$OUTPUT_DIR/poweroff"
OUTPUT_LOADKEYS="$OUTPUT_DIR/loadkeys"
INITRAMFS_FILE="$OUTPUT_DIR/initramfs.cpio.gz"
# Helper functions
info() { echo "[$(date +%H:%M:%S)] $*"; }
die() { echo "Error: $*" >&2; exit 1; }
require_cmd() { command -v "$1" >/dev/null 2>&1 || die "Required command not found: $1"; }
# Dependency checks
for cmd in "$CC" cpio gzip; do
require_cmd "$cmd"
done
# Create output directory
mkdir -p "$OUTPUT_DIR"
# Generate version.h from VERSION file
info "[1/5] Generating version.h from VERSION file"
VERSION=$(cat VERSION | tr -d '[:space:]')
VERSION_MAJOR=$(echo "$VERSION" | cut -d. -f1)
VERSION_MINOR=$(echo "$VERSION" | cut -d. -f2)
VERSION_PATCH=$(echo "$VERSION" | cut -d. -f3)
cat > include/version.h << EOF
// Copyright 2025 Erdem Ersoy (eersoy93)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef VERSION_H
#define VERSION_H
#define ERDEMOS_VERSION "$VERSION"
#define ERDEMOS_VERSION_MAJOR $VERSION_MAJOR
#define ERDEMOS_VERSION_MINOR $VERSION_MINOR
#define ERDEMOS_VERSION_PATCH $VERSION_PATCH
#endif // VERSION_H
EOF
info "[2/6] Compiling init userspace program (static)"
"$CC" $CFLAGS "$SRC_DIR/init.c" -o "$OUTPUT_INIT"
info "[3/6] Compiling ersh shell (static)"
"$CC" $CFLAGS "$SRC_DIR/ersh.c" -o "$OUTPUT_ERSH"
info "[4/6] Compiling poweroff utility (static)"
"$CC" $CFLAGS "$SRC_DIR/poweroff.c" -o "$OUTPUT_POWEROFF"
info "[5/6] Compiling loadkeys utility (static)"
"$CC" $CFLAGS "$SRC_DIR/loadkeys.c" -o "$OUTPUT_LOADKEYS"
info "[6/6] Creating initramfs with all binaries"
# Clean and create initramfs directory
rm -rf "$INITRAMFS_DIR"
mkdir -p "$INITRAMFS_DIR/bin"
# Copy binaries
cp "$OUTPUT_INIT" "$INITRAMFS_DIR/bin/init"
cp "$OUTPUT_ERSH" "$INITRAMFS_DIR/bin/ersh"
cp "$OUTPUT_POWEROFF" "$INITRAMFS_DIR/bin/poweroff"
cp "$OUTPUT_LOADKEYS" "$INITRAMFS_DIR/bin/loadkeys"
chmod +x "$INITRAMFS_DIR/bin/init"
chmod +x "$INITRAMFS_DIR/bin/ersh"
chmod +x "$INITRAMFS_DIR/bin/poweroff"
chmod +x "$INITRAMFS_DIR/bin/loadkeys"
# Package into initramfs
cd "$INITRAMFS_DIR"
find . | cpio -o -H newc 2>/dev/null | gzip > "$ROOT_DIR/$INITRAMFS_FILE"
cd "$ROOT_DIR"
# Clean up temporary initramfs directory
rm -rf "$INITRAMFS_DIR"
# Final info
info "Build complete:"
info " Init binary: $OUTPUT_INIT"
info " Ersh binary: $OUTPUT_ERSH"
info " Poweroff binary: $OUTPUT_POWEROFF"
info " Loadkeys binary: $OUTPUT_LOADKEYS"
info " Initramfs: $INITRAMFS_FILE"