CONTRIBUTING: describe the C code style
Fixes:
@@ -42,6 +42,7 @@ Before submitting a PR, we suggest you could take a look at the PR rules here.
- [Workspace Preparation](#workspace-preparation)
- [Branch Definition](#branch-definition)
+- [Format C Codes](#format-c-codes)
- [Commit Rules](#commit-rules)
- [PR Description](#pr-description)
@@ -74,6 +75,41 @@ With above, we can easily synchronize local branches with upstream branches.
Right now we assume every contribution via pull request is for the `master` branch in Inclavare Containers. There are several other branches such as rc branches, release branches and backport branches. Before officially releasing a version, we may checkout a rc (release candidate) branch for more testings. When officially releasing a version, there may be a release branch before tagging which will be deleted after tagging. When backporting some fixes to existing released version, we will checkout backport branches.
+### Format C Codes
+
+Inclavare Containers project uses `indent` to format C codes.
+
+1. Install `indent`. Please make sure the version of `indent` must be 2.2.12 or higher to get advanced features.
+
+```shell
+wget -c https://https://ftp.gnu.org/gnu/indent/indent-2.2.12.tar.gz
+tar xzf indent-2.2.12.tar.gz
+cd indent-2.2.12
+./configure
+make
+sudo make install
+```
+
+2. Format C code style using the following command:
+
+```shell
+indent -npro -linux -il-8 -ppi2 -nbbo -ci0 -cs -cp1 -gts foo.c
+```
+
+However, `indent` might generate unexpected results sometimes due to its limitation. For example, `indent` will completely destroy the indentation of the inline assembly because it does not recognize the syntax of inline assembly codes.
+
+To avoid this problem, you need to temporarily disable formatting with [the pair of control comment](https://www.gnu.org/software/indent/manual/indent.html#SEC13), e.g, forbidding formatting the following inline assembly codes.
+
+```shell
+/* *INDENT-OFF* */
+asm volatile(".byte 0x0f,0x01,0xd0" /* xgetbv */
+ : "=a" (eax), "=d" (edx)
+ : "c" (index));
+/* *INDENT-ON* */
+```
+
+Please refer to [this manual](https://www.gnu.org/software/indent/manual/indent.html) for the details about the options of `indent`.
+
### Commit Rules
#### Commit Message
