From 5f1d97598196007ccf2b99efc14c354431040947 Mon Sep 17 00:00:00 2001 From: Christopher Nielsen Date: Wed, 27 Jan 2021 17:32:16 -0500 Subject: [PATCH] opencv3/opencv4: reduce path copy-paste in configure arguments; simplify via cmake portgroup when possible See: https://trac.macports.org/ticket/62011 --- graphics/opencv3/Portfile | 114 +++++++++++++++++------------ graphics/opencv4/Portfile | 150 ++++++++++++++++++++++---------------- 2 files changed, 158 insertions(+), 106 deletions(-) diff --git a/graphics/opencv3/Portfile b/graphics/opencv3/Portfile index 09723038d9254..88380ac85b0b9 100644 --- a/graphics/opencv3/Portfile +++ b/graphics/opencv3/Portfile @@ -59,11 +59,14 @@ platform macosx { # # This is needed to support Python subports, whose names have no relation to # the actual physical file layout. +# +# NOTE: Presently, 'parent_subport_name' matches 'name'. HOWEVER, this will +# change once the various OpenCV-related ports are merged. #------------------------------------------------------------------------------ -set physical_subport_name \ +set parent_subport_name \ ${name} -worksrcdir ${physical_subport_name}-${version} +worksrcdir ${parent_subport_name}-${version} compiler.cxx_standard \ 2011 @@ -115,40 +118,61 @@ post-patch { # -DWITH_NVCUVID=OFF # -DCMAKE_VERBOSE=ON +#------------------------------------------------------------------------------ +# CMake Variables +# +# When/if the CMake portgroup is extended to support more of these options, +# they can be replaced with those equivalents. For now, define them ahead of +# time, for later re-use. +#------------------------------------------------------------------------------ + +# Define all of our base paths up-front +set opencv_install_prefix \ + ${prefix}/libexec/${parent_subport_name} +set opencv_install_cmake \ + ${opencv_install_prefix}/cmake +set opencv_install_include \ + ${prefix}/include/${parent_subport_name} +set opencv_install_lib \ + ${prefix}/lib/${parent_subport_name} + +# Populate the few CMake options currently available +# TODO: Extend CMake portgroup to support more paths +cmake.install_prefix \ + ${opencv_install_prefix} +cmake_share_module_dir \ + ${opencv_install_cmake} +cmake.install_rpath \ + ${opencv_install_lib} + configure.args-append \ - -DCMAKE_RULE_MESSAGES=OFF \ - -DCMAKE_VERBOSE_MAKEFILE=ON \ - \ -DENABLE_CONFIG_VERIFICATION=OFF \ \ - -DCMAKE_INSTALL_PREFIX=${prefix}/libexec/${physical_subport_name} \ - -DOPENCV_CONFIG_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/cmake \ - -DOPENCV_BIN_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/bin \ - -DOPENCV_SETUPVARS_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/scripts \ - -DOPENCV_SBIN_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/sbin \ - -DOPENCV_JAR_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/java/jar \ - -DOPENCV_JNI_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/java/jni \ - -DOPENCV_JNI_BIN_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/java/jni \ - -DOPENCV_TEST_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/test/bin \ - -DOPENCV_TEST_DATA_PATH=${prefix}/libexec/${physical_subport_name}/test/data \ - -DOPENCV_SAMPLES_BIN_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/share/samples/bin \ - -DOPENCV_SAMPLES_SRC_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/share/samples/src \ - -DOPENCV_OTHER_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/share/data \ - -DOPENCV_DOC_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/share/doc \ - -DOPENCV_LICENSES_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/share/license \ - -DOPENCV_INCLUDE_INSTALL_PATH=${prefix}/include/${physical_subport_name} \ - -DOPENCV_LIB_INSTALL_PATH=${prefix}/lib/${physical_subport_name} \ - -DOPENCV_3P_LIB_INSTALL_PATH=${prefix}/lib/${physical_subport_name}/3rdparty \ - -DOPENCV_LIB_ARCHIVE_INSTALL_PATH=${prefix}/lib/${physical_subport_name}/static \ - -DCMAKE_BINARY_DIR=${prefix}/libexec/${physical_subport_name}/bin \ - -DCMAKE_INSTALL_LIBEXECDIR=${prefix}/libexec/${physical_subport_name} \ - -DCMAKE_INSTALL_BINDIR=${prefix}/libexec/${physical_subport_name}/bin \ - -DCMAKE_INSTALL_SBINDIR=${prefix}/libexec/${physical_subport_name}/sbin \ - -DCMAKE_INSTALL_SHAREDIR=${prefix}/libexec/${physical_subport_name}/share \ - -DCMAKE_INSTALL_INCLUDEDIR=${prefix}/include/${physical_subport_name} \ - -DCMAKE_INSTALL_LIBDIR=${prefix}/lib/${physical_subport_name} \ - -DCMAKE_INSTALL_NAME_DIR=${prefix}/lib/${physical_subport_name} \ - -DCMAKE_INSTALL_RPATH=${prefix}/lib/${physical_subport_name} \ + -DOPENCV_CONFIG_INSTALL_PATH=${opencv_install_cmake} \ + -DOPENCV_BIN_INSTALL_PATH=${opencv_install_prefix}/bin \ + -DOPENCV_SETUPVARS_INSTALL_PATH=${opencv_install_prefix}/scripts \ + -DOPENCV_SBIN_INSTALL_PATH=${opencv_install_prefix}/sbin \ + -DOPENCV_JAR_INSTALL_PATH=${opencv_install_prefix}/java/jar \ + -DOPENCV_JNI_INSTALL_PATH=${opencv_install_prefix}/java/jni \ + -DOPENCV_JNI_BIN_INSTALL_PATH=${opencv_install_prefix}/java/jni \ + -DOPENCV_TEST_INSTALL_PATH=${opencv_install_prefix}/test/bin \ + -DOPENCV_TEST_DATA_PATH=${opencv_install_prefix}/test/data \ + -DOPENCV_SAMPLES_BIN_INSTALL_PATH=${opencv_install_prefix}/share/samples/bin \ + -DOPENCV_SAMPLES_SRC_INSTALL_PATH=${opencv_install_prefix}/share/samples/src \ + -DOPENCV_OTHER_INSTALL_PATH=${opencv_install_prefix}/share/data \ + -DOPENCV_DOC_INSTALL_PATH=${opencv_install_prefix}/share/doc \ + -DOPENCV_LICENSES_INSTALL_PATH=${opencv_install_prefix}/share/license \ + -DOPENCV_INCLUDE_INSTALL_PATH=${opencv_install_include} \ + -DOPENCV_LIB_INSTALL_PATH=${opencv_install_lib} \ + -DOPENCV_3P_LIB_INSTALL_PATH=${opencv_install_lib}/3rdparty \ + -DOPENCV_LIB_ARCHIVE_INSTALL_PATH=${opencv_install_lib}/static \ + -DCMAKE_INSTALL_LIBEXECDIR=${opencv_install_prefix} \ + -DCMAKE_INSTALL_BINDIR=${opencv_install_prefix}/bin \ + -DCMAKE_INSTALL_SBINDIR=${opencv_install_prefix}/sbin \ + -DCMAKE_INSTALL_SHAREDIR=${opencv_install_prefix}/share \ + -DCMAKE_INSTALL_INCLUDEDIR=${opencv_install_include} \ + -DCMAKE_INSTALL_LIBDIR=${opencv_install_lib} \ + -DCMAKE_INSTALL_NAME_DIR=${opencv_install_lib} \ \ -DWITH_1394=OFF \ -DWITH_CARBON=OFF \ @@ -300,9 +324,9 @@ if {[variant_isset universal]} { foreach python_branch {2.7} { set python_version [join [lrange [split ${python_branch} .] 0 1] ""] - subport py${python_version}-${physical_subport_name} { + subport py${python_version}-${parent_subport_name} { depends_lib-append \ - port:${physical_subport_name} \ + port:${parent_subport_name} \ port:python${python_version} \ port:py${python_version}-numpy configure.args-replace \ @@ -324,7 +348,7 @@ foreach python_branch {2.7} { # Deconflict with parent port contents post-destroot { ui_debug "${subport}: python subport: removing files unrelated to Python bindings" - foreach f [exec port contents ${physical_subport_name}] { + foreach f [exec port contents ${parent_subport_name}] { delete ${destroot}${f} } } @@ -334,9 +358,9 @@ foreach python_branch {2.7} { set python_branches {3.5 3.6 3.7 3.8 3.9} foreach python_branch ${python_branches} { set python_version [join [lrange [split ${python_branch} .] 0 1] ""] - subport py${python_version}-${physical_subport_name} { + subport py${python_version}-${parent_subport_name} { depends_lib-append \ - port:${physical_subport_name} \ + port:${parent_subport_name} \ port:python${python_version} \ port:py${python_version}-numpy configure.args-replace \ @@ -354,7 +378,7 @@ foreach python_branch ${python_branches} { # Deconflict with parent port contents post-destroot { ui_debug "${subport}: python subport: removing files unrelated to Python bindings" - foreach f [exec port contents ${physical_subport_name}] { + foreach f [exec port contents ${parent_subport_name}] { delete ${destroot}${f} } } @@ -684,20 +708,20 @@ proc opencv_soft_link_binaries {p_bin_main_dir p_bin_port_dir p_destroot p_prefi proc opencv_post_destroot {} { global prefix global destroot - global physical_subport_name + global parent_subport_name # http://trac.macports.org/ticket/42702 if {[variant_isset qt4] || [variant_isset qt5]} { reinplace "s|-L//System/Library/Frameworks ||g" \ - ${destroot}${prefix}/lib/${physical_subport_name}/pkgconfig/opencv.pc + ${destroot}${prefix}/lib/${parent_subport_name}/pkgconfig/opencv.pc reinplace "s|-lOpenGL.framework|-framework OpenGL|g" \ - ${destroot}${prefix}/lib/${physical_subport_name}/pkgconfig/opencv.pc + ${destroot}${prefix}/lib/${parent_subport_name}/pkgconfig/opencv.pc } set bin_main_dir \ "${destroot}${prefix}/bin" set bin_port_dir \ - "${destroot}${prefix}/libexec/${physical_subport_name}/bin" + "${destroot}${prefix}/libexec/${parent_subport_name}/bin" # While the various configure-related options should catch everything, one or more # files may be missed. If so, ensure they're moved to the subport's bin area. @@ -705,13 +729,13 @@ proc opencv_post_destroot {} { ${bin_main_dir} \ ${bin_port_dir} - # Create soft links for binaries, each prefixed with '_'. + # Create soft links for binaries, each prefixed with '_'. opencv_soft_link_binaries \ ${bin_main_dir} \ ${bin_port_dir} \ ${destroot} \ ${prefix} \ - ${physical_subport_name} + ${parent_subport_name} } post-destroot { diff --git a/graphics/opencv4/Portfile b/graphics/opencv4/Portfile index 2fabd6b42aeb6..3fe107eea1d42 100644 --- a/graphics/opencv4/Portfile +++ b/graphics/opencv4/Portfile @@ -44,35 +44,17 @@ checksums ${distname}${extract.suffix} \ # # This is needed to support Python subports, whose names have no relation to # the actual physical file layout. +# +# NOTE: Presently, 'parent_subport_name' matches 'name'. HOWEVER, this will +# change once the various OpenCV-related ports are merged. #------------------------------------------------------------------------------ -set physical_subport_name \ +set parent_subport_name \ ${name} # recognize dylib as a valid library suffix patchfiles-append patch-dylib_suffix.diff -#worksrcdir ${physical_subport_name}-${version} - -# modify from _resources/port1.0/group/github-1.0.tcl to avoid file tag issue -proc move_gh_repo {repo_dir_patt new_name} { - global distfiles workpath worksrcpath - if {(![file exists ${worksrcpath}] || ![file exists ${workpath}/${new_name}]) && \ - [llength ${distfiles}] > 0 && \ - [llength [glob -nocomplain ${workpath}/*]] > 0} { - if {[file exists [glob -nocomplain ${workpath}/${repo_dir_patt}]] && \ - [file isdirectory [glob -nocomplain ${workpath}/${repo_dir_patt}]]} { - move [glob ${workpath}/${repo_dir_patt}] ${workpath}/${new_name} - } else { - # tarball is not "${repo_dir_patt}" - ui_error "\n\ngithub PortGroup: Error: \${worksrcpath} does not exist after extracting distfiles. This might indicate that the author or project is different than set in the Portfile due to a rename at GitHub. Please examine the extracted directory in ${workpath} and try to correct the Portfile by either changing the author or project or adding the worksrcdir option with the correct directory name.\n" - return -code error "Unexpected github tarball extract." - } - } -} - -post-extract { - move_gh_repo ${github.author}-${github.project}-* ${distname} -} +#worksrcdir ${parent_subport_name}-${version} compiler.cxx_standard \ 2011 @@ -98,40 +80,61 @@ depends_lib-append \ port:ilmbase \ port:ade +#------------------------------------------------------------------------------ +# CMake Variables +# +# When/if the CMake portgroup is extended to support more of these options, +# they can be replaced with those equivalents. For now, define them ahead of +# time, for use by configure arguments. +#------------------------------------------------------------------------------ + +# Define all of our base paths up-front +set opencv_install_prefix \ + ${prefix}/libexec/${parent_subport_name} +set opencv_install_cmake \ + ${opencv_install_prefix}/cmake +set opencv_install_include \ + ${prefix}/include/${parent_subport_name} +set opencv_install_lib \ + ${prefix}/lib/${parent_subport_name} + +# Populate the few CMake options currently available +# TODO: Extend CMake portgroup to support more paths +cmake.install_prefix \ + ${opencv_install_prefix} +cmake_share_module_dir \ + ${opencv_install_cmake} +cmake.install_rpath \ + ${opencv_install_lib} + configure.args-append \ - -DCMAKE_RULE_MESSAGES:BOOL=OFF \ - -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \ - \ -DENABLE_CONFIG_VERIFICATION:BOOL=OFF \ \ - -DCMAKE_INSTALL_PREFIX=${prefix}/libexec/${physical_subport_name} \ - -DOPENCV_CONFIG_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/cmake \ - -DOPENCV_BIN_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/bin \ - -DOPENCV_SETUPVARS_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/scripts \ - -DOPENCV_SBIN_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/sbin \ - -DOPENCV_JAR_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/java/jar \ - -DOPENCV_JNI_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/java/jni \ - -DOPENCV_JNI_BIN_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/java/jni \ - -DOPENCV_TEST_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/test/bin \ - -DOPENCV_TEST_DATA_PATH=${prefix}/libexec/${physical_subport_name}/test/data \ - -DOPENCV_SAMPLES_BIN_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/share/samples/bin \ - -DOPENCV_SAMPLES_SRC_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/share/samples/src \ - -DOPENCV_OTHER_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/share/data \ - -DOPENCV_DOC_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/share/doc \ - -DOPENCV_LICENSES_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/share/license \ - -DOPENCV_INCLUDE_INSTALL_PATH=${prefix}/include/${physical_subport_name} \ - -DOPENCV_LIB_INSTALL_PATH=${prefix}/lib/${physical_subport_name} \ - -DOPENCV_3P_LIB_INSTALL_PATH=${prefix}/lib/${physical_subport_name}/3rdparty \ - -DOPENCV_LIB_ARCHIVE_INSTALL_PATH=${prefix}/lib/${physical_subport_name}/static \ - -DCMAKE_BINARY_DIR=${prefix}/libexec/${physical_subport_name}/bin \ - -DCMAKE_INSTALL_LIBEXECDIR=${prefix}/libexec/${physical_subport_name} \ - -DCMAKE_INSTALL_BINDIR=${prefix}/libexec/${physical_subport_name}/bin \ - -DCMAKE_INSTALL_SBINDIR=${prefix}/libexec/${physical_subport_name}/sbin \ - -DCMAKE_INSTALL_SHAREDIR=${prefix}/libexec/${physical_subport_name}/share \ - -DCMAKE_INSTALL_INCLUDEDIR=${prefix}/include/${physical_subport_name} \ - -DCMAKE_INSTALL_LIBDIR=${prefix}/lib/${physical_subport_name} \ - -DCMAKE_INSTALL_NAME_DIR=${prefix}/lib/${physical_subport_name} \ - -DCMAKE_INSTALL_RPATH=${prefix}/lib/${physical_subport_name} \ + -DOPENCV_CONFIG_INSTALL_PATH=${opencv_install_cmake} \ + -DOPENCV_BIN_INSTALL_PATH=${opencv_install_prefix}/bin \ + -DOPENCV_SETUPVARS_INSTALL_PATH=${opencv_install_prefix}/scripts \ + -DOPENCV_SBIN_INSTALL_PATH=${opencv_install_prefix}/sbin \ + -DOPENCV_JAR_INSTALL_PATH=${opencv_install_prefix}/java/jar \ + -DOPENCV_JNI_INSTALL_PATH=${opencv_install_prefix}/java/jni \ + -DOPENCV_JNI_BIN_INSTALL_PATH=${opencv_install_prefix}/java/jni \ + -DOPENCV_TEST_INSTALL_PATH=${opencv_install_prefix}/test/bin \ + -DOPENCV_TEST_DATA_PATH=${opencv_install_prefix}/test/data \ + -DOPENCV_SAMPLES_BIN_INSTALL_PATH=${opencv_install_prefix}/share/samples/bin \ + -DOPENCV_SAMPLES_SRC_INSTALL_PATH=${opencv_install_prefix}/share/samples/src \ + -DOPENCV_OTHER_INSTALL_PATH=${opencv_install_prefix}/share/data \ + -DOPENCV_DOC_INSTALL_PATH=${opencv_install_prefix}/share/doc \ + -DOPENCV_LICENSES_INSTALL_PATH=${opencv_install_prefix}/share/license \ + -DOPENCV_INCLUDE_INSTALL_PATH=${opencv_install_include} \ + -DOPENCV_LIB_INSTALL_PATH=${opencv_install_lib} \ + -DOPENCV_3P_LIB_INSTALL_PATH=${opencv_install_lib}/3rdparty \ + -DOPENCV_LIB_ARCHIVE_INSTALL_PATH=${opencv_install_lib}/static \ + -DCMAKE_INSTALL_LIBEXECDIR=${opencv_install_prefix} \ + -DCMAKE_INSTALL_BINDIR=${opencv_install_prefix}/bin \ + -DCMAKE_INSTALL_SBINDIR=${opencv_install_prefix}/sbin \ + -DCMAKE_INSTALL_SHAREDIR=${opencv_install_prefix}/share \ + -DCMAKE_INSTALL_INCLUDEDIR=${opencv_install_include} \ + -DCMAKE_INSTALL_LIBDIR=${opencv_install_lib} \ + -DCMAKE_INSTALL_NAME_DIR=${opencv_install_lib} \ \ -DWITH_ADE:BOOL=ON \ -Dade_DIR:PATH=${prefix}/share/ade/ \ @@ -273,9 +276,9 @@ platform darwin { set python_branches {3.5 3.6 3.7 3.8 3.9} foreach python_branch ${python_branches} { set python_version [join [lrange [split ${python_branch} .] 0 1] ""] - subport py${python_version}-${physical_subport_name} { + subport py${python_version}-${parent_subport_name} { depends_lib-append \ - port:${physical_subport_name} \ + port:${parent_subport_name} \ port:python${python_version} \ port:py${python_version}-numpy configure.args-replace \ @@ -296,7 +299,7 @@ foreach python_branch ${python_branches} { # Deconflict with parent port contents post-destroot { ui_debug "${subport}: python subport: removing files unrelated to Python bindings" - foreach f [exec port contents ${physical_subport_name}] { + foreach f [exec port contents ${parent_subport_name}] { delete ${destroot}${f} } } @@ -518,12 +521,12 @@ proc opencv_soft_link_binaries {p_bin_main_dir p_bin_port_dir p_destroot p_prefi proc opencv_post_destroot {} { global prefix global destroot - global physical_subport_name + global parent_subport_name set bin_main_dir \ "${destroot}${prefix}/bin" set bin_port_dir \ - "${destroot}${prefix}/libexec/${physical_subport_name}/bin" + "${destroot}${prefix}/libexec/${parent_subport_name}/bin" # While the various configure-related options should catch everything, one or more # files may be missed. If so, ensure they're moved to the opencv4 bin area. @@ -531,13 +534,38 @@ proc opencv_post_destroot {} { ${bin_main_dir} \ ${bin_port_dir} - # Create soft links for binaries, each prefixed with '_'. + # Create soft links for binaries, each prefixed with '_'. opencv_soft_link_binaries \ ${bin_main_dir} \ ${bin_port_dir} \ ${destroot} \ ${prefix} \ - ${physical_subport_name} + ${parent_subport_name} +} + +# modify from _resources/port1.0/group/github-1.0.tcl to avoid file tag issue +proc move_gh_repo {repo_dir_patt new_name} { + global distfiles workpath worksrcpath + if {(![file exists ${worksrcpath}] || ![file exists ${workpath}/${new_name}]) && \ + [llength ${distfiles}] > 0 && \ + [llength [glob -nocomplain ${workpath}/*]] > 0} { + if {[file exists [glob -nocomplain ${workpath}/${repo_dir_patt}]] && \ + [file isdirectory [glob -nocomplain ${workpath}/${repo_dir_patt}]]} { + move [glob ${workpath}/${repo_dir_patt}] ${workpath}/${new_name} + } else { + # tarball is not "${repo_dir_patt}" + ui_error "\n\nGitHub Extract Error: \${worksrcpath} does not exist after extracting\ + distfiles. This might indicate that the author or project is different than set\ + in the Portfile due to a rename at GitHub. Please examine the extracted directory\ + in ${workpath} and try to correct the Portfile by either changing the author or\ + project or adding the worksrcdir option with the correct directory name.\n" + return -code error "Unexpected github tarball extract." + } + } +} + +post-extract { + move_gh_repo ${github.author}-${github.project}-* ${distname} } post-destroot {