mu/HACKING

131 lines
4.0 KiB
Plaintext
Raw Permalink Normal View History

* HACKING
Here are some guidelines for hacking on the 'mu' source code.
2014-10-19 17:48:48 +02:00
This is a fairly long list -- this is not meant to discourage anyone from
working on mu; I think most of the rules are common sense anyway, and some of
the more stylistic-aesthetic rules are clearly visible in current source code,
so as long as any new code 'fits in', it should go a long way in satisfying
them.
2010-01-06 00:21:28 +01:00
2012-03-24 10:17:11 +01:00
I should add some notes for the Lisp/Scheme code as well...
** Coding style
For consistency and, more important, to keep things understandable, mu
attempts to follow the following rules:
1. Basic code layout is like in the Linux kernel coding style. Keep the '{'
2021-03-17 17:34:24 +01:00
on the same line as the statement, except for functions. We're slowly
moving to use SPC for indentation: all new code should use that.
While TABs are techically better, it seems that using SPCs is harder to
get wrong.
2. Lines should not exceed 100 characters
2021-03-17 17:34:24 +01:00
3. Functions should be kept short.
2021-03-17 17:34:24 +01:00
4. Source files should not exceed 1000 lines, with few exceptions.
5. Non-static C-functions have the prefix based on their module, e.g.,
~mu-foo.h~ declares a function of 'mu_foo_bar (int a);', mu-foo.c implements
2021-03-17 17:34:24 +01:00
this. C++ functions use the Mu namespace
6. Non-global functions *don't* have the module prefix, and are declared
2012-07-24 02:29:34 +02:00
static.
7. Functions have their return type on a separate line before the function
name, so:
#+BEGIN_EXAMPLE
static int
2012-11-18 21:10:05 +01:00
foo (const char *bar)
2010-01-16 14:28:40 +01:00
{
....
}
#+END_EXAMPLE
2010-01-16 14:28:40 +01:00
8. In C code, variable-declarations are at the beginning of a block.
In C code, the declaration does *not* initialize the variable. This will
give the compiler a chance to warn us if the variable is not initialized
2021-03-17 17:34:24 +01:00
in a certain code path. Exception: autoptr & friends.
2021-03-17 17:34:24 +01:00
9. Returned strings of type ~char*~ must be freed by the caller; if they are
not to be freed, ~const char*~ should be used instead
10. Functions calls have a space between function name and arguments, unless
there are none, so:
2010-10-25 23:25:14 +02:00
~foo (12, 3)~;
2010-10-25 23:25:14 +02:00
and
~bar();~
2010-10-25 23:25:14 +02:00
after a comma, a space should follow.
2021-03-17 17:34:24 +01:00
11. C-functions that do not take arguments are explicitly declared as f(void)
and not f(). Reason: f() means that the arguments are /unspecified/ (in C)
12. C-code should not use ~//~ comments.
2012-03-24 10:17:11 +01:00
2010-01-06 00:21:28 +01:00
2014-10-19 17:48:48 +02:00
** Logging
2010-01-06 00:21:28 +01:00
For logging, mu uses the GLib logging functions/macros as listed below,
except when logging may not have been initialized.
2014-10-19 17:48:48 +02:00
The logging system redirects most logging to the log file (typically,
2021-03-17 17:34:24 +01:00
=~/.cache/mu/mu.log, or to the systemd journal=). ~g_critical~ messages are
written to stderr.
2014-10-19 17:48:48 +02:00
- ~g_message~ is for non-error messages the user will see (unless running with
~--quiet~)
- ~g_warning~ is for problems the user may be able to do something about (and
they are written on ~stderr~)
- ~g_critical~ is for mu bugs, serious, internal problems (~g_return_if_fail~ and
friends use this). (and they are written on ~stderr~)
- don't use ~g_error~
2010-01-06 00:21:28 +01:00
** Compiling from git
For hacking, you're strongly advised to use the latest git version.
Compilation from git should be straightforward, if you have the right tools
installed.
2016-12-15 07:18:00 +01:00
*** dependencies
You need to install a few dependencies; e.g. on Debian/Ubuntu:
#+BEGIN_EXAMPLE
2016-12-15 07:18:00 +01:00
sudo apt-get install \
2021-03-17 17:34:24 +01:00
automake \
autoconf-archive \
autotools-dev \
libglib2.0-dev \
2016-12-15 07:18:00 +01:00
libxapian-dev \
libgmime-3.0-dev \
2021-03-17 17:34:24 +01:00
m4 \
make \
libtool \
pkg-config
#+END_EXAMPLE
2016-12-15 07:18:00 +01:00
Then, to compile straight from ~git~:
#+BEGIN_EXAMPLE
2012-03-24 10:17:11 +01:00
$ git clone https://github.com/djcb/mu
2011-07-31 11:59:16 +02:00
$ cd mu
2016-12-15 07:18:00 +01:00
$ ./autogen.sh
$ make
#+END_EXAMPLE
You only need to run ~./autogen.sh~ the first time and after changes in the
build system; otherwise you can use ~./configure~.
2010-10-25 23:25:14 +02:00
# Local Variables:
2012-07-24 02:29:34 +02:00
# mode: org; org-startup-folded: nofold
# fill-column: 80
2010-10-25 23:25:14 +02:00
# End: