|
| 1 | +# MIT License |
| 2 | +# |
| 3 | +# Copyright (c) 2026 Advanced Micro Devices, Inc. All rights reserved. |
| 4 | +# |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +# of this software and associated documentation files (the "Software"), to deal |
| 7 | +# in the Software without restriction, including without limitation the rights |
| 8 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +# copies of the Software, and to permit persons to whom the Software is |
| 10 | +# furnished to do so, subject to the following conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be included in all |
| 13 | +# copies or substantial portions of the Software. |
| 14 | +# |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | +# SOFTWARE. |
| 22 | + |
| 23 | +# Dependency checker for rocm-examples Makefile build system |
| 24 | +# |
| 25 | +# Usage in example Makefiles: |
| 26 | +# REQUIRED_DEPS := FFMPEG OPENCV |
| 27 | +# include $(COMMON_INCLUDE_DIR)/require_deps.mk |
| 28 | +# |
| 29 | +# Before including, set COMMON_INCLUDE_DIR (already standard in all examples). |
| 30 | +# |
| 31 | +# This file works in two modes: |
| 32 | +# 1. Fast path: includes config.mk (generated by configure.sh) from the repo root |
| 33 | +# 2. Fallback: uses inline pkg-config checks for standalone builds |
| 34 | +# |
| 35 | +# After including, check SKIP_BUILD. This composes with filter_hip_architectures.mk |
| 36 | +# which also sets SKIP_BUILD. |
| 37 | +# |
| 38 | +# Output variables: |
| 39 | +# SKIP_BUILD - set to 1 if any required dependency is missing |
| 40 | +# MISSING_DEPS - list of missing dependency names |
| 41 | + |
| 42 | +# Locate the repository root relative to COMMON_INCLUDE_DIR |
| 43 | +_REPO_ROOT := $(dir $(COMMON_INCLUDE_DIR)) |
| 44 | + |
| 45 | +# Try to include the pre-generated config.mk (silent if absent) |
| 46 | +-include $(_REPO_ROOT)/config.mk |
| 47 | + |
| 48 | +# If config.mk was not found, run inline fallback detection. |
| 49 | +# We detect this by checking if HAVE_FFMPEG is defined (it's always written by configure.sh). |
| 50 | +ifndef HAVE_FFMPEG |
| 51 | + # Fallback: detect dependencies via pkg-config / file existence |
| 52 | + |
| 53 | + # FFmpeg (pkg-config + link test to catch missing -dev packages) |
| 54 | + _FFMPEG_CHECK := $(shell pkg-config --exists libavcodec libavformat libavutil 2>/dev/null \ |
| 55 | + && echo 'int main(){return 0;}' | $${CC:-cc} -x c - $$(pkg-config --libs libavcodec libavformat libavutil) -o /dev/null 2>/dev/null \ |
| 56 | + && echo 1 || echo 0) |
| 57 | + HAVE_FFMPEG := $(_FFMPEG_CHECK) |
| 58 | + ifeq ($(HAVE_FFMPEG),1) |
| 59 | + FFMPEG_CFLAGS := $(shell pkg-config --cflags libavcodec libavformat libavutil 2>/dev/null) |
| 60 | + FFMPEG_LIBS := $(shell pkg-config --libs libavcodec libavformat libavutil 2>/dev/null || echo "-lavcodec -lavformat -lavutil") |
| 61 | + else |
| 62 | + FFMPEG_CFLAGS := |
| 63 | + FFMPEG_LIBS := |
| 64 | + endif |
| 65 | + |
| 66 | + # OpenCV (pkg-config + link test) |
| 67 | + _OPENCV_CHECK := $(shell (pkg-config --exists opencv4 2>/dev/null && echo 'int main(){return 0;}' | $${CC:-cc} -x c - $$(pkg-config --libs opencv4) -o /dev/null 2>/dev/null && echo 1) \ |
| 68 | + || (pkg-config --exists opencv 2>/dev/null && echo 'int main(){return 0;}' | $${CC:-cc} -x c - $$(pkg-config --libs opencv) -o /dev/null 2>/dev/null && echo 1) \ |
| 69 | + || echo 0) |
| 70 | + HAVE_OPENCV := $(_OPENCV_CHECK) |
| 71 | + ifeq ($(HAVE_OPENCV),1) |
| 72 | + OPENCV_CFLAGS := $(shell pkg-config --cflags opencv4 2>/dev/null || pkg-config --cflags opencv) |
| 73 | + OPENCV_LIBS := $(shell pkg-config --libs opencv4 2>/dev/null || pkg-config --libs opencv) |
| 74 | + else |
| 75 | + OPENCV_CFLAGS := |
| 76 | + OPENCV_LIBS := |
| 77 | + endif |
| 78 | + |
| 79 | + # GLFW3 (pkg-config + link test) |
| 80 | + _GLFW3_CHECK := $(shell pkg-config --exists glfw3 2>/dev/null \ |
| 81 | + && echo 'int main(){return 0;}' | $${CC:-cc} -x c - $$(pkg-config --libs glfw3) -o /dev/null 2>/dev/null \ |
| 82 | + && echo 1 || echo 0) |
| 83 | + HAVE_GLFW3 := $(_GLFW3_CHECK) |
| 84 | + ifeq ($(HAVE_GLFW3),1) |
| 85 | + GLFW3_CFLAGS := $(shell pkg-config --cflags glfw3 2>/dev/null) |
| 86 | + GLFW3_LIBS := $(shell pkg-config --libs glfw3 2>/dev/null) |
| 87 | + else |
| 88 | + GLFW3_CFLAGS := |
| 89 | + GLFW3_LIBS := |
| 90 | + endif |
| 91 | + |
| 92 | + # Vulkan (pkg-config + link test) |
| 93 | + _VULKAN_CHECK := $(shell pkg-config --exists vulkan 2>/dev/null \ |
| 94 | + && echo 'int main(){return 0;}' | $${CC:-cc} -x c - $$(pkg-config --libs vulkan) -o /dev/null 2>/dev/null \ |
| 95 | + && echo 1 || echo 0) |
| 96 | + HAVE_VULKAN := $(_VULKAN_CHECK) |
| 97 | + ifeq ($(HAVE_VULKAN),1) |
| 98 | + VULKAN_CFLAGS := $(shell pkg-config --cflags vulkan 2>/dev/null) |
| 99 | + VULKAN_LIBS := $(shell pkg-config --libs vulkan 2>/dev/null || echo "-lvulkan") |
| 100 | + else |
| 101 | + VULKAN_CFLAGS := |
| 102 | + VULKAN_LIBS := |
| 103 | + endif |
| 104 | + |
| 105 | + # libdw (elfutils) |
| 106 | + _LIBDW_CHECK := $(shell pkg-config --exists libdw 2>/dev/null && echo 1 || echo 0) |
| 107 | + ifeq ($(_LIBDW_CHECK),0) |
| 108 | + _LIBDW_CHECK := $(if $(or $(wildcard /usr/include/elfutils/libdw.h),$(wildcard /usr/include/dwarf.h)),1,0) |
| 109 | + endif |
| 110 | + HAVE_LIBDW := $(_LIBDW_CHECK) |
| 111 | + |
| 112 | + # amd_comgr |
| 113 | + ROCM_PATH ?= /opt/rocm |
| 114 | + _AMD_COMGR_CHECK := $(if $(or $(wildcard $(ROCM_PATH)/include/amd_comgr/amd_comgr.h),$(wildcard $(ROCM_PATH)/lib/libamd_comgr.so)),1,0) |
| 115 | + ifeq ($(_AMD_COMGR_CHECK),0) |
| 116 | + _AMD_COMGR_CHECK := $(shell pkg-config --exists amd_comgr 2>/dev/null && echo 1 || echo 0) |
| 117 | + endif |
| 118 | + HAVE_AMD_COMGR := $(_AMD_COMGR_CHECK) |
| 119 | + |
| 120 | + # glslangValidator |
| 121 | + _GLSLANG_CHECK := $(shell command -v glslangValidator >/dev/null 2>&1 && echo 1 || echo 0) |
| 122 | + HAVE_GLSLANG_VALIDATOR := $(_GLSLANG_CHECK) |
| 123 | + |
| 124 | +endif # ifndef HAVE_FFMPEG |
| 125 | + |
| 126 | +# Check REQUIRED_DEPS against HAVE_<dep> flags |
| 127 | +MISSING_DEPS := |
| 128 | +$(foreach dep,$(REQUIRED_DEPS),\ |
| 129 | + $(if $(filter 1,$(HAVE_$(dep))),,\ |
| 130 | + $(eval MISSING_DEPS += $(dep)))) |
| 131 | + |
| 132 | +ifneq ($(MISSING_DEPS),) |
| 133 | + SKIP_BUILD := 1 |
| 134 | + $(info $(EXAMPLE): Skipping build — missing dependencies: $(MISSING_DEPS)) |
| 135 | +endif |
0 commit comments