Elly Fong-Jones | 0873b2b | 2022-11-02 19:49:51 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
Avi Drissman | ea62cfa | 2023-01-24 14:57:29 -0500 | [diff] [blame] | 3 | # Copyright 2022 The Chromium Authors |
Elly Fong-Jones | 0873b2b | 2022-11-02 19:49:51 +0000 | [diff] [blame] | 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | """A script to update and tweak nasm's generated configs post-autoconf.""" |
| 7 | |
| 8 | import re |
| 9 | import os |
| 10 | |
| 11 | |
| 12 | def RewriteFile(path, search_replace): |
| 13 | with open(path) as f: |
| 14 | contents = f.read() |
| 15 | with open(path, 'w') as f: |
| 16 | for search, replace in search_replace: |
| 17 | contents = re.sub(search, replace, contents) |
| 18 | |
| 19 | # Cleanup trailing newlines. |
| 20 | f.write(contents.strip() + '\n') |
| 21 | |
| 22 | |
| 23 | def UpdateLinuxConfig(path): |
| 24 | RewriteFile( |
| 25 | path, |
| 26 | [ |
| 27 | # While glibc has canonicalize_file_name(3), other libcs do not, |
| 28 | # and we want the source tree not to depend on glibc if we can avoid it, |
| 29 | # especially for linux distribution tarballs. Since nasm has fallback |
| 30 | # code for not having canonicalize_file_name(3) anyway, just pretend it |
| 31 | # doesn't exist. |
| 32 | (r'#define HAVE_CANONICALIZE_FILE_NAME 1', |
| 33 | r'/* #undef HAVE_CANONICALIZE_FILE_NAME */ // Controlled by the Chromium build process - see generate_nasm_configs.py' |
| 34 | ) |
| 35 | ]) |
| 36 | |
| 37 | |
| 38 | def UpdateMacConfig(path): |
| 39 | pass |
| 40 | |
| 41 | |
| 42 | def main(): |
| 43 | UpdateLinuxConfig('config/config-linux.h') |
| 44 | UpdateMacConfig('config/config-mac.h') |
| 45 | |
| 46 | |
| 47 | if __name__ == "__main__": |
| 48 | main() |