cleanup
This commit is contained in:
parent
9f96626ea7
commit
6a02b24ae6
29 changed files with 653 additions and 583 deletions
254
pxl8.sh
254
pxl8.sh
|
|
@ -39,21 +39,21 @@ if [[ "$(uname)" == "Linux" ]]; then
|
|||
CFLAGS="$CFLAGS -D_GNU_SOURCE"
|
||||
fi
|
||||
|
||||
print_info() {
|
||||
echo -e "${BLUE}${BOLD}info:${NC} $1"
|
||||
}
|
||||
compile_source_file() {
|
||||
local src_file="$1"
|
||||
local obj_file="$2"
|
||||
local compile_flags="$3"
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}${BOLD}✓${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}${BOLD}error:${NC} $1" >&2
|
||||
print_info "Compiling: $src_file"
|
||||
if ! $CC -c $compile_flags "$src_file" -o "$obj_file"; then
|
||||
print_error "Compilation failed for $src_file"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
detect_simd() {
|
||||
local simd_flags=""
|
||||
|
||||
|
||||
case "$(uname -m)" in
|
||||
x86_64|amd64)
|
||||
if $CC -mavx2 -c -x c /dev/null -o /dev/null 2>/dev/null; then
|
||||
|
|
@ -68,10 +68,26 @@ detect_simd() {
|
|||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
echo "$simd_flags"
|
||||
}
|
||||
|
||||
make_lib_dirs() {
|
||||
mkdir -p lib/linenoise lib/fennel lib/microui/src lib/miniz
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}${BOLD}error:${NC} $1" >&2
|
||||
}
|
||||
|
||||
print_info() {
|
||||
echo -e "${BLUE}${BOLD}info:${NC} $1"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}${BOLD}✓${NC} $1"
|
||||
}
|
||||
|
||||
print_usage() {
|
||||
echo -e "${BOLD}pxl8${NC} - framework build tool"
|
||||
echo
|
||||
|
|
@ -80,15 +96,18 @@ print_usage() {
|
|||
echo
|
||||
echo -e "${BOLD}COMMANDS:${NC}"
|
||||
echo " build Build pxl8"
|
||||
echo " run Build and run pxl8 [script.fnl|script.lua]"
|
||||
echo " clean Remove build artifacts"
|
||||
echo " run Build and run pxl8 (optional: cart.pxc or folder)"
|
||||
echo
|
||||
echo " update Download/update all dependencies"
|
||||
echo " vendor Fetch source for dependencies (ex. sdl3)"
|
||||
echo " vendor Fetch source for dependencies (ex. SDL3)"
|
||||
echo
|
||||
echo " help Show this help message"
|
||||
echo
|
||||
echo -e "${BOLD}OPTIONS:${NC}"
|
||||
echo " --all Remove all artifacts including dependencies when cleaning"
|
||||
echo " --release Build/run in release mode"
|
||||
echo " --all Clean both build artifacts and dependencies"
|
||||
echo " --deps Clean only dependencies"
|
||||
echo " --release Build/run/clean in release mode (default: debug)"
|
||||
}
|
||||
|
||||
COMMAND="$1"
|
||||
|
|
@ -115,6 +134,34 @@ else
|
|||
BINDIR="$BINDIR/debug"
|
||||
fi
|
||||
|
||||
build_luajit() {
|
||||
if [[ ! -f "lib/luajit/src/libluajit.a" ]]; then
|
||||
print_info "Building LuaJIT"
|
||||
cd lib/luajit
|
||||
|
||||
if [[ "$(uname)" == "Darwin" ]]; then
|
||||
export MACOSX_DEPLOYMENT_TARGET="10.11"
|
||||
fi
|
||||
|
||||
make clean >/dev/null 2>&1 || true
|
||||
make -j$(nproc 2>/dev/null || echo 4) > /dev/null 2>&1
|
||||
cd - > /dev/null
|
||||
print_success "Built LuaJIT"
|
||||
fi
|
||||
}
|
||||
|
||||
build_sdl() {
|
||||
if [[ ! -f "lib/SDL/build/libSDL3.so" ]] && [[ ! -f "lib/SDL/build/libSDL3.a" ]] && [[ ! -f "lib/SDL/build/libSDL3.dylib" ]]; then
|
||||
print_info "Building SDL3"
|
||||
mkdir -p lib/SDL/build
|
||||
cd lib/SDL/build
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Release > /dev/null 2>&1
|
||||
cmake --build . --parallel $(nproc 2>/dev/null || echo 4) > /dev/null 2>&1
|
||||
cd - > /dev/null
|
||||
print_success "Built SDL3"
|
||||
fi
|
||||
}
|
||||
|
||||
setup_sdl3() {
|
||||
if [[ -d "lib/SDL/build" ]]; then
|
||||
SDL3_CFLAGS="-Ilib/SDL/include"
|
||||
|
|
@ -125,49 +172,52 @@ setup_sdl3() {
|
|||
SDL3_CFLAGS=$(pkg-config --cflags sdl3 2>/dev/null || echo "")
|
||||
SDL3_LIBS=$(pkg-config --libs sdl3 2>/dev/null || echo "")
|
||||
SDL3_RPATH=""
|
||||
|
||||
|
||||
if [[ -z "$SDL3_LIBS" ]]; then
|
||||
case "$(uname)" in
|
||||
Darwin)
|
||||
SDL3_CFLAGS="-I/usr/local/include/SDL3"
|
||||
SDL3_LIBS="-L/usr/local/lib -lSDL3"
|
||||
if [[ -f "/usr/local/include/SDL3/SDL.h" ]]; then
|
||||
SDL3_CFLAGS="-I/usr/local/include/SDL3"
|
||||
SDL3_LIBS="-L/usr/local/lib -lSDL3"
|
||||
fi
|
||||
;;
|
||||
Linux)
|
||||
SDL3_CFLAGS="-I/usr/include/SDL3"
|
||||
SDL3_LIBS="-lSDL3"
|
||||
if [[ -f "/usr/include/SDL3/SDL.h" ]]; then
|
||||
SDL3_CFLAGS="-I/usr/include/SDL3"
|
||||
SDL3_LIBS="-lSDL3"
|
||||
fi
|
||||
;;
|
||||
MINGW*|MSYS*|CYGWIN*)
|
||||
SDL3_CFLAGS="-I/mingw64/include/SDL3"
|
||||
SDL3_LIBS="-lSDL3"
|
||||
if [[ -f "/mingw64/include/SDL3/SDL.h" ]]; then
|
||||
SDL3_CFLAGS="-I/mingw64/include/SDL3"
|
||||
SDL3_LIBS="-lSDL3"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
print_info "Using system SDL3"
|
||||
|
||||
if [[ -z "$SDL3_LIBS" ]]; then
|
||||
print_info "System SDL3 not found, vendoring SDL3..."
|
||||
update_sdl
|
||||
build_sdl
|
||||
SDL3_CFLAGS="-Ilib/SDL/include"
|
||||
SDL3_LIBS="-Llib/SDL/build -lSDL3"
|
||||
SDL3_RPATH="-Wl,-rpath,$(pwd)/lib/SDL/build"
|
||||
print_info "Using vendored SDL3"
|
||||
else
|
||||
print_info "Using system SDL3"
|
||||
fi
|
||||
fi
|
||||
|
||||
CFLAGS="$CFLAGS $SDL3_CFLAGS"
|
||||
LIBS="$LIBS $SDL3_LIBS $SDL3_RPATH"
|
||||
}
|
||||
|
||||
update_linenoise() {
|
||||
print_info "Fetching linenoise"
|
||||
mkdir -p lib/linenoise
|
||||
|
||||
if curl -s --max-time 5 -o lib/linenoise/linenoise.c https://raw.githubusercontent.com/antirez/linenoise/master/linenoise.c 2>/dev/null && \
|
||||
curl -s --max-time 5 -o lib/linenoise/linenoise.h https://raw.githubusercontent.com/antirez/linenoise/master/linenoise.h 2>/dev/null; then
|
||||
print_success "Updated linenoise"
|
||||
else
|
||||
print_error "Failed to download linenoise"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
update_fennel() {
|
||||
print_info "Fetching Fennel"
|
||||
mkdir -p lib/fennel
|
||||
|
||||
|
||||
local version="1.5.3"
|
||||
|
||||
|
||||
if curl -s --max-time 5 -o lib/fennel/fennel.lua "https://fennel-lang.org/downloads/fennel-${version}.lua" 2>/dev/null; then
|
||||
if [[ -f "lib/fennel/fennel.lua" ]] && [[ -s "lib/fennel/fennel.lua" ]]; then
|
||||
print_success "Updated Fennel (${version})"
|
||||
|
|
@ -181,6 +231,18 @@ update_fennel() {
|
|||
fi
|
||||
}
|
||||
|
||||
update_linenoise() {
|
||||
print_info "Fetching linenoise"
|
||||
|
||||
if curl -s --max-time 5 -o lib/linenoise/linenoise.c https://raw.githubusercontent.com/antirez/linenoise/master/linenoise.c 2>/dev/null && \
|
||||
curl -s --max-time 5 -o lib/linenoise/linenoise.h https://raw.githubusercontent.com/antirez/linenoise/master/linenoise.h 2>/dev/null; then
|
||||
print_success "Updated linenoise"
|
||||
else
|
||||
print_error "Failed to download linenoise"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
update_luajit() {
|
||||
print_info "Fetching LuaJIT"
|
||||
|
||||
|
|
@ -198,25 +260,8 @@ update_luajit() {
|
|||
print_success "Updated LuaJIT (${version})"
|
||||
}
|
||||
|
||||
build_luajit() {
|
||||
if [[ ! -f "lib/luajit/src/libluajit.a" ]]; then
|
||||
print_info "Building LuaJIT"
|
||||
cd lib/luajit
|
||||
|
||||
if [[ "$(uname)" == "Darwin" ]]; then
|
||||
export MACOSX_DEPLOYMENT_TARGET="10.11"
|
||||
fi
|
||||
|
||||
make clean >/dev/null 2>&1 || true
|
||||
make -j$(nproc 2>/dev/null || echo 4) > /dev/null 2>&1
|
||||
cd - > /dev/null
|
||||
print_success "Built LuaJIT"
|
||||
fi
|
||||
}
|
||||
|
||||
update_microui() {
|
||||
print_info "Fetching microui"
|
||||
mkdir -p lib/microui/src
|
||||
|
||||
if curl -s --max-time 5 -o lib/microui/src/microui.c https://raw.githubusercontent.com/rxi/microui/master/src/microui.c 2>/dev/null && \
|
||||
curl -s --max-time 5 -o lib/microui/src/microui.h https://raw.githubusercontent.com/rxi/microui/master/src/microui.h 2>/dev/null; then
|
||||
|
|
@ -229,11 +274,10 @@ update_microui() {
|
|||
|
||||
update_miniz() {
|
||||
print_info "Fetching miniz"
|
||||
mkdir -p lib/miniz
|
||||
|
||||
local version="3.0.2"
|
||||
|
||||
if curl -sL --max-time 10 -o /tmp/miniz.zip "https://github.com/richgel999/miniz/releases/download/${version}/miniz-${version}.zip" 2>/dev/null; then
|
||||
if curl -sL --max-time 5 -o /tmp/miniz.zip "https://github.com/richgel999/miniz/releases/download/${version}/miniz-${version}.zip" 2>/dev/null; then
|
||||
unzip -qjo /tmp/miniz.zip miniz.c miniz.h -d lib/miniz/ 2>/dev/null
|
||||
rm -f /tmp/miniz.zip
|
||||
|
||||
|
|
@ -249,7 +293,7 @@ update_miniz() {
|
|||
fi
|
||||
}
|
||||
|
||||
vendor_sdl() {
|
||||
update_sdl() {
|
||||
print_info "Fetching SDL3"
|
||||
|
||||
if [[ -d "lib/SDL/.git" ]]; then
|
||||
|
|
@ -263,18 +307,6 @@ vendor_sdl() {
|
|||
print_success "Updated SDL3"
|
||||
}
|
||||
|
||||
build_sdl() {
|
||||
if [[ ! -f "lib/SDL/build/libSDL3.so" ]] && [[ ! -f "lib/SDL/build/libSDL3.a" ]] && [[ ! -f "lib/SDL/build/libSDL3.dylib" ]]; then
|
||||
print_info "Building SDL3"
|
||||
mkdir -p lib/SDL/build
|
||||
cd lib/SDL/build
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Release > /dev/null 2>&1
|
||||
cmake --build . --parallel $(nproc 2>/dev/null || echo 4) > /dev/null 2>&1
|
||||
cd - > /dev/null
|
||||
print_success "Built SDL3"
|
||||
fi
|
||||
}
|
||||
|
||||
case "$COMMAND" in
|
||||
build)
|
||||
mkdir -p "$BUILDDIR"
|
||||
|
|
@ -286,9 +318,10 @@ case "$COMMAND" in
|
|||
[[ ! -f "lib/miniz/miniz.c" ]] || \
|
||||
[[ ! -f "lib/fennel/fennel.lua" ]]; then
|
||||
print_info "Missing dependencies, fetching..."
|
||||
|
||||
update_linenoise
|
||||
|
||||
make_lib_dirs
|
||||
update_fennel
|
||||
update_linenoise
|
||||
update_luajit
|
||||
update_microui
|
||||
update_miniz
|
||||
|
|
@ -341,7 +374,7 @@ case "$COMMAND" in
|
|||
|
||||
LIB_SOURCE_FILES="lib/linenoise/linenoise.c lib/miniz/miniz.c"
|
||||
|
||||
SRC_SOURCE_FILES="
|
||||
PXL8_SOURCE_FILES="
|
||||
src/pxl8.c
|
||||
src/pxl8_ase.c
|
||||
src/pxl8_blit.c
|
||||
|
|
@ -367,32 +400,24 @@ case "$COMMAND" in
|
|||
obj_name=$(basename "$src_file" .c).o
|
||||
obj_file="$OBJECT_DIR/$obj_name"
|
||||
OBJECTS="$OBJECTS $obj_file"
|
||||
|
||||
|
||||
if [[ "$src_file" -nt "$obj_file" ]]; then
|
||||
NEED_LINK=true
|
||||
print_info "Compiling: $src_file"
|
||||
if ! $CC -c $COMPILE_FLAGS "$src_file" -o "$obj_file"; then
|
||||
print_error "Compilation failed for $src_file"
|
||||
exit 1
|
||||
fi
|
||||
compile_source_file "$src_file" "$obj_file" "$COMPILE_FLAGS"
|
||||
SOURCES_COMPILED="yes"
|
||||
fi
|
||||
done
|
||||
|
||||
for src_file in $SRC_SOURCE_FILES; do
|
||||
for src_file in $PXL8_SOURCE_FILES; do
|
||||
obj_name=$(basename "$src_file" .c).o
|
||||
obj_file="$OBJECT_DIR/$obj_name"
|
||||
OBJECTS="$OBJECTS $obj_file"
|
||||
|
||||
|
||||
if [[ "$src_file" -nt "$obj_file" ]] || \
|
||||
[[ "src/pxl8_types.h" -nt "$obj_file" ]] || \
|
||||
[[ "src/pxl8_macros.h" -nt "$obj_file" ]]; then
|
||||
NEED_LINK=true
|
||||
print_info "Compiling: $src_file"
|
||||
if ! $CC -c $COMPILE_FLAGS "$src_file" -o "$obj_file"; then
|
||||
print_error "Compilation failed for $src_file"
|
||||
exit 1
|
||||
fi
|
||||
compile_source_file "$src_file" "$obj_file" "$COMPILE_FLAGS"
|
||||
SOURCES_COMPILED="yes"
|
||||
fi
|
||||
done
|
||||
|
|
@ -413,31 +438,58 @@ case "$COMMAND" in
|
|||
|
||||
run)
|
||||
"$0" build "$@" || exit 1
|
||||
|
||||
SCRIPT=""
|
||||
|
||||
CART=""
|
||||
for arg in "$@"; do
|
||||
if [[ "$arg" != "--release" ]]; then
|
||||
SCRIPT="$arg"
|
||||
CART="$arg"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ -z "$SCRIPT" ]]; then
|
||||
SCRIPT="src/fnl/demo.fnl"
|
||||
|
||||
if [[ -z "$CART" ]]; then
|
||||
"$BINDIR/pxl8"
|
||||
else
|
||||
"$BINDIR/pxl8" "$CART"
|
||||
fi
|
||||
|
||||
"$BINDIR/pxl8" "$SCRIPT"
|
||||
;;
|
||||
|
||||
clean)
|
||||
if [[ "$1" == "--all" ]] || [[ "$1" == "--deps" ]]; then
|
||||
print_info "Removing all build artifacts and dependencies"
|
||||
rm -rf "$BUILDDIR" "$BINDIR" lib
|
||||
CLEAN_ALL=false
|
||||
CLEAN_DEPS=false
|
||||
CLEAN_RELEASE=false
|
||||
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--all) CLEAN_ALL=true ;;
|
||||
--deps) CLEAN_DEPS=true ;;
|
||||
--release) CLEAN_RELEASE=true ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ "$CLEAN_RELEASE" == true ]]; then
|
||||
BUILD_PATH=".build/release"
|
||||
BIN_PATH="bin/release"
|
||||
MODE="release"
|
||||
else
|
||||
BUILD_PATH=".build/debug"
|
||||
BIN_PATH="bin/debug"
|
||||
MODE="debug"
|
||||
fi
|
||||
|
||||
if [[ "$CLEAN_ALL" == true ]]; then
|
||||
print_info "Removing build artifacts and dependencies"
|
||||
rm -rf "$BUILD_PATH" "$BIN_PATH" lib
|
||||
print_success "Cleaned all"
|
||||
elif [[ "$CLEAN_DEPS" == true ]]; then
|
||||
print_info "Removing dependencies"
|
||||
rm -rf lib
|
||||
print_success "Cleaned dependencies"
|
||||
else
|
||||
print_info "Removing build artifacts"
|
||||
rm -rf "$BUILDDIR" "$BINDIR"
|
||||
rm -rf "$BUILD_PATH" "$BIN_PATH"
|
||||
print_success "Cleaned"
|
||||
fi
|
||||
print_success "Cleaned"
|
||||
;;
|
||||
|
||||
update)
|
||||
|
|
@ -450,7 +502,7 @@ case "$COMMAND" in
|
|||
;;
|
||||
|
||||
vendor)
|
||||
vendor_sdl
|
||||
update_sdl
|
||||
;;
|
||||
|
||||
help|--help|-h|"")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue