]> git.ipfire.org Git - pakfire.git/blob - macros/build.macro
4eedd6a91f728dde7ddb6dfffbcdaee19ab51231
[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 # GNU Make Stuff
149 __make = make -O
150
151 # Default "make" command
152 make_build = %{__make} %{PARALLELISMFLAGS} %{make_build_targets}
153
154 # Default "make install" command
155 make_install = %{__make} DESTDIR=%{BUILDROOT} %{make_install_targets}
156
157 # These variables are used if you have to add some targets directly to the make command
158 # LEGACY: DO NOT USE ANY MORE
159 make_build_targets =
160 make_install_targets = install
161
162 def _prepare
163 rm -rf %{BUILDROOT}/*
164 mkdir -p %{DIR_SRC} && cd %{DIR_SRC}
165
166 %{prepare}
167
168 # Create the build directory
169 mkdir -pv %{DIR_BUILD}
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}
181 end
182
183 def prepare_cmds
184 end
185
186 def _build
187 [ -d "%{DIR_BUILD}" ] && cd %{DIR_BUILD}
188
189 %{build}
190 end
191
192 def build
193 # Run configure
194 %{configure}
195
196 # Remove any RPATH stuff from locally installed libtool
197 %{MACRO_FIX_LIBTOOL}
198
199 # Run custom commands
200 %{configure_cmds}
201
202 # Run build
203 %{make_build}
204
205 # Run more custom commands.
206 %{build_cmds}
207 end
208
209 def configure_cmds
210 end
211
212 def build_cmds
213 end
214
215 def _test
216 [ -d "%{DIR_BUILD}" ] && cd %{DIR_BUILD}
217
218 %{test}
219 end
220
221 def test
222 end
223
224 def _install
225 [ -d "%{DIR_BUILD}" ] && cd %{DIR_BUILD}
226
227 # Create BUILDROOT
228 mkdir -pv %{BUILDROOT}
229
230 %{install}
231
232 %{MACRO_INSTALL_FILES}
233 %{MACRO_PYTHON_COMPILE}
234
235 # Cleanup perl modules
236 %{perl_cleanup}
237
238 %{install_post}
239 end
240
241 def install
242 # Install
243 %{make_install}
244
245 # Run custom commands
246 %{install_cmds}
247 end
248 end