diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..f0817e988 --- /dev/null +++ b/.clang-format @@ -0,0 +1,80 @@ + +###################### +# clang-format options +###################### + +# #### +# NOTE: The IOCCC style is somewhat similar to the Linux Kernel style +# +# See: https://clang.llvm.org/docs/ClangFormatStyleOptions.html +# +# NOTE: Linux Kernel style differences will be noted in comments below, with +# the Kernel style setting noted in a "Kernel style uses:" comment. +# #### + +# A style complying with the LLVM coding standards +# +# See: https://llvm.org/docs/CodingStandards.html#include-style +# +BasedOnStyle: LLVM + +# Never put short ifs on the same line +# +AllowShortIfStatementsOnASingleLine: false + +# Use the same indentation level as for the switch statement +# +IndentCaseLabels: false + +# Always attach braces to surrounding context +# +BreakBeforeBraces: Linux + +# The number of columns to use for indentation +# +# Kernel style uses: IndentWidth: 8 +# +IndentWidth: 4 + +# Never use tab to indent +# +# Kernel style uses: UseTab: Always +# +UseTab: Never + +# Align escaped newlines as far left as possible, using the last line of the +# preprocessor directive as the reference if it’s the longest. +# +# Kernel style uses: AlignEscapedNewlines: Right +# +AlignEscapedNewlines: LeftWithLastLine + +# The column limit +# +# Kernel style uses: ColumnLimit: 80 +# +ColumnLimit: 131 + +# The number of columns to use for indentation of preprocessor statements +# +# NOTE: When set to -1 (default) IndentWidth is used also for preprocessor statements. +# +# Kernel style uses: PPIndentWidth: -1 +# +PPIndentWidth: 2 + +# Indents directives after the hash +# +# Kernel style uses: IndentPPDirectives: None +# +IndentPPDirectives: AfterHash + +# Insert braces after control statements (if, else, for, do, and while) in +# +# Kernel style uses: InsertBraces: false +# +# WARNING: Setting this option to true could lead to incorrect code formatting due to clang-format’s +# lack of complete semantic information. As such, extra care should be taken to review code +# changes made by this option! +# +InsertBraces: true diff --git a/1337.mk b/1337.mk index 483154ec3..a9293d0b2 100644 --- a/1337.mk +++ b/1337.mk @@ -3,44 +3,27 @@ # extended utility rules ######################## -.PHONY: indent_clean indent_clobber install - -# you may be able to misunderstand the source by reading indent.c -# -indent.c: ${PROG}.c - @if which "${GINDENT}" >/dev/null 2>&1; then \ - echo ${RM} -f $@; \ - ${RM} -f $@; \ - echo "${GINDENT} < $< > $@"; \ - ${GINDENT} < $< > $@; \ - elif which "${INDENT}" >/dev/null 2>&1; then \ - echo ${RM} -f $@; \ - ${RM} -f $@; \ - echo "${INDENT} < $< > $@"; \ - ${INDENT} < $< > $@; \ - else \ - echo "no indent tool found, ident $< yourself, sorry"; \ - echo "exit 17"; \ - exit 17; \ - fi - -indent_clean: clean - @-if [ -f indent.c ]; then \ - echo ${RM} -f indent.c; \ - ${RM} -f indent.c; \ - fi - -indent_clobber: indent_clean clobber - @-if [ -e sandwich ]; then \ - ${RM} -f sandwich; \ - echo 'ate sandwich'; \ - fi - install: @echo "Dr. Spock says that is not logical!" @${TRUE} +###################### +# clang-format options +###################### + +.PHONY: clang-format + +# NOTE: The IOCCC Judges set CLANG_FORMAT_STYLE according to the ".clang-format" file. +# +# https://github.com/ioccc-src/winner/blob/master/.clang-format +# +# NOTE: Please don't add "// clang-format off" to your code: that is both annoying, and is easily disabled. +# +clang-format: ${PROG}.c + ${CLANG_FORMAT} -style=file ${PROG}.c + + ##################### # make a difference # ##################### diff --git a/var.mk b/var.mk index a641a8763..7b2eec456 100644 --- a/var.mk +++ b/var.mk @@ -39,6 +39,7 @@ CHGRP= chgrp CHMOD= chmod CKSUM= cksum CLANG= clang +CLANG_FORMAT= clang-format CLANG_PLUSPLUS= clang++ CLEAR= clear CMP= cmp