blob: f291482048701d3a608fae841f9a26ca6e84655a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
Name: file-classify
Version: 0.0.3
Release: 1%{?dist}
Summary: Classify the files.
License: MulanPSL2
Source: https://github.com/stevending1st/%{name}/archive/refs/tags/v%{version}.tar.gz
BuildRequires: wget, dnf-plugins-core, binutils, glibc-devel, gcc-c++, openssl
Requires(pre): wget
%description
Move files to different folders based on their extensions and types.
%global cangjie_zip_name Cangjie-0.53.13-linux.tar.gz
%global cangjie_x86_64_download_url "https://cangjie-lang.cn/v1/files/auth/downLoad?nsId=142267&fileName=Cangjie-0.53.13-linux_x64.tar.gz&objectKey=6719f1eb3af6947e3c6af327"
%global cangjie_aarch64_download_url "https://cangjie-lang.cn/v1/files/auth/downLoad?nsId=142267&fileName=Cangjie-0.53.13-linux_aarch64.tar.gz&objectKey=6719f1ec3af6947e3c6af328"
%global output_dir_name %{name}-%{version}-%{release}.%{_arch}
%global command main
%global debug_package %{nil}
%define __requires_exclude (libcangjie-runtime\.so|libsecurec\.so)
# 根据环境设置下载地址
%ifarch x86_64
# 这里的指令仅在 x86_64 架构下运行
%global download_url %{cangjie_x86_64_download_url}
%endif
%ifarch aarch64
# 这里的指令仅在 ARM 架构下运行
%global download_url %{cangjie_aarch64_download_url}
%endif
%prep
%autosetup -n %{name}-%{version}
cd %{_builddir}/%{name}-%{version}
bash ./create_crt_links.sh
%build
cd %{_builddir}
# 检查文件是否存在,并设置一个宏
if [ ! -f %{_builddir}/%{cangjie_zip_name} ]; then
wget -O %{cangjie_zip_name} %{download_url}
fi
tar -xvf %{cangjie_zip_name}
cd %{_builddir}/%{buildsubdir}
source %{_builddir}/cangjie/envsetup.sh
cjpm build -o %{name}
echo "" > %{_builddir}/%{name}
%install
cd %{_buildrootdir}/%{output_dir_name}
%{__install} -p -D -m 755 %{_builddir}/%{buildsubdir}/target/release/bin/%{name} %{_buildrootdir}/%{output_dir_name}%{_bindir}/%{name}
ln -sf %{_bindir}/%{name} .%{_bindir}/%{command}
%{__install} -p -D -m 777 %{_builddir}/%{name} %{_buildrootdir}/%{output_dir_name}%{_sysconfdir}/%{name}
%clean
rm -rf %{buildroot}
%pre
if [ $1 == 1 ] ; then
# 获取当前系统架构
ARCH=$(uname -m)
# 下载目录
DOWNLOAD_CANGJIE_PATH=/tmp
# 配置 Cangjie 语言环境
if [ "$ARCH" == "x86_64" ]; then
DOWNLOAD_URL=%{cangjie_x86_64_download_url}
else
DOWNLOAD_URL=%{cangjie_aarch64_download_url}
fi
if [ ! -f $DOWNLOAD_CANGJIE_PATH/%{cangjie_zip_name} ]; then
wget -O $DOWNLOAD_CANGJIE_PATH/%{cangjie_zip_name} $DOWNLOAD_URL
fi
if [ ! -d $DOWNLOAD_CANGJIE_PATH/cangjie ]; then
tar -xvf $DOWNLOAD_CANGJIE_PATH/%{cangjie_zip_name} -C $DOWNLOAD_CANGJIE_PATH
fi
%{__install} -d -m 755 /usr/local/lib64/%{name}/
%{__install} -D -p -m 755 ${DOWNLOAD_CANGJIE_PATH}/cangjie/runtime/lib/linux_${ARCH}_llvm/* /usr/local/lib64/%{name}/
echo "/usr/local/lib64/%{name}" >> /etc/ld.so.conf.d/%{name}.conf
if [ -e /usr/lib/wsl/lib/libcuda.so.1 ]; then
cd /usr/lib/wsl/lib
rm libcuda.so libcuda.so.1
ln -s libcuda.so.1.1 libcuda.so.1
fi
/usr/sbin/ldconfig
fi
%post
if [ $1 == 1 ] && [ -s %{_sysconfdir}/%{name} ] ; then
if [ -z "$FILE_CLASSIFY_OUTPUT_FILE" ] ; then
if [ -f "/var/tmp/%{name}" ]; then
OUTPUT_PATH=$(cat /var/tmp/%{name})
fi
else
OUTPUT_PATH="$FILE_CLASSIFY_OUTPUT_FILE"
fi
if [ -n "$OUTPUT_PATH" ]; then
echo "$OUTPUT_PATH" > %{_sysconfdir}/%{name}
fi
fi
%postun
if [ $1 == 0 ] ; then
rm -rf /usr/local/lib64/%{name}/ 2>/dev/null ||:
rm -f /etc/ld.so.conf.d/%{name}.conf 2>/dev/null ||:
/usr/sbin/ldconfig
fi
%files
# %license add-license-file-here
# %doc add-docs-here
%defattr(-,root,root,-)
%{_bindir}/%{name}
%{_bindir}/%{command}
%config(noreplace) %{_sysconfdir}/%{name}
%changelog
* Sun Feb 23 2025 stevending1st <stevending1st@163.com> - 0.0.1-1
- Initial version.
|