1 # Build settings based on the upstream Xcode project.
2 # See: https://github.com/apple-oss-distributions/cctools/blob/main/cctools.xcodeproj/project.pbxproj
12 '-DCCTB_PROJECT=cctools',
13 '-DCCTB_PROJVERS=cctools-@version@',
14 '-DCCTB_VERSION=@version@',
15 '-DCURRENT_PROJECT_VERSION="@version@"',
16 '-DCODEDIRECTORY_SUPPORT',
25 target_prefix = get_option('target_prefix')
29 cc = meson.get_compiler('c')
31 libcodedirectory = cc.find_library('codedirectory')
32 libprunetrie = cc.find_library('prunetrie')
36 # Add compatibility header for Darwin SDKs that don’t define `utimensat`.
40 int main(int argc, char* argv[]) {
41 utimensat(AT_FDCWD, NULL, NULL, 0);
45 if host_machine.system() == 'darwin' and not cc.compiles(utimensat_test, name : 'supports utimensat')
46 add_project_arguments('-include', 'compat.h', language : 'c')
47 add_project_link_arguments('-undefined', 'dynamic_lookup', language : 'c')
51 incdirs = include_directories('include')
54 libstuff = static_library(
57 '-DCPU_TYPE_RISCV32=24', # Per src/abstraction/MachOFileAbstraction.hpp from ld64
59 include_directories : [incdirs, 'include/stuff'],
63 'libstuff/allocate.c',
64 'libstuff/apple_version.c',
66 'libstuff/arch_usage.c',
68 'libstuff/best_arch.c',
69 'libstuff/breakout.c',
71 'libstuff/checkout.c',
72 'libstuff/code_directory.c',
73 'libstuff/coff_bytesex.c',
76 'libstuff/diagnostics.c',
77 'libstuff/dylib_roots.c',
78 'libstuff/dylib_table.c',
81 'libstuff/fatal_arch.c',
83 'libstuff/get_arch_from_host.c',
84 'libstuff/get_toc_byte_sex.c',
85 'libstuff/guess_short_name.c',
86 'libstuff/hash_string.c',
90 'libstuff/macosx_deployment_target.c',
92 'libstuff/ofile_error.c',
93 'libstuff/ofile_get_word.c',
97 'libstuff/seg_addr_table.c',
98 'libstuff/set_arch_flag_name.c',
99 'libstuff/swap_headers.c',
100 'libstuff/symbol_list.c',
101 'libstuff/unix_standard_mode.c',
102 'libstuff/version_number.c',
103 'libstuff/vm_flush_cache.c',
104 'libstuff/write64.c',
105 'libstuff/writeout.c',
110 libstuff_otool = static_library(
113 '-DCPU_TYPE_RISCV32=24', # Per src/abstraction/MachOFileAbstraction.hpp from ld64
115 include_directories : [incdirs, 'include/stuff', 'otool'],
119 'libstuff/allocate.c',
120 'libstuff/apple_version.c',
122 'libstuff/arch_usage.c',
124 'libstuff/best_arch.c',
125 'libstuff/breakout.c',
126 'libstuff/bytesex.c',
127 'libstuff/checkout.c',
128 'libstuff/code_directory.c',
129 'libstuff/coff_bytesex.c',
131 'libstuff/depinfo.c',
132 'libstuff/diagnostics.c',
133 'libstuff/dylib_roots.c',
134 'libstuff/dylib_table.c',
136 'libstuff/execute.c',
137 'libstuff/fatal_arch.c',
139 'libstuff/get_arch_from_host.c',
140 'libstuff/get_toc_byte_sex.c',
141 'libstuff/guess_short_name.c',
142 'libstuff/hash_string.c',
146 'libstuff/macosx_deployment_target.c',
148 'libstuff/ofile_error.c',
149 'libstuff/ofile_get_word.c',
153 'libstuff/seg_addr_table.c',
154 'libstuff/set_arch_flag_name.c',
155 'libstuff/swap_headers.c',
156 'libstuff/symbol_list.c',
157 'libstuff/unix_standard_mode.c',
158 'libstuff/version_number.c',
159 'libstuff/vm_flush_cache.c',
160 'libstuff/write64.c',
161 'libstuff/writeout.c',
169 f'@target_prefix@ar',
170 include_directories : incdirs,
172 link_with : [libstuff],
192 f'@target_prefix@gas',
193 include_directories : incdirs,
195 link_with : [libstuff],
196 sources : ['as/driver.c'],
231 include_directories : [
237 install_dir : 'libexec/as/arm',
238 link_with : [libstuff],
239 sources : [as_common, 'as/arm.c'],
242 as_i386 = executable(
251 include_directories : [
257 install_dir : 'libexec/as/i386',
258 link_with : [libstuff],
259 sources : [as_common, 'as/i386.c'],
262 as_x86_64 = executable(
272 include_directories : [
278 install_dir : 'libexec/as/x86_64',
279 link_with : [libstuff],
280 sources : [as_common, 'as/i386.c'],
283 # # ld # excluded because ld64 is built separately
285 bitcode_strip = executable(
286 f'@target_prefix@bitcode_strip',
287 dependencies : [libcodedirectory],
288 include_directories : incdirs,
290 link_with : [libstuff],
291 sources : ['misc/bitcode_strip.c'],
293 install_man('man/bitcode_strip.1')
295 check_dylib = executable(
296 f'@target_prefix@check_dylib',
297 include_directories : incdirs,
299 link_with : [libstuff],
300 sources : ['misc/check_dylib.c'],
302 install_man('man/check_dylib.1')
304 checksyms = executable(
305 f'@target_prefix@checksyms',
306 include_directories : incdirs,
308 link_with : [libstuff],
309 sources : ['misc/checksyms.c'],
311 install_man('man/checksyms.1')
313 cmpdylib = executable(
314 f'@target_prefix@cmpdylib',
315 include_directories : incdirs,
317 link_with : [libstuff],
318 sources : ['misc/cmpdylib.c'],
320 install_man('man/cmpdylib.1')
322 codesign_allocate = executable(
323 f'@target_prefix@codesign_allocate',
324 dependencies : [libcodedirectory],
325 include_directories : incdirs,
327 link_with : [libstuff],
328 sources : ['misc/codesign_allocate.c'],
330 install_man('man/codesign_allocate.1')
332 ctf_insert = executable(
333 f'@target_prefix@ctf_insert',
334 dependencies : [libcodedirectory],
335 include_directories : [incdirs, 'include/stuff'],
337 link_with : [libstuff],
338 sources : ['misc/ctf_insert.c'],
340 install_man('man/ctf_insert.1')
342 depinfo = executable(
343 f'@target_prefix@depinfo',
344 include_directories : incdirs,
346 link_with : [libstuff],
347 sources : ['misc/depinfo.c'],
349 install_man('man/depinfo.1')
351 diagtest = executable(
352 f'@target_prefix@diagtest',
353 include_directories : incdirs,
355 link_with : [libstuff],
356 sources : ['misc/diagtest.c'],
358 install_man('man/diagtest.1')
361 f'@target_prefix@gprof',
362 include_directories : incdirs,
364 link_with : [libstuff],
373 'gprof/printgprof.c',
378 install_man('man/gprof.1')
380 # Not supported on 64-bit architectures
382 # f'@target_prefix@indr',
383 # include_directories : incdirs,
384 # sources : ['misc/indr.c'],
386 # install_man('man/indr.1')
388 install_name_tool = executable(
389 f'@target_prefix@install_name_tool',
390 dependencies : [libcodedirectory],
391 include_directories : incdirs,
393 link_with : [libstuff],
394 sources : ['misc/install_name_tool.c'],
396 install_man('man/install_name_tool.1')
398 libtool = executable(
399 f'@target_prefix@libtool',
400 include_directories : incdirs,
402 link_with : [libstuff],
403 sources : ['misc/libtool.c'],
405 install_man('man/libtool.1')
408 f'@target_prefix@lipo',
409 include_directories : incdirs,
411 link_with : [libstuff],
412 sources : ['misc/lipo.c'],
414 install_man('man/lipo.1')
417 f'@target_prefix@mtoc',
418 include_directories : incdirs,
420 link_with : [libstuff],
421 sources : ['efitools/mtoc.c'],
423 install_man('man/mtoc.1')
426 f'@target_prefix@mtor',
427 include_directories : incdirs,
429 link_with : [libstuff],
430 sources : ['efitools/mtor.c'],
432 install_man('man/mtor.1')
435 f'@target_prefix@nm',
436 include_directories : incdirs,
438 link_with : [libstuff],
439 sources : ['misc/nm.c'],
441 install_man('man/nm-classic.1')
444 f'@target_prefix@nmedit',
445 c_args : ['-DNMEDIT'],
446 dependencies : [libcodedirectory],
447 include_directories : incdirs,
449 link_with : [libstuff],
450 sources : ['misc/strip.c'],
452 install_man('man/nmedit.1')
455 f'@target_prefix@otool',
456 c_args : ['-DEFI_SUPPORT'],
457 include_directories : incdirs,
459 link_with : [libstuff],
461 'otool/arm64_disasm.c',
462 'otool/arm_disasm.c',
463 'otool/coff_print.c',
464 'otool/dyld_bind_info.c',
465 'otool/hppa_disasm.c',
466 'otool/i386_disasm.c',
467 'otool/i860_disasm.c',
468 'otool/m68k_disasm.c',
469 'otool/m88k_disasm.c',
471 'otool/ofile_print.c',
472 'otool/ppc_disasm.c',
473 'otool/print_bitcode.c',
474 'otool/print_objc.c',
475 'otool/print_objc2_32bit.c',
476 'otool/print_objc2_64bit.c',
477 'otool/print_objc2_util.c',
478 'otool/sparc_disasm.c',
481 install_man('man/otool-classic.1')
483 pagestuff = executable(
484 f'@target_prefix@pagestuff',
485 include_directories : incdirs,
487 link_with : [libstuff],
488 sources : ['misc/pagestuff.c'],
490 install_man('man/pagestuff.1')
492 # ranlib is a symlink to libtool
498 redo_prebinding = executable(
499 f'@target_prefix@redo_prebinding',
500 dependencies : [libcodedirectory],
501 include_directories : incdirs,
503 link_with : [libstuff],
504 sources : ['misc/redo_prebinding.c'],
506 install_man('man/redo_prebinding.1')
508 seg_addr_table = executable(
509 f'@target_prefix@seg_addr_table',
510 include_directories : incdirs,
512 link_with : [libstuff],
513 sources : ['misc/seg_addr_table.c'],
515 install_man('man/seg_addr_table.1')
517 seg_hack = executable(
518 f'@target_prefix@seg_hack',
519 dependencies : [libcodedirectory],
520 include_directories : incdirs,
522 link_with : [libstuff],
523 sources : ['misc/seg_hack.c'],
526 segedit = executable(
527 f'@target_prefix@segedit',
528 include_directories : incdirs,
530 link_with : [libstuff],
531 sources : ['misc/segedit.c'],
533 install_man('man/segedit.1',)
536 f'@target_prefix@size',
537 include_directories : incdirs,
539 link_with : [libstuff],
540 sources : ['misc/size.c'],
542 install_man('man/size-classic.1')
544 strings = executable(
545 f'@target_prefix@strings',
546 include_directories : incdirs,
548 link_with : [libstuff],
549 sources : ['misc/strings.c'],
551 install_man('man/strings.1')
554 f'@target_prefix@strip',
555 c_args : ['-DTRIE_SUPPORT'],
556 dependencies : [libcodedirectory, libprunetrie],
557 include_directories : incdirs,
559 link_with : [libstuff],
560 sources : ['misc/strip.c'],
562 install_man('man/strip.1')
565 f'@target_prefix@vtool',
566 dependencies : [libcodedirectory],
567 include_directories : [incdirs, 'include/stuff'],
569 link_with : [libstuff],
570 sources : ['misc/vtool.c'],
572 install_man('man/vtool.1')
577 libmacho = static_library(
579 include_directories : incdirs,
582 'libmacho/get_end.c',
583 'libmacho/getsecbyname.c',
584 'libmacho/getsegbyname.c',
585 'libmacho/hppa_swap.c',
586 'libmacho/i386_swap.c',
587 'libmacho/i860_swap.c',
588 'libmacho/m68k_swap.c',
589 'libmacho/m88k_swap.c',
590 'libmacho/ppc_swap.c',
591 'libmacho/slot_name.c',
592 'libmacho/sparc_swap.c',
597 libredo_prebinding = static_library(
599 c_args : ['-DLIBRARY_API'],
600 include_directories : incdirs,
601 sources : ['misc/redo_prebinding.c'],
603 install_man('man/redo_prebinding.3')
607 # Based on the contents of the upstream SDK.
609 'include/mach-o/arch.h',
610 'include/mach-o/fat.h',
611 'include/mach-o/getsect.h',
612 'include/mach-o/ldsyms.h',
613 'include/mach-o/loader.h',
614 'include/mach-o/nlist.h',
615 'include/mach-o/ranlib.h',
616 'include/mach-o/reloc.h',
617 'include/mach-o/stab.h',
618 'include/mach-o/swap.h',
622 # Some of these architectures are irrelevant, but the Libsystem derivation expects their headers to be present.
623 # Not every arch has both headers, so tailor the lists for each that does.
624 foreach arch : ['arm', 'arm64', 'hppa', 'i860', 'm88k', 'ppc', 'sparc', 'x86_64']
626 f'include/mach-o/@arch@/reloc.h',
627 subdir : f'mach-o/@arch@',
630 foreach arch : ['hppa', 'i386', 'i860', 'm68k', 'm88k', 'ppc', 'sparc']
632 f'include/mach-o/@arch@/swap.h',
633 subdir : f'mach-o/@arch@',
638 'include/modules/mach-o.modulemap',
639 install_dir : get_option('includedir'),
640 rename : 'mach-o/module.map',
645 'man/NSObjectFileImage.3',
646 'man/NSObjectFileImage_priv.3',
651 'man/getsectbyname.3',
652 'man/getsectbynamefromheader.3',
654 'man/getsectdatafromheader.3',
655 'man/getsegbyname.3',