diff --git a/cmake-tool/helpers/cpio.cmake b/cmake-tool/helpers/cpio.cmake index 732fb945..ba958ac0 100644 --- a/cmake-tool/helpers/cpio.cmake +++ b/cmake-tool/helpers/cpio.cmake @@ -43,12 +43,20 @@ function(MakeCPIO output_name input_files) if(NOT "${MAKE_CPIO_CPIO_SYMBOL}" STREQUAL "") set(archive_symbol ${MAKE_CPIO_CPIO_SYMBOL}) endif() + + # intermediate files + set(cpio_archive "archive.${output_name}.cpio") + set(cpio_archive_s "${output_name}.S") + # Check that the reproducible flag is available. Don't use it if it isn't. CheckCPIOArgument(cpio_reproducible_flag "--reproducible") set( - commands - "bash;-c;cpio ${cpio_reproducible_flag} --quiet --create -H newc --file=${CMAKE_CURRENT_BINARY_DIR}/archive.${output_name}.cpio;&&" + cpio_cmd + "cpio ${cpio_reproducible_flag} --quiet --create -H newc --file=${CMAKE_CURRENT_BINARY_DIR}/${cpio_archive}" ) + + set(tmp_dir "temp_${output_name}") + set(commands "bash;-c;${cpio_cmd};&&") foreach(file IN LISTS input_files) # Try and generate reproducible cpio meta-data as we do this: # - touch -d @0 file sets the modified time to 0 @@ -57,10 +65,11 @@ function(MakeCPIO output_name input_files) list( APPEND commands - "bash;-c; mkdir -p temp_${output_name} && cd temp_${output_name} && cp -a ${file} . && touch -d 1970-01-01T00:00:00Z `basename ${file}` && echo `basename ${file}` | cpio --append ${cpio_reproducible_flag} --owner=+0:+0 --quiet -o -H newc --file=${CMAKE_CURRENT_BINARY_DIR}/archive.${output_name}.cpio && rm `basename ${file}` && cd ../ && rmdir temp_${output_name};&&" + "bash;-c; mkdir -p ${tmp_dir} && cd ${tmp_dir} && cp -a ${file} . && touch -d 1970-01-01T00:00:00Z `basename ${file}` && echo `basename ${file}` | ${cpio_cmd} --append --owner=+0:+0 && rm `basename ${file}` && cd ../ && rmdir ${tmp_dir};&&" ) endforeach() list(APPEND commands "true") + separate_arguments(cmake_c_flags_sep NATIVE_COMMAND "${CMAKE_C_FLAGS}") if(CMAKE_C_COMPILER_ID STREQUAL "Clang") list(APPEND cmake_c_flags_sep "${CMAKE_C_COMPILE_OPTIONS_TARGET}${CMAKE_C_COMPILER_TARGET}") @@ -68,19 +77,19 @@ function(MakeCPIO output_name input_files) add_custom_command( OUTPUT ${output_name} - COMMAND rm -f archive.${output_name}.cpio + COMMAND rm -f ${cpio_archive} COMMAND ${commands} COMMAND sh -c - "echo 'X.section ._archive_cpio,\"aw\"X.globl ${archive_symbol}, ${archive_symbol}_endX${archive_symbol}:X.incbin \"archive.${output_name}.cpio\"X${archive_symbol}_end:X' | tr X '\\n'" - > ${output_name}.S + "echo 'X.section ._archive_cpio,\"aw\"X.globl ${archive_symbol}, ${archive_symbol}_endX${archive_symbol}:X.incbin \"${cpio_archive}\"X${archive_symbol}_end:X' | tr X '\\n'" + > "${cpio_archive_s}" COMMAND - ${CMAKE_C_COMPILER} ${cmake_c_flags_sep} -c -o ${output_name} ${output_name}.S + ${CMAKE_C_COMPILER} ${cmake_c_flags_sep} -c -o ${output_name} "${cpio_archive_s}" DEPENDS ${input_files} ${MAKE_CPIO_DEPENDS} VERBATIM BYPRODUCTS - archive.${output_name}.cpio - ${output_name}.S + "${cpio_archive}" + "${cpio_archive_s}" COMMENT "Generate CPIO archive ${output_name}" ) endfunction(MakeCPIO)