diff --git a/share/machdeps/machdep-schema.json b/share/machdeps/machdep-schema.json index ccb08477a96726c63bd79c33c385864667d45bd6..378e1dfa11125fea5f4a59f91ca8ae8904568671 100644 --- a/share/machdeps/machdep-schema.json +++ b/share/machdeps/machdep-schema.json @@ -13,7 +13,8 @@ }, "cpp_arch_flags": { "description": "arguments to be given to the compiler when this machdep is selected (e.g. '-m32')", - "type" : "string" + "type" : "array", + "items" : { "type": "string" } }, "sizeof_short": { "description": "size of 'short' type", diff --git a/share/machdeps/machdep_avr_16.json b/share/machdeps/machdep_avr_16.json index 327f9bc286ff307624ef82b0261e5ab0e23e5c80..785839a0b5add87321632c1beadf9e467d6812ba 100644 --- a/share/machdeps/machdep_avr_16.json +++ b/share/machdeps/machdep_avr_16.json @@ -12,7 +12,11 @@ "alignof_str": 1, "char_is_unsigned": false, "compiler": "clang", - "cpp_arch_flags": "-target avr -m16", + "cpp_arch_flags": [ + "-target", + "avr", + "-m16" + ], "has__builtin_va_list": true, "little_endian": true, "ptrdiff_t": "int", diff --git a/share/machdeps/machdep_gcc_x86_16.json b/share/machdeps/machdep_gcc_x86_16.json index d6dc63d3c14ec34049698ce595d345ebd50f3317..bc6a35bddbb5866394df362a559e2a88a108e802 100644 --- a/share/machdeps/machdep_gcc_x86_16.json +++ b/share/machdeps/machdep_gcc_x86_16.json @@ -12,7 +12,7 @@ "alignof_str": 1, "char_is_unsigned": false, "compiler": "gcc", - "cpp_arch_flags": "-m16", + "cpp_arch_flags": ["-m16"], "has__builtin_va_list": true, "little_endian": true, "ptrdiff_t": "int", diff --git a/share/machdeps/machdep_gcc_x86_32.json b/share/machdeps/machdep_gcc_x86_32.json index ac118c16125b327e27db9333372aa98d5f01af0a..f7030722574f21f0cdc1f6eca07b500af6ebc6f6 100644 --- a/share/machdeps/machdep_gcc_x86_32.json +++ b/share/machdeps/machdep_gcc_x86_32.json @@ -12,7 +12,9 @@ "alignof_str": 1, "char_is_unsigned": false, "compiler": "gcc", - "cpp_arch_flags": "-m32", + "cpp_arch_flags": [ + "-m32" + ], "has__builtin_va_list": true, "little_endian": true, "ptrdiff_t": "int", diff --git a/share/machdeps/machdep_gcc_x86_64.json b/share/machdeps/machdep_gcc_x86_64.json index 40a9f3a209ea06ae566bf6d907b111b7b898f950..28932cf951bc1b450440051556acb49b49aa1c66 100644 --- a/share/machdeps/machdep_gcc_x86_64.json +++ b/share/machdeps/machdep_gcc_x86_64.json @@ -12,8 +12,10 @@ "alignof_str": 1, "char_is_unsigned": false, "compiler": "gcc", - "cpp_arch_flags": "-m64", - "has__builtin_va_list": false, + "cpp_arch_flags": [ + "-m64" + ], + "has__builtin_va_list": true, "little_endian": true, "ptrdiff_t": "long", "size_t": "unsigned long", diff --git a/share/machdeps/machdep_ppc_32.json b/share/machdeps/machdep_ppc_32.json index de712c039d3e0884e9f29d560bb0d63a960c93a5..1a47569605b0d7a6e86e30bb12a814b3b82ec7d3 100644 --- a/share/machdeps/machdep_ppc_32.json +++ b/share/machdeps/machdep_ppc_32.json @@ -12,7 +12,11 @@ "alignof_str": 1, "char_is_unsigned": false, "compiler": "clang", - "cpp_arch_flags": "-target powerpc-apple-darwin -mcpu=603", + "cpp_arch_flags": [ + "-target", + "powerpc-apple-darwin", + "-mcpu=603" + ], "has__builtin_va_list": false, "little_endian": false, "ptrdiff_t": "int", diff --git a/share/machdeps/machdep_x86_16.json b/share/machdeps/machdep_x86_16.json index 100978d6a5635c9bebad6e596552f01707865e0b..59eff226c3e236b734e88d13561881002f5c9910 100644 --- a/share/machdeps/machdep_x86_16.json +++ b/share/machdeps/machdep_x86_16.json @@ -12,7 +12,7 @@ "alignof_str": 1, "char_is_unsigned": false, "compiler": "generic", - "cpp_arch_flags": "-m16", + "cpp_arch_flags": [ "-m16" ], "has__builtin_va_list": true, "little_endian": true, "ptrdiff_t": "int", diff --git a/share/machdeps/machdep_x86_32.json b/share/machdeps/machdep_x86_32.json index f0165c1d03e36aa49b193bb29f38dc33d500f6aa..44d776d1d3fe7dbef0e2bf75bac6f89dfed3cb4a 100644 --- a/share/machdeps/machdep_x86_32.json +++ b/share/machdeps/machdep_x86_32.json @@ -12,7 +12,9 @@ "alignof_str": 1, "char_is_unsigned": false, "compiler": "generic", - "cpp_arch_flags": "-m32", + "cpp_arch_flags": [ + "-m32" + ], "has__builtin_va_list": true, "little_endian": true, "ptrdiff_t": "int", diff --git a/share/machdeps/make_machdep/make_machdep.py b/share/machdeps/make_machdep/make_machdep.py index f3e922f099c207553217dd174aee6173d81e10b2..810acc91eb8719bcfd81dfe1c815176aef76cc9c 100755 --- a/share/machdeps/make_machdep/make_machdep.py +++ b/share/machdeps/make_machdep/make_machdep.py @@ -69,6 +69,17 @@ parser.add_argument( default="--version", help="option to pass to the compiler to obtain its version; default is --version", ) + +parser.add_argument( + "--from-file", + help="reads compiler and arch flags from existing json file. Use -i to update it in place" +) +parser.add_argument( + "-i", "--in-place", + action="store_true", + help="when reading compiler config from json, update the file in place. unused otherwise" +) + parser.add_argument( "--cpp-arch-flags", nargs="+", @@ -90,10 +101,23 @@ if not args.compiler_flags: args.compiler_flags = ["-c"] +if args.from_file: + orig_file = open(args.from_file,"r") + orig_machdep = json.load(orig_file) + orig_file.close() + if not "compiler" in orig_machdep or not "cpp_arch_flags" in orig_machdep: + raise Exception("Missing fields in json file") + args.compiler = orig_machdep["compiler"] + if isinstance(orig_machdep["cpp_arch_flags"],list): + args.cpp_arch_flags = orig_machdep["cpp_arch_flags"] + else: # old version of the schema used a single string + args.cpp_arch_flags = orig_machdep["cpp_arch_flags"].split() + def print_machdep(machdep): + if args.in_place: + args.dest_file = open(args.from_file,"w") json.dump(machdep, args.dest_file, indent=4, sort_keys=True) - def check_machdep(machdep): try: from jsonschema import validate, ValidationError @@ -238,7 +262,7 @@ version_output = subprocess.run( version = version_output.stdout.splitlines()[0] machdep["compiler"] = args.compiler -machdep["cpp_arch_flags"] = " ".join(args.cpp_arch_flags) +machdep["cpp_arch_flags"] = args.cpp_arch_flags machdep["version"] = version missing_fields = [f for [f, v] in machdep.items() if v is None]