On Wed, 3 Aug 2022, Palani kodeswaran wrote: > Hello, > > I am new to coccinelle and am trying to see if it would be possible in coccinelle to add a header file to a source file.  > Our current coccinelle rules change function calls to a different function that is defined in another header file that is not included by default. Would greatly appreciate if someone could point to an example that can accomplish adding header files.  You should be able to do: @@ @@ #include <...> +#include The problem comes if there is no include in your code at the moment. I don't think there is any convenient solution for this at the moment. You could use python to print out that your Coccinelle rule has detected that the header file shold be added, and then add it by hand. Also, the above will not necessarily put the header file at the place where you want it. I don't really remember what strategy it uses. Perhaps it is just put as the last one with the above rule, and as the first one with the following: @@ @@ +#include #include <...> Instead of ... you can also put a file name, if there is a specific file you want the new header to always be before or after. You may also need to make separate rules for the case #include "..." You can give each rule a name, and then ensure that later ones are only run if earlier ones are not used, eg: @r1@ @@ - foo + bar @depends on !r1@ @@ - xxx + yyy julia