{"id":22843449,"url":"https://github.com/milahu/gcc-options-parser","last_synced_at":"2025-03-31T05:12:01.193Z","repository":{"id":109859801,"uuid":"447574466","full_name":"milahu/gcc-options-parser","owner":"milahu","description":"parse command line options for the GCC compiler","archived":false,"fork":false,"pushed_at":"2022-01-20T22:38:44.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-06T09:37:32.965Z","etag":null,"topics":["bash","ccache","code-transformation","gcc","normalization","normalize","options-parser","parse","parser","postprocess","postprocessing","postprocessor","reproducible-builds"],"latest_commit_sha":null,"homepage":"","language":"Mako","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/milahu.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-13T11:30:20.000Z","updated_at":"2022-01-13T18:32:17.000Z","dependencies_parsed_at":"2023-06-19T09:44:40.614Z","dependency_job_id":null,"html_url":"https://github.com/milahu/gcc-options-parser","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milahu%2Fgcc-options-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milahu%2Fgcc-options-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milahu%2Fgcc-options-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milahu%2Fgcc-options-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/milahu","download_url":"https://codeload.github.com/milahu/gcc-options-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246418646,"owners_count":20773938,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","ccache","code-transformation","gcc","normalization","normalize","options-parser","parse","parser","postprocess","postprocessing","postprocessor","reproducible-builds"],"created_at":"2024-12-13T02:14:50.268Z","updated_at":"2025-03-31T05:12:01.187Z","avatar_url":"https://github.com/milahu.png","language":"Mako","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gcc-options-parser\n\nparse command line options for the GCC compiler\n\n\"what would gcc do?\"\n\n## features\n\nwhat can `gcc-options-parser` do?\n\n* parse all gcc \"binary\" options (binary: consume the next argument). in gcc's `*.opt` files, these options have the `Separate` keyword.\n* parse input paths and input languages\n  * gcc's [-x language](https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html) option allows the user to override the input file extension. this setting is applied to all following input files.\n  * with `-x none`, gcc goes back to the default \"parse language from file extension\" mode.\n* parse the output path, if one was set with `-o path` or `-opath` (the `-o` option accepts `Separate` and `Joined` values).\n  * if no output path was set, then gcc will use the default output path `a.out` (at least for C/C++ inputs).\n* TODO? (do we need this? alternative: patch options like `-D`) parse options which are used only for the C/C++ preprocessor ([preprocessor options](https://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html)). these options can be safely removed from the compiler options.\n\n### anti features\n\nwhat will `gcc-options-parser` NOT do?\n\n* validate \"unary\" options (options which do not consume the next argument).\n\n## concept\n\nthe parser is generated from gcc's opt files,\nfor example [gcc/common.opt](https://github.com/gcc-mirror/gcc/blob/master/gcc/common.opt)\n\n## use case\n\nin my use case ([incremental nix-build with ccache](https://nixos.wiki/wiki/CCache)),\ni want to \"normalize\" source code,\nto get more cache hits with `ccache`.\n\nnormalize source code? aka \"reproducible builds\".\n\n* replace variable output paths with constant template strings\n* remove gcc options like `-frandom-seed=somestring`\n\nso i want ...\n\n* insert a code transformer (source postprocessor)\n  * after the C/C++ preprocessor\n  * before the C/C++ compiler\n* insert a binary transformer (binary postprocessor)\n  * after the C/C++ compiler\n\nso, i want to split the compilation into\n\n* multiple preprocessor steps = `gcc -E`, one for every input file\n* multiple \"source postprocessor\" steps = custom code transformer, one for every input file\n* one compile step\n* one \"binary postprocessor\" step, so we need the output path\n\nsolution: a wrapper script for gcc, which understands some gcc options,\nwhich can split the compilation into phases,\nwhich can manipulate the intermediary files.\n\n### example\n\nthe input is something like\n\n```\ngcc -o /out/output.o -frandom-seed=asdf -D PREFIX=/some/variable/path \\\n  -I/tmp/include/ /src/source1.c /src/source2.cc\n```\n\n* patch `-D PREFIX=/some/variable/path` to something constant\n* remove `-frandom-seed=asdf`\n* always set `-frandom-seed=some_constant_string`. we use the output path `/out/output.o`, just like [bazel: `-frandom-seed=%{output_file}`](https://github.com/bazelbuild/bazel/issues/6540).\n* preprocess /src/source1.c to /tmp/source1.i\n* preprocess /src/source2.cc to /tmp/source2.ii\n* postprocess /tmp/source1.i\n* postprocess /tmp/source2.ii\n* compile /tmp/source1.i + /tmp/source2.ii \u0026rarr; /out/output.o\n\n## related\n\n### parse arguments from array\n\n* https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash\n  * https://stackoverflow.com/a/38297066/10440128 \u0026rarr; https://github.com/matejak/argbash cli parser generator\n  * https://stackoverflow.com/a/63413837/10440128 \u0026rarr; https://github.com/ko1nksm/getoptions cli parser generator\n\n### parse arguments from string\n\nhere: parse arguments from file, via [gcc's @file option](https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilahu%2Fgcc-options-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmilahu%2Fgcc-options-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilahu%2Fgcc-options-parser/lists"}