|
| 1 | +#!/bin/bash |
1 | 2 |
|
2 | 3 | # see here for info on "new paths for toolchains":
|
3 | 4 | # https://developer.android.com/ndk/guides/other_build_systems
|
@@ -191,34 +192,69 @@ linker_flags_for_abi_name() {
|
191 | 192 |
|
192 | 193 | echo "$COMMON_FLAGS $ABI_FLAGS"
|
193 | 194 | }
|
| 195 | + |
| 196 | +#---------------------------------------------------------------------------------- |
194 | 197 | #----------------------------------------------------------------------------------
|
195 |
| -# write the ndk version to a header file for future reference and programmatic querying |
196 | 198 | persist_ndk_version()
|
197 | 199 | {
|
198 |
| - # get the version string from the "Pkg.Revision" attribute in the $ANDROID_NDK_ROOT"/source.properties" file |
199 |
| - # and write this to a new header file (beside include/boost/version.hpp which documents the boost version) |
200 |
| - local source_properties=${NDK_DIR}/source.properties |
| 200 | + # Define the path to the source properties file |
| 201 | + local source_properties="${NDK_DIR}/source.properties" |
| 202 | + |
| 203 | + # Read the file contents into a variable while stripping carriage returns |
| 204 | + local file_contents="$(cat "$source_properties" | tr -d '\r')" |
201 | 205 |
|
202 |
| - local dir_path=${PREFIX_DIR}/include/boost |
203 |
| - mkdir -p $dir_path |
204 |
| - local headerFile=${dir_path}/version_ndk.hpp |
| 206 | + # Define the output directory and header file |
| 207 | + local dir_path="${PREFIX_DIR}/include/boost" |
| 208 | + mkdir -p "$dir_path" |
| 209 | + local headerFile="${dir_path}/version_ndk.hpp" |
205 | 210 |
|
206 |
| - |
207 |
| - local version=$(sed -En -e 's/^Pkg.Revision\s*=\s*([0-9a-f]+)/\1/p' $source_properties) |
| 211 | + # Check if source.properties file exists |
| 212 | + if [[ ! -f "$source_properties" ]]; then |
| 213 | + echo "Error: $source_properties does not exist!" |
| 214 | + return 1 |
| 215 | + fi |
| 216 | + |
| 217 | + # echo "$source_properties contains:" |
| 218 | + # cat $source_properties |
| 219 | + # Read Pkg.ReleaseName (remove leading/trailing spaces, handle \r for carriage returns) |
| 220 | + local release_name="$(grep -m1 '^Pkg\.ReleaseName[[:space:]]*=' "$source_properties" \ |
| 221 | + | tr -d '\r' \ |
| 222 | + | cut -d= -f2 \ |
| 223 | + | sed 's/^[[:space:]]*//; s/[[:space:]]*$//' |
| 224 | + )" |
| 225 | + |
208 | 226 |
|
209 |
| - |
210 |
| - echo "writing NDK version $version to $headerFile " |
| 227 | + # Read Pkg.BaseRevision (remove leading/trailing spaces, handle \r for carriage returns) |
| 228 | + local base_revision="$(grep -m1 '^Pkg\.BaseRevision[[:space:]]*=' "$source_properties" \ |
| 229 | + | tr -d '\r' \ |
| 230 | + | cut -d= -f2 \ |
| 231 | + | sed 's/^[[:space:]]*//; s/[[:space:]]*$//' |
| 232 | + )" |
| 233 | + |
| 234 | + # Check if the variables are empty |
| 235 | + if [[ -z "$release_name" || -z "$base_revision" ]]; then |
| 236 | + echo "Error: Failed to read values from $source_properties" |
| 237 | + return 1 |
| 238 | + fi |
| 239 | + |
| 240 | + # Concatenate ReleaseName and BaseRevision into ndk_ver |
| 241 | + local ndk_ver="${release_name} (${base_revision})" |
211 | 242 |
|
212 |
| - echo '#ifndef BOOST_VERSION_NDK_HPP' > $headerFile |
213 |
| - echo '#define BOOST_VERSION_NDK_HPP' >> $headerFile |
214 |
| - |
215 |
| - echo -e '\n//The version of the NDK used to build boost' >> $headerFile |
216 |
| - echo -e " #define BOOST_BUILT_WITH_NDK_VERSION \"$version\" \\n" >>$headerFile |
217 |
| - |
218 |
| - echo '#endif' >>$headerFile |
| 243 | + # Print the version to verify |
| 244 | + echo "NDK Version: $ndk_ver" |
219 | 245 |
|
220 |
| - |
| 246 | + # Write to the header file |
| 247 | + echo "writing NDK version $ndk_ver to $headerFile" |
| 248 | + |
| 249 | + # Create the header file with the NDK version information |
| 250 | + echo '#ifndef BOOST_VERSION_NDK_HPP' > "$headerFile" |
| 251 | + echo '#define BOOST_VERSION_NDK_HPP' >> "$headerFile" |
| 252 | + echo -e "\n// The version of the NDK used to build boost" >> "$headerFile" |
| 253 | + echo -e " #define BOOST_BUILT_WITH_NDK_VERSION \"$ndk_ver\" \\n" >> "$headerFile" |
| 254 | + echo '#endif' >> "$headerFile" |
221 | 255 | }
|
| 256 | + |
| 257 | + |
222 | 258 | #----------------------------------------------------------------------------------
|
223 | 259 | #----------------------------------------------------------------------------------
|
224 | 260 | fix_version_suffices() {
|
@@ -261,122 +297,125 @@ fix_version_suffices() {
|
261 | 297 | }
|
262 | 298 | #----------------------------------------------------------------------------------
|
263 | 299 | #----------------------------------------------------------------------------------
|
| 300 | +#---------------------------------------------------------------------------------- |
| 301 | +do_build() |
| 302 | +{ |
264 | 303 |
|
| 304 | + USER_CONFIG_FILE=$(pwd)/user-config.jam |
265 | 305 |
|
266 |
| -USER_CONFIG_FILE=$(pwd)/user-config.jam |
267 |
| - |
268 |
| -cd $BOOST_DIR |
269 |
| - |
270 |
| -#------------------------------------------- |
271 |
| -# Bootstrap |
272 |
| -# --------- |
273 |
| -if [ ! -f ${BOOST_DIR}/b2 ] |
274 |
| -then |
275 |
| - echo "Performing boost bootstrap" |
| 306 | + cd $BOOST_DIR |
276 | 307 |
|
277 |
| - ./bootstrap.sh # 2>&1 | tee -a bootstrap.log |
278 |
| -fi |
279 |
| - |
280 |
| -#------------------------------------------- |
| 308 | + #------------------------------------------- |
| 309 | + # Bootstrap |
| 310 | + # --------- |
| 311 | + if [ ! -f ${BOOST_DIR}/b2 ] |
| 312 | + then |
| 313 | + echo "Performing boost bootstrap" |
281 | 314 |
|
282 |
| -# use as many cores as available (for build) |
283 |
| -num_cores=$(num_cpu_cores) |
284 |
| -echo " cores available = " $num_cores |
| 315 | + ./bootstrap.sh # 2>&1 | tee -a bootstrap.log |
| 316 | + fi |
| 317 | + |
| 318 | + #------------------------------------------- |
285 | 319 |
|
| 320 | + # use as many cores as available (for build) |
| 321 | + num_cores=$(num_cpu_cores) |
| 322 | + echo " cores available = " $num_cores |
286 | 323 |
|
287 | 324 |
|
288 |
| -#------------------------------------------- |
289 |
| -for LINKAGE in $LINKAGES; do |
290 | 325 |
|
291 |
| - for ABI_NAME in $ABI_NAMES; do |
292 |
| - |
| 326 | + #------------------------------------------- |
| 327 | + for LINKAGE in $LINKAGES; do |
293 | 328 |
|
294 |
| - #------------------- |
295 |
| - LOG_FILE=${BUILD_DIR}/build_${ABI_NAME}_${LINKAGE}.log |
296 |
| - # clear any existing |
297 |
| - if [ -f "$LOG_FILE" ] |
298 |
| - then |
299 |
| - rm "$LOG_FILE" |
300 |
| - fi |
301 |
| - |
302 |
| - # ------------------ |
303 |
| - ABI_SPECIFIC_FLAGS="" |
304 |
| - if [ "$ABI_NAME" = "x86" ]; then |
305 |
| - # avoid possible memory leaks on x86 |
306 |
| - ABI_SPECIFIC_FLAGS+=" boost.stacktrace.from_exception=off" |
307 |
| - fi |
308 |
| - |
309 |
| - # ------------------ |
310 |
| - |
311 |
| - # toolset_name="$(toolset_for_abi_name $ABI_NAME)" |
312 |
| - abi="$(abi_for_abi_name $ABI_NAME)" |
313 |
| - address_model="$(address_model_for_abi_name $ABI_NAME)" |
314 |
| - arch_for_abi="$(arch_for_abi_name $ABI_NAME)" |
315 |
| - |
316 |
| - # used by scripts in ./bin/ |
317 |
| - export BFA_CLANG_TRIPLE_FOR_ABI="$(clang_triple_for_abi_name $ABI_NAME)" |
318 |
| - export BFA_TOOL_TRIPLE_FOR_ABI="$(tool_triple_for_abi_name $ABI_NAME)" |
319 |
| - export BFA_COMPILER_FLAGS_FOR_ABI="$(compiler_flags_for_abi_name $ABI_NAME)" |
320 |
| - export BFA_LINKER_FLAGS_FOR_ABI="$(linker_flags_for_abi_name $ABI_NAME)" |
| 329 | + for ABI_NAME in $ABI_NAMES; do |
321 | 330 |
|
322 |
| - echo "------------------------------------------------------------"| tee -a ${LOG_FILE} |
323 |
| - echo "Building boost for: $ABI_NAME $LINKAGE on host ${HOST_OS_TAG}" | tee -a ${LOG_FILE} |
324 |
| - |
325 |
| - # echo "address-model=$address_model " | tee -a ${LOG_FILE} |
326 |
| - # echo "architecture=$arch_for_abi " | tee -a ${LOG_FILE} |
327 |
| - # echo "abi=$abi " | tee -a ${LOG_FILE} |
328 |
| - # echo "link=$LINKAGE " | tee -a ${LOG_FILE} |
329 |
| - # echo "--user-config=$USER_CONFIG_FILE" | tee -a ${LOG_FILE} |
330 |
| - |
331 |
| - # echo "WITH_LIBRARIES = $WITH_LIBRARIES" | tee -a ${LOG_FILE} |
332 |
| - # echo "WITHOUT_LIBRARIES = $WITHOUT_LIBRARIES" | tee -a ${LOG_FILE} |
333 |
| - # echo "ABI_SPECIFIC_FLAGS = $ABI_SPECIFIC_FLAGS" | tee -a ${LOG_FILE} |
334 | 331 |
|
335 |
| - # echo "--builddir=${BUILD_DIR_TMP}/$ABI_NAME " | tee -a ${LOG_FILE} |
336 |
| - # echo "--includedir=${INCLUDE_DIR}" | tee -a ${LOG_FILE} |
337 |
| - # echo "--libdir=${LIBS_DIR}/$ABI_NAME" | tee -a ${LOG_FILE} |
| 332 | + #------------------- |
| 333 | + LOG_FILE=${BUILD_DIR}/build_${ABI_NAME}_${LINKAGE}.log |
| 334 | + # clear any existing |
| 335 | + if [ -f "$LOG_FILE" ] |
| 336 | + then |
| 337 | + rm "$LOG_FILE" |
| 338 | + fi |
| 339 | + |
| 340 | + # ------------------ |
| 341 | + ABI_SPECIFIC_FLAGS="" |
| 342 | + if [ "$ABI_NAME" = "x86" ]; then |
| 343 | + # avoid possible memory leaks on x86 |
| 344 | + ABI_SPECIFIC_FLAGS+=" boost.stacktrace.from_exception=off" |
| 345 | + fi |
338 | 346 |
|
| 347 | + # ------------------ |
| 348 | + |
| 349 | + # toolset_name="$(toolset_for_abi_name $ABI_NAME)" |
| 350 | + abi="$(abi_for_abi_name $ABI_NAME)" |
| 351 | + address_model="$(address_model_for_abi_name $ABI_NAME)" |
| 352 | + arch_for_abi="$(arch_for_abi_name $ABI_NAME)" |
| 353 | + |
| 354 | + # used by scripts in ./bin/ |
| 355 | + export BFA_CLANG_TRIPLE_FOR_ABI="$(clang_triple_for_abi_name $ABI_NAME)" |
| 356 | + export BFA_TOOL_TRIPLE_FOR_ABI="$(tool_triple_for_abi_name $ABI_NAME)" |
| 357 | + export BFA_COMPILER_FLAGS_FOR_ABI="$(compiler_flags_for_abi_name $ABI_NAME)" |
| 358 | + export BFA_LINKER_FLAGS_FOR_ABI="$(linker_flags_for_abi_name $ABI_NAME)" |
| 359 | + |
| 360 | + echo "------------------------------------------------------------"| tee -a ${LOG_FILE} |
| 361 | + echo "Building boost for: $ABI_NAME $LINKAGE on host ${HOST_OS_TAG}" | tee -a ${LOG_FILE} |
339 | 362 |
|
340 |
| - # echo "BFA_CLANG_TRIPLE_FOR_ABI=$(clang_triple_for_abi_name $ABI_NAME)" | tee -a ${LOG_FILE} |
341 |
| - # echo "BFA_TOOL_TRIPLE_FOR_ABI=$(tool_triple_for_abi_name $ABI_NAME)" | tee -a ${LOG_FILE} |
342 |
| - # echo "BFA_COMPILER_FLAGS_FOR_ABI=$(compiler_flags_for_abi_name $ABI_NAME)" | tee -a ${LOG_FILE} |
343 |
| - # echo "BFA_LINKER_FLAGS_FOR_ABI=$(linker_flags_for_abi_name $ABI_NAME)" | tee -a ${LOG_FILE} |
344 |
| - |
345 |
| - echo "------------------------------------------------------------"| tee -a ${LOG_FILE} |
346 |
| - # toolset=clang-$toolset_name \ |
347 |
| - |
348 |
| - { |
349 |
| - ./b2 -q -j$num_cores \ |
350 |
| - binary-format=elf \ |
351 |
| - address-model=$address_model \ |
352 |
| - architecture=$arch_for_abi \ |
353 |
| - abi=$abi \ |
354 |
| - link=$LINKAGE \ |
355 |
| - threading=multi \ |
356 |
| - target-os=android \ |
357 |
| - --user-config=$USER_CONFIG_FILE \ |
358 |
| - --ignore-site-config \ |
359 |
| - --layout=system \ |
360 |
| - $WITH_LIBRARIES \ |
361 |
| - $WITHOUT_LIBRARIES \ |
362 |
| - $ABI_SPECIFIC_FLAGS \ |
363 |
| - --build-dir=${BUILD_DIR_TMP}/$ABI_NAME/$LINKAGE \ |
364 |
| - --includedir=${INCLUDE_DIR} \ |
365 |
| - --libdir=${LIBS_DIR}/$ABI_NAME/$LINKAGE \ |
366 |
| - install 2>&1 \ |
367 |
| - || { echo "Error: Failed to build boost for $ABI_NAME!";} |
368 |
| - } | tee -a ${LOG_FILE} |
| 363 | + # echo "address-model=$address_model " | tee -a ${LOG_FILE} |
| 364 | + # echo "architecture=$arch_for_abi " | tee -a ${LOG_FILE} |
| 365 | + # echo "abi=$abi " | tee -a ${LOG_FILE} |
| 366 | + # echo "link=$LINKAGE " | tee -a ${LOG_FILE} |
| 367 | + # echo "--user-config=$USER_CONFIG_FILE" | tee -a ${LOG_FILE} |
| 368 | + |
| 369 | + # echo "WITH_LIBRARIES = $WITH_LIBRARIES" | tee -a ${LOG_FILE} |
| 370 | + # echo "WITHOUT_LIBRARIES = $WITHOUT_LIBRARIES" | tee -a ${LOG_FILE} |
| 371 | + # echo "ABI_SPECIFIC_FLAGS = $ABI_SPECIFIC_FLAGS" | tee -a ${LOG_FILE} |
| 372 | + |
| 373 | + # echo "--builddir=${BUILD_DIR_TMP}/$ABI_NAME " | tee -a ${LOG_FILE} |
| 374 | + # echo "--includedir=${INCLUDE_DIR}" | tee -a ${LOG_FILE} |
| 375 | + # echo "--libdir=${LIBS_DIR}/$ABI_NAME" | tee -a ${LOG_FILE} |
| 376 | + |
| 377 | + |
| 378 | + # echo "BFA_CLANG_TRIPLE_FOR_ABI=$(clang_triple_for_abi_name $ABI_NAME)" | tee -a ${LOG_FILE} |
| 379 | + # echo "BFA_TOOL_TRIPLE_FOR_ABI=$(tool_triple_for_abi_name $ABI_NAME)" | tee -a ${LOG_FILE} |
| 380 | + # echo "BFA_COMPILER_FLAGS_FOR_ABI=$(compiler_flags_for_abi_name $ABI_NAME)" | tee -a ${LOG_FILE} |
| 381 | + # echo "BFA_LINKER_FLAGS_FOR_ABI=$(linker_flags_for_abi_name $ABI_NAME)" | tee -a ${LOG_FILE} |
| 382 | + |
| 383 | + echo "------------------------------------------------------------"| tee -a ${LOG_FILE} |
| 384 | + # toolset=clang-$toolset_name \ |
| 385 | + |
| 386 | + { |
| 387 | + ./b2 -q -j$num_cores \ |
| 388 | + binary-format=elf \ |
| 389 | + address-model=$address_model \ |
| 390 | + architecture=$arch_for_abi \ |
| 391 | + abi=$abi \ |
| 392 | + link=$LINKAGE \ |
| 393 | + threading=multi \ |
| 394 | + target-os=android \ |
| 395 | + --user-config=$USER_CONFIG_FILE \ |
| 396 | + --ignore-site-config \ |
| 397 | + --layout=system \ |
| 398 | + $WITH_LIBRARIES \ |
| 399 | + $WITHOUT_LIBRARIES \ |
| 400 | + $ABI_SPECIFIC_FLAGS \ |
| 401 | + --build-dir=${BUILD_DIR_TMP}/$ABI_NAME/$LINKAGE \ |
| 402 | + --includedir=${INCLUDE_DIR} \ |
| 403 | + --libdir=${LIBS_DIR}/$ABI_NAME/$LINKAGE \ |
| 404 | + install 2>&1 \ |
| 405 | + || { echo "Error: Failed to build boost for $ABI_NAME!";} |
| 406 | + } | tee -a ${LOG_FILE} |
| 407 | + |
| 408 | + done # for ABI_NAME in $ABI_NAMES |
369 | 409 |
|
370 |
| - done # for ABI_NAME in $ABI_NAMES |
371 |
| - |
372 |
| -done # for LINKAGE in $LINKAGES |
373 |
| - |
| 410 | + done # for LINKAGE in $LINKAGES |
| 411 | +} |
374 | 412 | #-------------------------------------------
|
375 | 413 |
|
| 414 | +# do_build |
376 | 415 |
|
377 | 416 | persist_ndk_version
|
378 | 417 |
|
379 |
| -fix_version_suffices |
| 418 | +# fix_version_suffices |
380 | 419 |
|
381 | 420 | echo "built boost to " ${PREFIX_DIR}
|
382 | 421 |
|
|
0 commit comments