|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# SPDX-FileCopyrightText: 2025 Laurent Huberdeau |
| 4 | +# |
| 5 | +# SPDX-License-Identifier: GPL-3.0-or-later |
| 6 | + |
| 7 | +set -ex |
| 8 | + |
| 9 | +# Variables |
| 10 | +M2LIB="../../../M2-Planet/M2libc/" |
| 11 | +PNUT_BRANCH="laurent-small-fixes-for-TCC" |
| 12 | +PNUT_DIR="pnut-${PNUT_BRANCH}" |
| 13 | + |
| 14 | +# Check tarball checksums |
| 15 | +checksum-transcriber sources |
| 16 | +sha256sum -c sources.SHA256SUM |
| 17 | + |
| 18 | +# Unpack |
| 19 | +mkdir build |
| 20 | +cd build |
| 21 | +# ungz --file ${DISTFILES}/${PNUT_PKG}.tar.gz --output ${PNUT_PKG}.tar |
| 22 | +untar --file ${DISTFILES}/${PNUT_PKG}.tar |
| 23 | + |
| 24 | +M2-Planet \ |
| 25 | + --architecture x86 \ |
| 26 | + --debug \ |
| 27 | + --expand-includes \ |
| 28 | + -I ${M2LIB} \ |
| 29 | + --file ${PNUT_DIR}/pnut.c \ |
| 30 | + -D target_i386_linux=1 \ |
| 31 | + -D NO_TERNARY_SUPPORT=1 \ |
| 32 | + -D ONE_PASS_GENERATOR=1 \ |
| 33 | + -D SMALL_HEAP=1 \ |
| 34 | + -o pnut-exe.M1 |
| 35 | + |
| 36 | +# Generate basic DWARF debug info (optional) |
| 37 | +blood-elf \ |
| 38 | + --file pnut-exe.M1 \ |
| 39 | + --little-endian \ |
| 40 | + --entry _start \ |
| 41 | + --output pnut-exe-footer.M1 |
| 42 | + |
| 43 | +# Compile to hex2 (for debug: -f pnut-footer.M1) |
| 44 | +M1 \ |
| 45 | + --file ${M2LIB}/x86/x86_defs.M1 \ |
| 46 | + --file ${M2LIB}/x86/libc-full.M1 \ |
| 47 | + --file pnut-exe.M1 \ |
| 48 | + --file pnut-exe-footer.M1 \ |
| 49 | + --architecture x86 \ |
| 50 | + --little-endian \ |
| 51 | + --output pnut-exe.hex2 |
| 52 | + |
| 53 | +# Assemble |
| 54 | +mkdir -p bin |
| 55 | + |
| 56 | +hex2 \ |
| 57 | + --architecture x86 \ |
| 58 | + --little-endian \ |
| 59 | + --file ${M2LIB}/x86/ELF-x86-debug.hex2 \ |
| 60 | + --file pnut-exe.hex2 \ |
| 61 | + --base-address 0x8048000 \ |
| 62 | + --output bin/pnut-exe |
| 63 | + |
| 64 | +# Recompile pnut with itself, this time |
| 65 | +./bin/pnut-exe \ |
| 66 | + -D target_i386_linux=1 \ |
| 67 | + -D ONE_PASS_GENERATOR=1 \ |
| 68 | + -D BOOTSTRAP_TCC=1 \ |
| 69 | + ${PNUT_DIR}/pnut.c \ |
| 70 | + -o bin/pnut-exe-for-tcc |
| 71 | + |
| 72 | +# Install pnut-exe |
| 73 | +cp bin/pnut-exe-for-tcc ${BINDIR}/pnut |
| 74 | +chmod 755 ${BINDIR}/pnut |
0 commit comments