@@ -1130,29 +1130,37 @@ static void relocate_function_starts_command(linkedit_data_command *x, int32_t p
11301130
11311131// //////////////////////////////////////////////////////////////////////////////
11321132
1133- static bool MCDeployToMacOSXFetchMinOSVersion ( const MCDeployParameters& p_params, mach_header& p_header, uint32_t & r_version )
1133+ static MCDeployArchitecture MCDeployMachArchToDeployArchitecture ( cpu_type_t p_type, cpu_subtype_t p_subtype )
11341134{
1135- // First work out what DeployArchitecture to look for.
11361135 MCDeployArchitecture t_arch;
1137- if (p_header . cputype == CPU_TYPE_X86)
1136+ if (p_type == CPU_TYPE_X86)
11381137 t_arch = kMCDeployArchitecture_I386 ;
1139- else if (p_header . cputype == CPU_TYPE_X86_64)
1138+ else if (p_type == CPU_TYPE_X86_64)
11401139 t_arch = kMCDeployArchitecture_X86_64 ;
1141- else if (p_header . cputype == CPU_TYPE_ARM && p_header . cpusubtype == CPU_SUBTYPE_ARM_V6)
1140+ else if (p_type == CPU_TYPE_ARM && p_subtype == CPU_SUBTYPE_ARM_V6)
11421141 t_arch = kMCDeployArchitecture_ARMV6 ;
1143- else if (p_header . cputype == CPU_TYPE_ARM && p_header . cpusubtype == CPU_SUBTYPE_ARM_V7)
1142+ else if (p_type == CPU_TYPE_ARM && p_subtype == CPU_SUBTYPE_ARM_V7)
11441143 t_arch = kMCDeployArchitecture_ARMV7 ;
1145- else if (p_header . cputype == CPU_TYPE_ARM && p_header . cpusubtype == CPU_SUBTYPE_ARM_V7S)
1144+ else if (p_type == CPU_TYPE_ARM && p_subtype == CPU_SUBTYPE_ARM_V7S)
11461145 t_arch = kMCDeployArchitecture_ARMV7S ;
1147- else if (p_header . cputype == CPU_TYPE_ARM64)
1146+ else if (p_type == CPU_TYPE_ARM64)
11481147 t_arch = kMCDeployArchitecture_ARM64 ;
1149- else if (p_header . cputype == CPU_TYPE_POWERPC)
1148+ else if (p_type == CPU_TYPE_POWERPC)
11501149 t_arch = kMCDeployArchitecture_PPC ;
1151- else if (p_header . cputype == CPU_TYPE_POWERPC64)
1150+ else if (p_type == CPU_TYPE_POWERPC64)
11521151 t_arch = kMCDeployArchitecture_PPC64 ;
11531152 else
11541153 t_arch = kMCDeployArchitecture_Unknown ;
11551154
1155+ return t_arch;
1156+ }
1157+
1158+ static bool MCDeployToMacOSXFetchMinOSVersion (const MCDeployParameters& p_params, mach_header& p_header, uint32_t & r_version)
1159+ {
1160+ // First work out what DeployArchitecture to look for.
1161+ MCDeployArchitecture t_arch;
1162+ t_arch = MCDeployMachArchToDeployArchitecture (p_header.cputype , p_header.cpusubtype );
1163+
11561164 // Search for both the architecture in the mach header and for the 'unknown'
11571165 // architecture. If the real arch is found, then we use that version; otherwise
11581166 // if there is an unknown arch then we use that version. If neither are found we
@@ -1850,56 +1858,86 @@ static bool MCDeployToMacOSXFat(const MCDeployParameters& p_params, bool p_embed
18501858 t_output_offset = sizeof (fat_header);
18511859
18521860 // The fat_arch structures follow the fat header directly
1853- uint32_t t_header_offset ;
1854- t_header_offset = sizeof (fat_header);
1861+ uint32_t t_header_read_offset, t_header_write_offset ;
1862+ t_header_read_offset = t_header_write_offset = sizeof (fat_header);
18551863
18561864 // Loop through all the fat headers.
1865+ uint32_t t_slice_count = 0 ;
18571866 for (uint32_t i = 0 ; i < t_fat_header . nfat_arch && t_success; i++)
18581867 {
18591868 fat_arch t_fat_arch;
1860- if (!MCDeployFileReadAt (p_engine, &t_fat_arch, sizeof (fat_arch), t_header_offset ))
1869+ if (!MCDeployFileReadAt (p_engine, &t_fat_arch, sizeof (fat_arch), t_header_read_offset ))
18611870 t_success = MCDeployThrow (kMCDeployErrorMacOSXBadHeader );
18621871
1863- uint32_t t_last_output_offset;
1864- if (t_success)
1865- {
1872+ // Ensure the header has the appropriate byte order
1873+ if (t_success)
18661874 swap_fat_arch (true , t_fat_arch);
1867-
1868- // Round the end of the last engine up to the nearest page boundary.
1869- t_output_offset = (t_output_offset + ((1 << t_fat_arch . align))) & ~((1 << t_fat_arch . align) - 1 );
1870-
1871- // Record the end of the last engine.
1872- t_last_output_offset = t_output_offset;
1873-
1874- // Write out this arch's portion.
1875- if (!p_embedded)
1876- t_success = MCDeployToMacOSXMain (p_params, false , p_engine, t_fat_arch . offset, t_fat_arch . size, t_output_offset, p_output, p_validate_header_callback);
1877- #if 0
1878- else
1879- t_success = MCDeployToMacOSXEmbedded(p_params, false, p_engine, 0, 0, t_output_offset, p_output);
1880- #endif
1881- }
1882-
1883- if (t_success)
1884- {
1885- // Update the fat header.
1886- t_fat_arch . offset = t_last_output_offset;
1887- t_fat_arch . size = t_output_offset - t_last_output_offset;
1888-
1889- // Put it back to network byte order.
1890- swap_fat_arch (true , t_fat_arch);
1891-
1892- // Write out the header.
1893- t_success = MCDeployFileWriteAt (p_output, &t_fat_arch, sizeof (t_fat_arch), t_header_offset);
1894- }
1875+
1876+ // Is this slice for an architecture we want to keep?
1877+ bool t_want_slice = true ;
1878+ if (t_success && p_params.architectures .Size () > 0 )
1879+ {
1880+ // Get the architecture for this slice and check whether it is
1881+ // in the list of desired slices or not
1882+ t_want_slice = false ;
1883+ MCDeployArchitecture t_arch = MCDeployMachArchToDeployArchitecture (t_fat_arch.cputype , t_fat_arch.cpusubtype );
1884+ for (uindex_t j = 0 ; j < p_params.architectures .Size (); j++)
1885+ {
1886+ if (p_params.architectures [j] == t_arch)
1887+ {
1888+ t_want_slice = true ;
1889+ break ;
1890+ }
1891+ }
1892+ }
1893+
1894+ // Do we want to keep this architecture?
1895+ if (t_want_slice)
1896+ {
1897+ uint32_t t_last_output_offset;
1898+ if (t_success)
1899+ {
1900+ // Round the end of the last engine up to the nearest page boundary.
1901+ t_output_offset = (t_output_offset + ((1 << t_fat_arch . align))) & ~((1 << t_fat_arch . align) - 1 );
1902+
1903+ // Record the end of the last engine.
1904+ t_last_output_offset = t_output_offset;
1905+
1906+ // Write out this arch's portion.
1907+ if (!p_embedded)
1908+ t_success = MCDeployToMacOSXMain (p_params, false , p_engine, t_fat_arch . offset, t_fat_arch . size, t_output_offset, p_output, p_validate_header_callback);
1909+ #if 0
1910+ else
1911+ t_success = MCDeployToMacOSXEmbedded(p_params, false, p_engine, 0, 0, t_output_offset, p_output);
1912+ #endif
1913+ }
1914+
1915+ if (t_success)
1916+ {
1917+ // Update the fat header.
1918+ t_fat_arch . offset = t_last_output_offset;
1919+ t_fat_arch . size = t_output_offset - t_last_output_offset;
1920+
1921+ // Put it back to network byte order.
1922+ swap_fat_arch (true , t_fat_arch);
1923+
1924+ // Write out the header.
1925+ t_success = MCDeployFileWriteAt (p_output, &t_fat_arch, sizeof (t_fat_arch), t_header_write_offset);
1926+ }
1927+
1928+ // We've written another slice
1929+ t_slice_count++;
1930+ t_header_write_offset += sizeof (fat_arch);
1931+ }
18951932
1896- t_header_offset += sizeof (fat_arch);
1933+ t_header_read_offset += sizeof (fat_arch);
18971934 }
18981935
18991936 // Final step is to update the fat header.
19001937 if (t_success)
19011938 {
1902- swap_fat_header (true , t_fat_header);
1939+ t_fat_header.nfat_arch = t_slice_count;
1940+ swap_fat_header (true , t_fat_header);
19031941 t_success = MCDeployFileWriteAt (p_output, &t_fat_header, sizeof (t_fat_header), 0 );
19041942 }
19051943 }
@@ -1913,7 +1951,8 @@ static bool MCDeployValidateMacEngine(const MCDeployParameters& p_params, mach_h
19131951{
19141952 // Check the CPU type is PowerPC or X86
19151953 if (p_header . cputype != CPU_TYPE_POWERPC &&
1916- p_header . cputype != CPU_TYPE_X86)
1954+ p_header . cputype != CPU_TYPE_X86 &&
1955+ p_header . cputype != CPU_TYPE_X86_64)
19171956 return MCDeployThrow (kMCDeployErrorMacOSXBadCpuType );
19181957
19191958 // Check that Cocoa is one of the libraries linked to
0 commit comments