]> git.ipfire.org Git - people/ms/pakfire.git/blame - macros/build.macro
macros: Update CFLAGS (again)
[people/ms/pakfire.git] / macros / build.macro
CommitLineData
c07a3ca7
MT
1
2
3def MACRO_EXTRACT_TARBALL
c07a3ca7
MT
4 for source in %{sources}; do
5 %{MACRO_EXTRACT} %{DIR_DL}/${source} || exit 1
6 done
7 unset source
8
9 [ -d "%{DIR_APP}" ] && cd %{DIR_APP}
c07a3ca7
MT
10end
11
12def MACRO_INSTALL_FILES
13 %{MACRO_INSTALL_DEFAULT_FILES}
14 %{MACRO_INSTALL_SYSTEMD_FILES}
15 %{MACRO_INSTALL_SYSTEMD_TMPFILES}
16 %{MACRO_INSTALL_PAM_FILES}
17 %{MACRO_INSTALL_LOGROTATE_FILES}
18end
19
20# XXX to be removed soon
21def MACRO_INSTALL_DEFAULT_FILES
22 for file in %{DIR_SOURCE}/default/*; do
23 [ -e "${file}" ] || continue
24 mkdir -p %{BUILDROOT}/etc/default
25 cp -vf ${file} %{BUILDROOT}/etc/default/$(basename ${file})
26 done
27 unset file
28end
29
30def MACRO_INSTALL_PAM_FILES
31 for file in %{DIR_SOURCE}/{*.pam,pam.d/*}; do
32 [ -e "${file}" ] || continue
33 mkdir -p %{BUILDROOT}/etc/pam.d
34 cp -vf ${file} %{BUILDROOT}/etc/pam.d/$(basename ${file%*.pam})
35 done
36 unset file
37end
38
39def MACRO_INSTALL_LOGROTATE_FILES
40 for file in %{DIR_SOURCE}/{*.logrotate,logrotate/*}; do
41 [ -e "${file}" ] || continue
42 mkdir -p %{BUILDROOT}/etc/logrotate.d
43 cp -vf ${file} %{BUILDROOT}/etc/logrotate.d/$(basename ${file%*.logrotate})
44 done
45 unset file
46end
47
48def MACRO_PYTHON_COMPILE
b7c8579c
MT
49 __python_compile() {
50 if [ -x "%{python3}" ]; then
51 %{python3} -m compileall -f \
52 %{BUILDROOT}%{python3_sitearch} %{BUILDROOT}%{python3_sitelib} $@
53 fi
54 }
e9e430d4 55
b7c8579c
MT
56 # Compile any Python modules
57 __python_compile
c07a3ca7
MT
58end
59
47c4090e
MT
60def MACRO_FIX_AUTOTOOLS
61 if [ "%{DISTRO_ARCH}" = "aarch64" ]; then
62 for i in $(find %{DIR_SRC} -name config.guess -or -name config.sub); do
63 if ! grep -q "aarch64" ${i}; then
64 if [ -e "%{datadir}/pakfire/$(basename ${i})" ]; then
65 cp -vf %{datadir}/pakfire/$(basename ${i}) $(dirname ${i})
66 fi
67 fi
68 done
69 fi
70end
71
3477bd1e
MT
72def MACRO_PATCHES
73 __patch() {
74 local paths=()
75 local path
76 local patches=()
77 local patch
78
79 while [ $# -gt 0 ]; do
80 case "${1}" in
81 --search-path=*)
82 paths+=( "${1#--search-path=}" )
83 ;;
84 *)
85 patches+=( "${1}" )
86 ;;
87 esac
88 shift
89 done
90
91 # Apply all patches given on command line.
92 for patch in ${patches[@]}; do
93 case "${patch}" in
94 /*)
95 ;;
96 *)
97 for path in ${paths[@]}; do
98 if [ -e "${path}/${patch}" ]; then
99 patch="${path}/${patch}"
100 break
101 fi
102 done
103 ;;
104 esac
105
106 # Check if patch file does exist.
107 if ! [ -e "${patch}" ]; then
108 echo >&2 " ERROR: Patch file does not exist: ${patch}"
109 return 1
110 fi
111
112 # Options applied to patch command.
113 options="-N"
114
115 # Get right -p1 option.
116 case "${patch}" in
117 *.patch[0-9]|*.patch[0-9]R)
118 _patch="${patch}"
119 # Get patch level from file name.
120 while [ ${#_patch} -gt 0 ]; do
121 last_pos=$(( ${#_patch} - 1 ))
122 last_char=${_patch:${last_pos}}
123 _patch=${_patch:0:${last_pos}}
124
125 case "${last_char}" in
126 [0-9])
127 options="${options} -p${last_char}"
128 break
129 ;;
130 R)
131 options="${options} -R"
132 ;;
133 esac
134 done
135 ;;
136 *.patch|*.diff)
137 # Default is -p1.
138 options="${options} -p1"
139 ;;
140 *)
141 echo >&2 " WARNING: Ignoring unknown file: ${patch}"
142 continue
143 ;;
144 esac
145
146 echo " Applying ${patch} (${options})..."
147 patch ${options} -i ${patch} || return $?
148 done
149
150 return 0
151 }
152
153 __patch --search-path=%{DIR_PATCHES} "%{patches}"
154end
49e0e073 155
c07a3ca7
MT
156# Pre-defined build scripts.
157build
ddabaf53
MT
158 # These variables are used if you have to add some targets
159 # directly to the make command.
160 make_build_targets =
161 make_install_targets = install
162
c07a3ca7 163 def _prepare
3ce6a8ad 164 rm -rf %{BUILDROOT}/*
c44f9d6a 165 mkdir -p %{DIR_SRC} && cd %{DIR_SRC}
c07a3ca7
MT
166
167 %{prepare}
168 end
169
170 def prepare
171 # Extract source tarball.
172 %{MACRO_EXTRACT_TARBALL}
173
174 # Apply all patches.
175 %{MACRO_PATCHES}
176
177 # Run custom commands.
178 %{prepare_cmds}
47c4090e
MT
179
180 # Fix outdated autotools on aarch64
181 %{MACRO_FIX_AUTOTOOLS}
c07a3ca7
MT
182 end
183
184 def prepare_cmds
185 end
186
187 def _build
188 [ -d "%{DIR_APP}" ] && cd %{DIR_APP}
189
190 %{build}
191 end
192
193 def build
194 if [ -e "%{CONFIGURE_SCRIPT}" ]; then
195 ./%{CONFIGURE_SCRIPT} \
196 %{configure_options}
197
28d69c2c 198 %{MACRO_FIX_LIBTOOL}
c07a3ca7
MT
199 fi
200
201 # Run custom commands.
202 %{configure_cmds}
203
204 make %{PARALLELISMFLAGS} %{make_build_targets}
205
206 # Run more custom commands.
207 %{build_cmds}
208 end
209
210 def configure_cmds
211 end
212
213 def build_cmds
214 end
215
216 def _test
217 [ -d "%{DIR_APP}" ] && cd %{DIR_APP}
218
219 %{test}
220 end
221
222 def test
223 end
224
225 def _install
226 [ -d "%{DIR_APP}" ] && cd %{DIR_APP}
227
228 mkdir -pv %{BUILDROOT}
229
230 %{install}
231
232 %{MACRO_INSTALL_FILES}
233 %{MACRO_PYTHON_COMPILE}
9cbc043d
MT
234
235 # Cleanup perl modules.
236 %{perl_cleanup}
c07a3ca7
MT
237
238 %{install_post}
c07a3ca7
MT
239 end
240
241 def install
242 make DESTDIR=%{BUILDROOT} %{make_install_targets}
243
244 # Run custom commands.
245 %{install_cmds}
246 end
247
248 # XXX to be removed soon
249 def install_post
250 end
3ce6a8ad
MT
251
252 # Enable strict processing of build-id by default.
253 # The build will fail if a file is missing its build-id.
254 debuginfo_strict_build_id = true
255 debuginfo_options =
c07a3ca7 256end