!69 Make spec file support both system-version and multi-version

From: @cf-zhao 
Reviewed-by: @eastb233 
Signed-off-by: @eastb233
This commit is contained in:
openeuler-ci-bot 2023-07-12 01:41:19 +00:00 committed by Gitee
commit 298e35c791
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 268 additions and 140 deletions

21
README.en.md Normal file
View File

@ -0,0 +1,21 @@
# The LLVM Compiler Infrastructure
#### Description
The LLVM Core libraries provide a modern source- and target-independent optimizer, along with code generation support for many popular CPUs (as well as some less common ones!) These libraries are built around a well specified code representation known as the LLVM intermediate representation ("LLVM IR").
#### Contribution
1. Fork the repository
2. Create Feat_xxx branch
3. Commit your code
4. Create Pull Request
#### Gitee Feature
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
4. The most valuable open source project [GVP](https://gitee.com/gvp)
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)

21
README.md Normal file
View File

@ -0,0 +1,21 @@
# The LLVM Compiler Infrastructure
#### 介绍
The LLVM Core libraries provide a modern source- and target-independent optimizer, along with code generation support for many popular CPUs (as well as some less common ones!) These libraries are built around a well specified code representation known as the LLVM intermediate representation ("LLVM IR").
#### 参与贡献
1. Fork 本仓库
2. 新建 Feat_xxx 分支
3. 提交代码
4. 新建 Pull Request
#### 特技
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)

358
llvm.spec
View File

