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