# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#########################################################################################
##  Build CV-CUDA dependencies on top of manylinux_2_28
##  CV-CUDA is based on "manylinux_2_28", official page https://github.com/pypa/manylinux
#########################################################################################

# Docker buildx sets TARGETARCH automatically for multi-arch builds (amd64, arm64)
# Manylinux images use x86_64 and aarch64 naming
ARG TARGETARCH
ARG MANYLINUX_IMAGE_TAG=latest
ARG BUILDER_EXTRA_DEPS=scratch

FROM ${BUILDER_EXTRA_DEPS:-scratch} AS extra_deps

# Map Docker's TARGETARCH to manylinux arch naming
FROM quay.io/pypa/manylinux_2_28_x86_64:${MANYLINUX_IMAGE_TAG} AS base_amd64
FROM quay.io/pypa/manylinux_2_28_aarch64:${MANYLINUX_IMAGE_TAG} AS base_arm64

# Select the correct base based on TARGETARCH
ARG TARGETARCH
FROM base_${TARGETARCH:-amd64}

# Install yum Dependencies
RUN yum install -y epel-release && \
    yum repolist && \
    yum install -y wget nasm doxygen graphviz gettext xz openssl autogen zip \
                   gcc-toolset-10 gcc-toolset-10-libasan-devel gcc-toolset-10-liblsan-devel \
                   gcc-toolset-10-libtsan-devel gcc-toolset-10-libubsan-devel dpkg

ENV ACLOCAL_PATH=/usr/share/aclocal/:/usr/local/share/aclocal

# Don't want the short-unicode version for Python 2.7
RUN rm -f /opt/python/cp27-cp27m
