@@ -1809,6 +1809,31 @@ fn add_v3_tcc_compat_defines(mut user_defines []string, target_os string, target
18091809 }
18101810}
18111811
1812+ struct V3TccResourceFlags {
1813+ install_dir string
1814+ base_arg string
1815+ include_arg string
1816+ library_arg string
1817+ }
1818+
1819+ fn v3_tcc_resource_flags (vroot string ) V3 TccResourceFlags {
1820+ tcc_root_dir := os.join_path (vroot, 'thirdparty' , 'tcc' )
1821+ tcc_lib_dir := os.join_path_single (tcc_root_dir, 'lib' )
1822+ tcc_nested_dir := os.join_path_single (tcc_lib_dir, 'tcc' )
1823+ install_dir := if os.is_dir (tcc_nested_dir) { tcc_nested_dir } else { tcc_lib_dir }
1824+ mut include_dir := os.join_path_single (install_dir, 'include' )
1825+ tcc_root_include_dir := os.join_path_single (tcc_root_dir, 'include' )
1826+ if ! os.is_dir (include_dir) && os.is_dir (tcc_root_include_dir) {
1827+ include_dir = tcc_root_include_dir
1828+ }
1829+ return V3 TccResourceFlags{
1830+ install_dir: install_dir
1831+ base_arg: '-B${install_dir }'
1832+ include_arg: '-I${include_dir }'
1833+ library_arg: '-L${install_dir }'
1834+ }
1835+ }
1836+
18121837fn v3_c_compiler_flag_plan (options V3 CCompilerFlagOptions) V3 CCompilerFlagPlan {
18131838 mut before_inputs := options.environment_c_flags.clone ()
18141839 before_inputs << options.target_args
@@ -1822,9 +1847,9 @@ fn v3_c_compiler_flag_plan(options V3CCompilerFlagOptions) V3CCompilerFlagPlan {
18221847 }
18231848 mut tcc_includes := ''
18241849 if options.explicit_tcc {
1825- tcc_lib_dir := os. join_path (options.vroot, 'thirdparty' , 'tcc' , 'lib' )
1826- tcc_includes = '-I${ os . join_path_single ( tcc_lib_dir , ' include ')}'
1827- before_inputs << [tcc_includes, '-L${ tcc_lib_dir }' ]
1850+ tcc_resources := v3_tcc_resource_flags (options.vroot)
1851+ tcc_includes = tcc_resources.include_arg
1852+ before_inputs << [tcc_resources.base_arg, tcc_resources.include_arg, tcc_resources.library_arg ]
18281853 if v3_tcc_backtrace_enabled (options.target_os, options.target_arch, options.is_shared) {
18291854 before_inputs << '-bt25'
18301855 }
@@ -9657,11 +9682,9 @@ pub fn run(args []string) {
96579682 tried_tcc = true
96589683 tcc_dir := os.join_path_single (os.join_path_single (prefs.vroot, 'thirdparty' ), 'tcc' )
96599684 tcc_path := os.join_path_single (tcc_dir, 'tcc.exe' )
9660- tcc_lib_dir := os.join_path_single (tcc_dir, 'lib' )
9661- tcc_includes := '-I${os .join_path_single (tcc_lib_dir , 'include ')}'
9662- tcc_lib := '-L${tcc_lib_dir }'
9663- mut tcc_args := [c_standard, tcc_includes, tcc_lib, '-w' ,
9664- '-Werror=implicit-function-declaration' ]
9685+ tcc_resources := v3_tcc_resource_flags (prefs.vroot)
9686+ mut tcc_args := [c_standard, tcc_resources.base_arg, tcc_resources.include_arg,
9687+ tcc_resources.library_arg, '-w' , '-Werror=implicit-function-declaration' ]
96659688 if v3_tcc_backtrace_enabled (prefs.normalized_target_os (),
96669689 prefs.normalized_target_arch (), is_shared)
96679690 {
@@ -9672,7 +9695,7 @@ pub fn run(args []string) {
96729695 }
96739696 tcc_args << tcc_cached_main_flags (resolved_c_flags)
96749697 tcc_args << ['-o' , 'out' , os.base (tcc_main_file)]
9675- atomic_s := tcc_atomic_arg (prefs, tcc_path, tcc_includes )
9698+ atomic_s := tcc_atomic_arg (prefs, tcc_path, tcc_resources.include_arg )
96769699 if atomic_s.len > 0 {
96779700 tcc_args << atomic_s
96789701 }
@@ -9689,7 +9712,7 @@ pub fn run(args []string) {
96899712 }}'
96909713 tcc_cached_executable := v3_cached_tcc_executable_path (& cache_state.manager,
96919714 program_source_identity, c_object_cache_stats.link_plan_signature, tcc_path,
9692- tcc_lib_dir , tcc_args)
9715+ tcc_resources.install_dir , tcc_args)
96939716 if os.is_file (tcc_cached_executable) {
96949717 os.cp (tcc_cached_executable, cc_out) or {}
96959718 tcc_cache_hit = os.is_file (cc_out)
@@ -9732,17 +9755,15 @@ pub fn run(args []string) {
97329755 } else {
97339756 bundled_tcc_path
97349757 }
9735- tcc_lib_dir := os.join_path_single (tcc_dir, 'lib' )
9736- tcc_includes := '-I${os .join_path_single (tcc_lib_dir , 'include ')}'
9737- tcc_lib := '-L${tcc_lib_dir }'
9758+ tcc_resources := v3_tcc_resource_flags (prefs.vroot)
97389759 mut tcc_args := environment_c_flags.clone ()
97399760 if link_c_standard.len > 0 {
97409761 tcc_args << link_c_standard
97419762 }
97429763 if pic_flag.len > 0 {
97439764 tcc_args << pic_flag
97449765 }
9745- tcc_args << [tcc_includes, tcc_lib ]
9766+ tcc_args << [tcc_resources.base_arg, tcc_resources.include_arg, tcc_resources.library_arg ]
97469767 if v3_tcc_backtrace_enabled (prefs.normalized_target_os (),
97479768 prefs.normalized_target_arch (), is_shared)
97489769 {
@@ -9760,7 +9781,7 @@ pub fn run(args []string) {
97609781 'src.c'
97619782 }
97629783 tcc_args << ['-o' , 'out' , tcc_source]
9763- atomic_s := tcc_atomic_arg (prefs, tcc_path, tcc_includes )
9784+ atomic_s := tcc_atomic_arg (prefs, tcc_path, tcc_resources.include_arg )
97649785 if atomic_s.len > 0 {
97659786 tcc_args << atomic_s
97669787 }
0 commit comments