#!/bin/sh
# Build script for apptest
# A test application that uses libtest

set -e

echo "Building apptest..."

# Create source file
mkdir -p src

cat > src/apptest.c << 'EOF'
#include <stdio.h>
#include <libtest.h>

int main(void) {
    printf("apptest v1.0.0\n");
    printf("Using libtest: %s\n", libtest_version());
    printf("Message: %s\n", libtest_greet());
    printf("\nDependency chain validated successfully!\n");
    return 0;
}
EOF

# Compile - link against libtest
echo "Compiling apptest..."
gcc ${CFLAGS} -I/usr/include -o apptest src/apptest.c -L/usr/lib -ltest

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

echo "Build complete!"
