MCPcopy Create free account
hub / github.com/bfbbdecomp/bfbb / c_build

Function c_build

tools/project.py:875–964  ·  view source on GitHub ↗
(obj: Object, src_path: Path)

Source from the content-addressed store, hash-verified

873 source_added: Set[Path] = set()
874
875 def c_build(obj: Object, src_path: Path) -> Optional[Path]:
876 # Avoid creating duplicate build rules
877 if obj.src_obj_path is None or obj.src_obj_path in source_added:
878 return obj.src_obj_path
879 source_added.add(obj.src_obj_path)
880
881 cflags = obj.options["cflags"]
882 extra_cflags = obj.options["extra_cflags"]
883
884 # Add appropriate language flag if it doesn't exist already
885 # Added directly to the source so it flows to other generation tasks
886 if not any(flag.startswith("-lang") for flag in cflags) and not any(
887 flag.startswith("-lang") for flag in extra_cflags
888 ):
889 # Ensure extra_cflags is a unique instance,
890 # and insert into there to avoid modifying shared sets of flags
891 extra_cflags = obj.options["extra_cflags"] = list(extra_cflags)
892 if file_is_cpp(src_path):
893 extra_cflags.insert(0, "-lang=c++")
894 else:
895 extra_cflags.insert(0, "-lang=c")
896
897 all_cflags = cflags + extra_cflags
898 cflags_str = make_flags_str(all_cflags)
899 used_compiler_versions.add(obj.options["mw_version"])
900
901
902 # Add MWCC build rule
903 fakerule = "mwcc_sjis" if obj.options["shift_jis"] else "mwcc"
904 fakeimplicit = mwcc_sjis_implicit if obj.options["shift_jis"] else mwcc_implicit
905 if ("prodg" in obj.options["mw_version"].lower()):
906 fakerule = "prodg"
907 fakeimplicit = ngccc_implicit
908 lib_name = obj.options["lib"]
909 n.comment(f"{obj.name}: {lib_name} (linked {obj.completed})")
910 n.build(
911 outputs=obj.src_obj_path,
912 rule=fakerule,
913 inputs=src_path,
914 variables={
915 "mw_version": Path(obj.options["mw_version"]),
916 "cflags": cflags_str,
917 "basedir": os.path.dirname(obj.src_obj_path),
918 "basefile": obj.src_obj_path.with_suffix(""),
919 },
920 implicit=(
921 fakeimplicit
922 ),
923 order_only="pre-compile",
924 )
925
926 # Add ctx build rule
927 if obj.ctx_path is not None:
928 include_dirs = []
929 for flag in all_cflags:
930 if (
931 flag.startswith("-i ")
932 or flag.startswith("-I ")

Callers 1

add_unitFunction · 0.85

Calls 8

file_is_cppFunction · 0.85
make_flags_strFunction · 0.85
file_is_cFunction · 0.85
addMethod · 0.80
insertMethod · 0.80
commentMethod · 0.80
buildMethod · 0.80
newlineMethod · 0.80

Tested by

no test coverage detected