#!/bin/sh
# Build script for hello package
# This is a test package that creates a simple hello world program

set -e

echo "Building hello world test package..."

# Create source directory
mkdir -p src

# Create simple hello.c
cat > src/hello.c << 'EOF'
#include <stdio.h>

int main(void) {
    printf("Hello from Coral package manager!\n");
    printf("If you see this, the build system is working.\n");
    return 0;
}
EOF

# Compile
echo "Compiling hello.c..."
gcc ${CFLAGS} -o hello src/hello.c

# Install to DESTDIR
echo "Installing to ${DESTDIR}..."
mkdir -p "${DESTDIR}/usr/bin"
install -m 755 hello "${DESTDIR}/usr/bin/hello"

# Create a simple man page
mkdir -p "${DESTDIR}/usr/share/man/man1"
cat > "${DESTDIR}/usr/share/man/man1/hello.1" << 'EOF'
.TH HELLO 1 "2025" "Coral" "User Commands"
.SH NAME
hello \- a test program for coral package manager
.SH SYNOPSIS
.B hello
.SH DESCRIPTION
A simple hello world program used to test the Coral package build system.
.SH AUTHOR
Chris Tusa <chris.tusa@leafscale.com>
EOF

echo "Build complete!"