@ -1,25 +1,96 @@
%bcond_with check
%bcond_with sys_llvm
%bcond_without check
Name: llvm
Version: 12.0.1
Release: 5
%global maj_ver 12
%global min_ver 0
%global patch_ver 1
%if %{with sys_llvm}
%global pkg_name llvm
%global install_prefix %{_prefix}
%else
%global pkg_name llvm%{maj_ver}
%global install_prefix %{_libdir}/%{name}
%endif
%global install_bindir %{install_prefix}/bin
%global install_includedir %{install_prefix}/include
%if 0%{?__isa_bits} == 64
%global install_libdir %{install_prefix}/lib64
%else
%global install_libdir %{install_prefix}/lib
%endif
%global install_srcdir %{install_prefix}/src
%global install_docdir %{install_prefix}/share/doc
%global max_link_jobs %{_smp_build_ncpus}
%global targets_to_build "all"
%global experimental_targets_to_build ""
%global build_install_prefix %{buildroot}%{install_prefix}
%global llvm_triple %{_host}
# Disable LTO as this causes crash if gcc lto enabled.
%define _lto_cflags %{nil}
Name: %{pkg_name}
Version: %{maj_ver}.%{min_ver}.%{patch_ver}
Release: 6
Summary: The Low Level Virtual Machine
License: NCSA
URL: http://llvm.org
Source0: https://github.com/llvm/llvm-project/releases/download/llvmorg-%{version}/%{name}-%{version}.src.tar.xz
Source0: https://github.com/llvm/llvm-project/releases/download/llvmorg-%{version}/llvm-%{version}.src.tar.xz
BuildRequires: gcc gcc-c++ cmake ninja-build zlib-devel libffi-devel ncurses-devel libstdc++-static
BuildRequires: python3-sphinx binutils-devel valgrind-devel libedit-devel python3-devel
BuildRequires: binutils-devel
BuildRequires: cmake
BuildRequires: gcc
BuildRequires: gcc-c++
BuildRequires: libedit-devel
BuildRequires: libffi-devel
BuildRequires: multilib-rpm-config
BuildRequires: ncurses-devel
BuildRequires: ninja-build
BuildRequires: python3-devel
BuildRequires: python3-psutil
BuildRequires: python3-recommonmark
BuildRequires: python3-sphinx
BuildRequires: python3-setuptools
BuildRequires: zlib-devel
Requires: %{name}-libs%{?_isa} = %{version}-%{release}
Provides: llvm(major) = %{maj_ver}
%description
LLVM is a compiler infrastructure designed for compile-time, link-time,
runtime, and idle-time optimization of programs from arbitrary programming
languages.
languages. The compiler infrastructure includes mirror sets of programming
tools as well as libraries with equivalent functionality.
The LLVM compiler infrastructure supports a wide range of projects,
from industrial strength compilers to specialized JIT applications
to small research projects.
%package devel
Summary: Libraries and header files for LLVM
Requires: %{name}%{?_isa} = %{version}-%{release}
Requires: %{name}-libs%{?_isa} = %{version}-%{release}
Requires: libedit-devel
Requires: %{name}-static%{?_isa} = %{version}-%{release}
Requires(post): %{_sbindir}/alternatives
Requires(postun): %{_sbindir}/alternatives
Provides: llvm-devel(major) = %{maj_ver}
%description devel
This package contains library and header files needed to develop new native
programs that use the LLVM infrastructure.
%package doc
Summary: Documentation for LLVM
BuildArch: noarch
Requires: %{name} = %{version}-%{release}
%description doc
Documentation for the LLVM compiler infrastructure.
%package libs
Summary: LLVM shared libraries
@ -27,98 +98,85 @@ Summary:LLVM shared libraries
%description libs
Shared libraries for the LLVM compiler infrastructure.
%package devel
Summary: Development files for %{name}
Requires: %{name} = %{version}-%{release}
Requires: libedit-devel python3-lit binutils gcc
Requires(post): %{_sbindir}/alternatives
Requires(postun):%{_sbindir}/alternatives
Provides: %{name}-static = %{version}-%{release}
Obsoletes: %{name}-static < %{version}-%{release}
Provides: %{name}-googletest = %{version}-%{release}
Obsoletes: %{name}-googletest < %{version}-%{release}
Provides: %{name}-test = %{version}-%{release}
Obsoletes: %{name}-test < %{version}-%{release}
%package static
Summary: LLVM static libraries
Conflicts: %{name}-devel < 8
%description devel
The %{name}-devel package contains libraries and header files for
developing applications that use %{name}.
Provides: llvm-static(major) = %{maj_ver}
%package help
Summary: Doc files for %{name}
Buildarch: noarch
Requires: man
Provides: %{name}-doc = %{version}-%{release}
Obsoletes: %{name}-doc < %{version}-%{release}
%description static
Static libraries for the LLVM compiler infrastructure.
%description help
The %{name}-help package contains doc files for %{name}.
%package test
Summary: LLVM regression tests
Requires: %{name}%{?_isa} = %{version}-%{release}
Requires: %{name}-libs%{?_isa} = %{version}-%{release}
Provides: llvm-test(major) = %{maj_ver}
%description test
LLVM regression tests.
%package googletest
Summary: LLVM's modified googletest sources
%description googletest
LLVM's modified googletest sources.
%prep
%autosetup -n %{name}-%{version}.src -p1
pathfix.py -i %{__python3} -pn test/BugPoint/compile-custom.ll.py tools/opt-viewer/*.py
%setup -T -q -b 0 -n llvm-%{version}.src
pathfix.py -i %{__python3} -pn \
test/BugPoint/compile-custom.ll.py \
tools/opt-viewer/*.py \
utils/update_cc_test_checks.py
%build
#TODO: -DLLVM_TARGETS_TO_BUILD=all in needed(temporarily) when build rust,
# clarification is required in the future
mkdir -p _build
cd _build
%global optflags %(echo %{optflags} | sed 's/-g /-g1 /')
%cmake .. -G Ninja \
-DBUILD_SHARED_LIBS:BOOL=OFF \
-DLLVM_PARALLEL_LINK_JOBS=1 \
-DLLVM_PARALLEL_LINK_JOBS=%{max_link_jobs} \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_SKIP_RPATH:BOOL=ON \
-DCMAKE_C_FLAGS_RELWITHDEBINFO="%{optflags} -DNDEBUG -fPIE -fPIC" \
-DCMAKE_CXX_FLAGS_RELWITHDEBINFO="%{optflags} -DNDEBUG -fPIE -fPIC" \
-DCMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO="%{optflags} -pie" \
-DLLVM_TARGETS_TO_BUILD=%{targets_to_build} \
-DLLVM_ENABLE_LIBCXX:BOOL=OFF \
-DLLVM_ENABLE_ZLIB:BOOL=ON \
-DLLVM_ENABLE_FFI:BOOL=ON \
-DLLVM_ENABLE_RTTI:BOOL=ON \
-DLLVM_USE_PERF:BOOL=ON \
-DLLVM_BINUTILS_INCDIR=%{_includedir} \
-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=%{experimental_targets_to_build} \
-DLLVM_BUILD_RUNTIME:BOOL=ON \
-DLLVM_INCLUDE_TOOLS:BOOL=ON \
-DLLVM_BUILD_TOOLS:BOOL=ON \
-DLLVM_INCLUDE_TESTS:BOOL=ON \
-DLLVM_BUILD_TESTS:BOOL=ON \
-DLLVM_LIT_ARGS=-v \
-DLLVM_INCLUDE_EXAMPLES:BOOL=ON \
-DLLVM_BUILD_EXAMPLES:BOOL=OFF \
-DLLVM_INCLUDE_UTILS:BOOL=ON \
-DLLVM_INSTALL_UTILS:BOOL=ON \
-DLLVM_INCLUDE_DOCS:BOOL=ON \
-DLLVM_BUILD_DOCS:BOOL=ON \
-DLLVM_ENABLE_SPHINX:BOOL=ON \
-DLLVM_ENABLE_DOXYGEN:BOOL=OFF \
-DLLVM_BUILD_LLVM_DYLIB:BOOL=ON \
-DLLVM_LINK_LLVM_DYLIB:BOOL=ON \
-DLLVM_BUILD_EXTERNAL_COMPILER_RT:BOOL=ON \
-DLLVM_INSTALL_TOOLCHAIN_ONLY:BOOL=OFF \
-DLLVM_DEFAULT_TARGET_TRIPLE=%{llvm_triple} \
-DSPHINX_WARNINGS_AS_ERRORS=OFF \
-DCMAKE_INSTALL_PREFIX=%{install_prefix} \
-DLLVM_INSTALL_SPHINX_HTML_DIR=%{install_docdir}/html \
-DSPHINX_EXECUTABLE=%{_bindir}/sphinx-build-3 \
%if 0%{?__isa_bits} == 64
-DLLVM_LIBDIR_SUFFIX=64 \
%else
-DLLVM_LIBDIR_SUFFIX= \
%endif
%if 0
%ifarch %ix86 x86_64
-DLLVM_TARGETS_TO_BUILD="X86;AMDGPU;NVPTX;BPF;ARM;AArch64" \
%endif
%ifarch aarch64
-DLLVM_TARGETS_TO_BUILD="AArch64;AMDGPU;BPF" \
%endif
%ifarch %{arm}
-DLLVM_TARGETS_TO_BUILD="ARM;AMDGPU;BPF" \
%endif
%endif
-DLLVM_TARGETS_TO_BUILD=all \
-DLLVM_ENABLE_LIBCXX:BOOL=OFF \
-DLLVM_ENABLE_ZLIB:BOOL=ON \
-DLLVM_ENABLE_FFI:BOOL=ON \
-DLLVM_ENABLE_RTTI:BOOL=ON \
-DLLVM_BINUTILS_INCDIR=%{_includedir} \
-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=AVR \
-DLLVM_BUILD_RUNTIME:BOOL=ON \
-DLLVM_INCLUDE_TOOLS:BOOL=ON \
-DLLVM_BUILD_TOOLS:BOOL=ON \
-DLLVM_INCLUDE_TESTS:BOOL=ON \
-DLLVM_BUILD_TESTS:BOOL=OFF \
-DLLVM_INCLUDE_EXAMPLES:BOOL=ON \
-DLLVM_BUILD_EXAMPLES:BOOL=OFF \
-DLLVM_INCLUDE_UTILS:BOOL=ON \
-DLLVM_INSTALL_UTILS:BOOL=ON \
-DLLVM_UTILS_INSTALL_DIR:PATH=%{_bindir} \
-DLLVM_TOOLS_INSTALL_DIR:PATH=bin \
-DLLVM_INCLUDE_DOCS:BOOL=ON \
-DLLVM_BUILD_DOCS:BOOL=ON \
-DLLVM_ENABLE_SPHINX:BOOL=ON \
-DLLVM_ENABLE_DOXYGEN:BOOL=OFF \
-DLLVM_VERSION_SUFFIX='' \
-DLLVM_BUILD_LLVM_DYLIB:BOOL=ON \
-DLLVM_DYLIB_EXPORT_ALL:BOOL=ON \
-DLLVM_LINK_LLVM_DYLIB:BOOL=ON \
-DLLVM_BUILD_EXTERNAL_COMPILER_RT:BOOL=ON \
-DLLVM_INSTALL_TOOLCHAIN_ONLY:BOOL=OFF \
-DSPHINX_WARNINGS_AS_ERRORS=OFF \
-DLLVM_INSTALL_SPHINX_HTML_DIR=%{_pkgdocdir}/html \
-DSPHINX_EXECUTABLE=%{_bindir}/sphinx-build-3
-DLLVM_INCLUDE_BENCHMARKS=OFF
%ninja_build LLVM
%ninja_build
@ -126,81 +184,109 @@ cd _build
%install
%ninja_install -C _build
find %{buildroot}%{_libdir}/cmake/llvm -type f | xargs sed -i "s|%{buildroot}||g"
mv -v %{buildroot}%{_bindir}/llvm-config{,-%{__isa_bits}}
mkdir -p %{buildroot}/%{_bindir}
for f in llvm-isel-fuzzer llvm-opt-fuzzer; do
install -m 0755 ./_build/bin/$f %{buildroot}%{_bindir}
# Install binaries needed for lit tests
for f in llvm-isel-fuzzer llvm-opt-fuzzer
do
install -m 0755 %{_builddir}/llvm-%{version}.src/_build/bin/$f %{buildroot}%{install_bindir}
done
%global install_srcdir %{buildroot}%{_datadir}/llvm/src
%global lit_cfg test/lit.site.cfg.py
%global lit_unit_cfg test/Unit/lit.site.cfg.py
%if 0%{?__isa_bits} == 64
install %{_builddir}/llvm-%{version}.src/_build/lib64/libLLVMTestingSupport.a %{buildroot}%{install_libdir}
%else
install %{_builddir}/llvm-%{version}.src/_build/lib/libLLVMTestingSupport.a %{buildroot}%{install_libdir}
%endif
install -d %{install_srcdir}
install -d %{install_srcdir}/utils/
cp -R utils/unittest %{install_srcdir}/utils/
# Install gtest sources so clang can use them for gtest
install -d %{buildroot}%{install_srcdir}
install -d %{buildroot}%{install_srcdir}/utils/
cp -R %{_builddir}/llvm-%{version}.src/utils/unittest %{buildroot}%{install_srcdir}/utils/
cat _build/test/lit.site.cfg.py >> %{lit_cfg}
cat _build/test/Unit/lit.site.cfg.py >> %{lit_unit_cfg}
sed -i -e s~`pwd`/_build~%{_prefix}~g -e s~`pwd`~.~g %{lit_cfg} %{lit_cfg} %{lit_unit_cfg}
# Clang needs these for running lit tests.
cp %{_builddir}/llvm-%{version}.src/utils/update_cc_test_checks.py %{buildroot}%{install_srcdir}/utils/
cp -R %{_builddir}/llvm-%{version}.src/utils/UpdateTestChecks %{buildroot}%{install_srcdir}/utils/
sed -i 's~\(config.llvm_obj_root = \)"[^"]\+"~\1"%{_libdir}/%{name}"~' %{lit_unit_cfg}
# Move header files
mkdir -p %{buildroot}/%{install_includedir}
ln -s ../../../%{install_includedir}/llvm %{buildroot}/%{install_includedir}/llvm
ln -s ../../../%{install_includedir}/llvm-c %{buildroot}/%{install_includedir}/llvm-c
install -d %{buildroot}%{_libexecdir}/tests/llvm
# Fix multi-lib
%multilib_fix_c_header --file %{install_includedir}/llvm/Config/llvm-config.h
install -d %{buildroot}%{_datadir}/llvm/
tar -czf %{install_srcdir}/test.tar.gz test/
# Create ld.so.conf.d entry
mkdir -p %{buildroot}%{_sysconfdir}/ld.so.conf.d
cat >> %{buildroot}%{_sysconfdir}/ld.so.conf.d/%{name}-%{_arch}.conf << EOF
%{install_libdir}
EOF
mkdir -p %{buildroot}%{_libdir}/%{name}
cp -R _build/unittests %{buildroot}%{_libdir}/%{name}/
find %{buildroot}%{_libdir}/%{name} -ignore_readdir_race -iname 'cmake*' -exec rm -Rf '{}' ';' || true
# Remove opt-viewer, since this is just a compatibility package.
rm -Rf %{build_install_prefix}/share/opt-viewer
%check
%if %{with check}
cd _build
ninja check-all || :
LD_LIBRARY_PATH=%{buildroot}/%{install_libdir} %{__ninja} check-all -C ./_build/
%endif
%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
%post devel
%{_sbindir}/update-alternatives --install %{_bindir}/llvm-config llvm-config %{_bindir}/llvm-config-%{__isa_bits} %{__isa_bits}
%postun devel
if [ $1 -eq 0 ]; then
%{_sbindir}/update-alternatives --remove llvm-config %{_bindir}/llvm-config-%{__isa_bits}
fi
%ldconfig_scriptlets libs
%files
%license LICENSE.TXT
%{_bindir}/*
%{_libdir}/%{name}/*
%{_datadir}/opt-viewer/*
%exclude %{_bindir}/llvm-config-%{__isa_bits}
%exclude %{_libdir}/%{name}/unittests/
%{install_prefix}/share/man/man1/*
%{install_bindir}/*
%exclude %{install_bindir}/not
%exclude %{install_bindir}/count
%exclude %{install_bindir}/yaml-bench
%exclude %{install_bindir}/lli-child-target
%exclude %{install_bindir}/llvm-isel-fuzzer
%exclude %{install_bindir}/llvm-opt-fuzzer
%files libs
%{_libdir}/*.so*
%exclude %{_libdir}/libLLVM.so
%license LICENSE.TXT
%{install_libdir}/libLLVM-%{maj_ver}.so
%config(noreplace) %{_sysconfdir}/ld.so.conf.d/%{name}-%{_arch}.conf
%{install_libdir}/LLVMgold.so
%{install_libdir}/libLLVM-%{maj_ver}.%{min_ver}*.so
%{install_libdir}/libLTO.so*
%exclude %{install_libdir}/libLTO.so
%{install_libdir}/libRemarks.so*
%files devel
%{_bindir}/llvm-config-%{__isa_bits}
%{_includedir}/llvm/*
%{_includedir}/llvm-c/*
%{_libdir}/cmake/llvm/*
%{_libdir}/libLLVM.so
%{_libdir}/*.a
%{_datadir}/llvm/src/utils
%{_libdir}/%{name}/unittests/
%{_datadir}/llvm/src/test.tar.gz
%license LICENSE.TXT
%{install_includedir}/llvm
%{install_includedir}/llvm-c
%{install_libdir}/libLTO.so
%{install_libdir}/libLLVM.so
%{install_libdir}/cmake/llvm
%files help
%doc %{_pkgdocdir}/html
%{_mandir}/man1/*
%files doc
%license LICENSE.TXT
%doc %{install_docdir}/html
%files static
%license LICENSE.TXT
%{install_libdir}/*.a
%exclude %{install_libdir}/libLLVMTestingSupport.a
%files test
%license LICENSE.TXT
%{install_bindir}/not
%{install_bindir}/count
%{install_bindir}/yaml-bench
%{install_bindir}/lli-child-target
%{install_bindir}/llvm-isel-fuzzer
%{install_bindir}/llvm-opt-fuzzer
%files googletest
%license LICENSE.TXT
%{install_srcdir}/utils
%{install_libdir}/libLLVMTestingSupport.a
%changelog
* Sat Jul 08 2023 cf-zhao <zhaochuanfeng@huawei.com> -12.0.1-6
- Make this spec file support both system-version and multi-version.
* Tue Feb 14 2023 cf-zhao <zhaochuanfeng@huawei.com> - 12.0.1-5
- Disable check temporarily to avoid a build error that `rmbuild` cannot
- remove a file due to no permission.