Automatic base directory detection