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

This commit is contained in:
cf_zhao 2023-07-05 16:58:23 +08:00
parent 2247adc589
commit 755fe97684
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/)

360
llvm.spec
View File

@ -1,124 +1,182 @@
%bcond_with check %bcond_with sys_llvm
%bcond_without check
Name: llvm %global maj_ver 12
Version: 12.0.1 %global min_ver 0
Release: 5 %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 Summary: The Low Level Virtual Machine
License: NCSA License: NCSA
URL: http://llvm.org 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: binutils-devel
BuildRequires: python3-sphinx binutils-devel valgrind-devel libedit-devel python3-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-recommonmark
BuildRequires: python3-sphinx
BuildRequires: python3-setuptools
BuildRequires: zlib-devel
Requires: %{name}-libs%{?_isa} = %{version}-%{release}
Provides: llvm(major) = %{maj_ver}
%description %description
LLVM is a compiler infrastructure designed for compile-time, link-time, LLVM is a compiler infrastructure designed for compile-time, link-time,
runtime, and idle-time optimization of programs from arbitrary programming 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, %package devel
from industrial strength compilers to specialized JIT applications Summary: Libraries and header files for LLVM
to small research projects. 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 %package libs
Summary:LLVM shared libraries Summary: LLVM shared libraries
%description libs %description libs
Shared libraries for the LLVM compiler infrastructure. Shared libraries for the LLVM compiler infrastructure.
%package devel %package static
Summary: Development files for %{name} Summary: LLVM static libraries
Requires: %{name} = %{version}-%{release} Conflicts: %{name}-devel < 8
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}
%description devel Provides: llvm-static(major) = %{maj_ver}
The %{name}-devel package contains libraries and header files for
developing applications that use %{name}.
%package help %description static
Summary: Doc files for %{name} Static libraries for the LLVM compiler infrastructure.
Buildarch: noarch
Requires: man
Provides: %{name}-doc = %{version}-%{release}
Obsoletes: %{name}-doc < %{version}-%{release}
%description help %package test
The %{name}-help package contains doc files for %{name}. 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 %prep
%autosetup -n %{name}-%{version}.src -p1 %setup -T -q -b 0 -n llvm-%{version}.src
pathfix.py -i %{__python3} -pn test/BugPoint/compile-custom.ll.py tools/opt-viewer/*.py
pathfix.py -i %{__python3} -pn \
test/BugPoint/compile-custom.ll.py \
tools/opt-viewer/*.py \
utils/update_cc_test_checks.py
%build %build
#TODO: -DLLVM_TARGETS_TO_BUILD=all in needed(temporarily) when build rust,
# clarification is required in the future
mkdir -p _build mkdir -p _build
cd _build cd _build
%global optflags %(echo %{optflags} | sed 's/-g /-g1 /')
%cmake .. -G Ninja \ %cmake .. -G Ninja \
-DBUILD_SHARED_LIBS:BOOL=OFF \ -DBUILD_SHARED_LIBS:BOOL=OFF \
-DLLVM_PARALLEL_LINK_JOBS=1 \ -DLLVM_PARALLEL_LINK_JOBS=%{max_link_jobs} \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_SKIP_RPATH:BOOL=ON \ -DCMAKE_SKIP_RPATH:BOOL=ON \
-DCMAKE_C_FLAGS_RELWITHDEBINFO="%{optflags} -DNDEBUG -fPIE -fPIC" \ -DLLVM_TARGETS_TO_BUILD=%{targets_to_build} \
-DCMAKE_CXX_FLAGS_RELWITHDEBINFO="%{optflags} -DNDEBUG -fPIE -fPIC" \ -DLLVM_ENABLE_LIBCXX:BOOL=OFF \
-DCMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO="%{optflags} -pie" \ -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 %if 0%{?__isa_bits} == 64
-DLLVM_LIBDIR_SUFFIX=64 \ -DLLVM_LIBDIR_SUFFIX=64 \
%else %else
-DLLVM_LIBDIR_SUFFIX= \ -DLLVM_LIBDIR_SUFFIX= \
%endif %endif
%if 0 -DLLVM_INCLUDE_BENCHMARKS=OFF
%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
%ninja_build LLVM %ninja_build LLVM
%ninja_build %ninja_build
@ -126,81 +184,109 @@ cd _build
%install %install
%ninja_install -C _build %ninja_install -C _build
find %{buildroot}%{_libdir}/cmake/llvm -type f | xargs sed -i "s|%{buildroot}||g" mkdir -p %{buildroot}/%{_bindir}
mv -v %{buildroot}%{_bindir}/llvm-config{,-%{__isa_bits}}
for f in llvm-isel-fuzzer llvm-opt-fuzzer; do # Install binaries needed for lit tests
install -m 0755 ./_build/bin/$f %{buildroot}%{_bindir} for f in llvm-isel-fuzzer llvm-opt-fuzzer
do
install -m 0755 %{_builddir}/llvm-%{version}.src/_build/bin/$f %{buildroot}%{install_bindir}
done done
%global install_srcdir %{buildroot}%{_datadir}/llvm/src %if 0%{?__isa_bits} == 64
%global lit_cfg test/lit.site.cfg.py install %{_builddir}/llvm-%{version}.src/_build/lib64/libLLVMTestingSupport.a %{buildroot}%{install_libdir}
%global lit_unit_cfg test/Unit/lit.site.cfg.py %else
install %{_builddir}/llvm-%{version}.src/_build/lib/libLLVMTestingSupport.a %{buildroot}%{install_libdir}
%endif
install -d %{install_srcdir} # Install gtest sources so clang can use them for gtest
install -d %{install_srcdir}/utils/ install -d %{buildroot}%{install_srcdir}
cp -R utils/unittest %{install_srcdir}/utils/ 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} # Clang needs these for running lit tests.
cat _build/test/Unit/lit.site.cfg.py >> %{lit_unit_cfg} cp %{_builddir}/llvm-%{version}.src/utils/update_cc_test_checks.py %{buildroot}%{install_srcdir}/utils/
sed -i -e s~`pwd`/_build~%{_prefix}~g -e s~`pwd`~.~g %{lit_cfg} %{lit_cfg} %{lit_unit_cfg} 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/ # Create ld.so.conf.d entry
tar -czf %{install_srcdir}/test.tar.gz test/ 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} # Remove opt-viewer, since this is just a compatibility package.
cp -R _build/unittests %{buildroot}%{_libdir}/%{name}/ rm -Rf %{build_install_prefix}/share/opt-viewer
find %{buildroot}%{_libdir}/%{name} -ignore_readdir_race -iname 'cmake*' -exec rm -Rf '{}' ';' || true
%check %check
%if %{with check} %if %{with check}
cd _build LD_LIBRARY_PATH=%{buildroot}/%{install_libdir} %{__ninja} check-all -C ./_build/
ninja check-all || :
%endif %endif
%post -p /sbin/ldconfig %ldconfig_scriptlets libs
%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
%files %files
%license LICENSE.TXT %license LICENSE.TXT
%{_bindir}/* %{install_prefix}/share/man/man1/*
%{_libdir}/%{name}/* %{install_bindir}/*
%{_datadir}/opt-viewer/* %exclude %{install_bindir}/not
%exclude %{_bindir}/llvm-config-%{__isa_bits} %exclude %{install_bindir}/count
%exclude %{_libdir}/%{name}/unittests/ %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 %files libs
%{_libdir}/*.so* %license LICENSE.TXT
%exclude %{_libdir}/libLLVM.so %{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 %files devel
%{_bindir}/llvm-config-%{__isa_bits} %license LICENSE.TXT
%{_includedir}/llvm/* %{install_includedir}/llvm
%{_includedir}/llvm-c/* %{install_includedir}/llvm-c
%{_libdir}/cmake/llvm/* %{install_libdir}/libLTO.so
%{_libdir}/libLLVM.so %{install_libdir}/libLLVM.so
%{_libdir}/*.a %{install_libdir}/cmake/llvm
%{_datadir}/llvm/src/utils
%{_libdir}/%{name}/unittests/
%{_datadir}/llvm/src/test.tar.gz
%files help %files doc
%doc %{_pkgdocdir}/html %license LICENSE.TXT
%{_mandir}/man1/* %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 %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 * Tue Feb 14 2023 cf-zhao <zhaochuanfeng@huawei.com> - 12.0.1-5
- Disable check temporarily to avoid a build error that `rmbuild` cannot - Disable check temporarily to avoid a build error that `rmbuild` cannot
- remove a file due to no permission. - remove a file due to no permission.