#!/bin/bash

if [ ! -f "log.wmake" ]
then
    echo "wmake > log.wmake"
    wmake $@ >log.wmake 2>&1
fi

# Find the Python executable in the system
PYTHON_EXEC=$(which python3)

# Check if python3 is found
if [ -z "$PYTHON_EXEC" ]; then
    echo "python3 not found"
    exit 1
fi

# Get the Python version
PYTHON_VERSION=$($PYTHON_EXEC -c 'import sys; print(".".join(map(str, sys.version_info[:3])))')

# Split the version number
IFS='.' read -r -a version_parts <<< "$PYTHON_VERSION"

# Compare major and minor versions
if [ "${version_parts[0]}" -gt 3 ] || { [ "${version_parts[0]}" -eq 3 ] && [ "${version_parts[1]}" -ge 6 ]; }; then
    script_dir=$(cd "$(dirname "$0")" && pwd)
    $PYTHON_EXEC $script_dir/wmakelog2cmakelists.py
else
    echo "Python version must be greater than 3.6, current version is: $PYTHON_VERSION"
    exit 1
fi