Bulk of the changes is done by applying an awk script using
admin/reformat_all.sh --filter=copyright \
--pattern=src/\*.{cpp,cu,c} list-files | xargs add_gmxpre.h
where add_gmxpre.h contains
#!/bin/bash
for f in "$@" ; do
awk 'BEGIN {add=1}
/gmxpre\.h/ {add=0}
/#include/ {if (add) print "#include \"gmxpre.h\"\n"; add=0}
{print}' $f >$f.tmp
mv $f.tmp $f
done
In other words, by adding a gmxpre.h include before the first #include
statement.
Manual changes on top of that:
- Adapt reformat_all.sh to support the --pattern option used above.
- Manually edit the files directly under src/ to move some necessary
defines from config.h to gmxpre.h, and to adapt the build system to
generate the latter.
- Move the inserted include outside the HAVE_CONFIG_H #ifdef in
gmx_cpuid.c.
- Adapt nbnxn kernel generator files to insert the #include at the
proper place and regenerate the kernels.
- Adapt group kernel generators to insert the #include at the proper
place, and remove unnecessary include guards from generated _source_
files.
Adaptation for scanner.l and parser.y in the selection code will come
later, together with a checker that checks that gmxpre.h is actually
included everywhere.
Motivation for the change is documented in the file comment for
gmxpre.h. This file could potentially be used also for precompiled
headers to speed up the build, but that would require a lot more effort
than this...