]> git.ipfire.org Git - pakfire.git/blame - macros/build.macro
macros: Construct LDFLAGS with more information and add -O1
[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
4026d3a0
MT
158 configure = [ -x "%{CONFIGURE_SCRIPT}" ] && ./%{CONFIGURE_SCRIPT} %{configure_options}
159
ddabaf53
MT
160 # These variables are used if you have to add some targets
161 # directly to the make command.
162 make_build_targets =
163 make_install_targets = install
164
c07a3ca7 165 def _prepare
3ce6a8ad 166 rm -rf %{BUILDROOT}/*
c44f9d6a 167 mkdir -p %{DIR_SRC} && cd %{DIR_SRC}
c07a3ca7
MT
168
169 %{prepare}
170 end
171
172 def prepare
173 # Extract source tarball.
174 %{MACRO_EXTRACT_TARBALL}
175
176 # Apply all patches.
177 %{MACRO_PATCHES}
178
179 # Run custom commands.
180 %{prepare_cmds}
47c4090e
MT
181
182 # Fix outdated autotools on aarch64
183 %{MACRO_FIX_AUTOTOOLS}
c07a3ca7
MT
184 end
185
186 def prepare_cmds
187 end
188
189 def _build
190 [ -d "%{DIR_APP}" ] && cd %{DIR_APP}
191
192 %{build}
193 end
194
195 def build
4026d3a0
MT
196 # Run configure
197 %{configure}
c07a3ca7 198
4026d3a0
MT
199 # Remove any RPATH stuff from locally installed libtool
200 %{MACRO_FIX_LIBTOOL}
c07a3ca7
MT
201
202 # Run custom commands.
203 %{configure_cmds}
204
205 make %{PARALLELISMFLAGS} %{make_build_targets}
206
207 # Run more custom commands.
208 %{build_cmds}
209 end
210
211 def configure_cmds
212 end
213
214 def build_cmds
215 end
216
217 def _test
218 [ -d "%{DIR_APP}" ] && cd %{DIR_APP}
219
220 %{test}
221 end
222
223 def test
224 end
225
226 def _install
227 [ -d "%{DIR_APP}" ] && cd %{DIR_APP}
228
229 mkdir -pv %{BUILDROOT}
230
231 %{install}
232
233 %{MACRO_INSTALL_FILES}
234 %{MACRO_PYTHON_COMPILE}
9cbc043d
MT
235
236 # Cleanup perl modules.
237 %{perl_cleanup}
c07a3ca7
MT
238
239 %{install_post}
c07a3ca7
MT
240 end
241
242 def install
243 make DESTDIR=%{BUILDROOT} %{make_install_targets}
244
245 # Run custom commands.
246 %{install_cmds}
247 end
248
249 # XXX to be removed soon
250 def install_post
251 end
3ce6a8ad
MT
252
253 # Enable strict processing of build-id by default.
254 # The build will fail if a file is missing its build-id.
255 debuginfo_strict_build_id = true
256 debuginfo_options =
c07a3ca7 257end