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