def merge_hex_executables(target, source, env):
    """Combine all hex files into a singular executable file."""
    output_name = str(target[0])

    hex_final = IntelHex()
    for image in source:
        file = str(image)
        root, ext = os.path.splitext(file)
        file_format = ext[1:]
        if file_format == 'elf':
            file = root + '.hex'
        hex_data = IntelHex(file)

        # merge will throw errors on mismatched Start Segment Addresses, which we don't need
        # See <https://stackoverflow.com/questions/26295776/what-are-the-intel-hex-records-type-03-or-05-doing-in-ihex-program-for-arm>
        hex_data.start_addr = None
        hex_final.merge(hex_data, overlap='error')

    with open(output_name, 'w') as outfile:
        hex_final.write_hex_file(outfile)
Combine all hex files into a singular executable file.