blob: e97efcac7d76ee7b9f5757758f3801ea57e3f7df [file] [log] [blame]
swissChili01ba07f2022-07-03 21:36:42 -07001JMK 2 Build System
2==================
3
4JMK2 is a rewrite of the JMK build system. I am slowly porting
5Bluejay to JMK2 instead of the legacy M4-based JMK build system.
6
7JMK2 is used to generate makefiles for each project in Bluejay. A
8project is a directory with a ``Jmk2`` file (case sensitive). Each
9project produces a single output based on some sources.
10
11The script ``bin/jmk2`` looks in the source tree for ``Jmk2`` files,
12and process each one into the corresponding Makefile. It accepts
13option definitions with the ``-D`` flag, eg ``./bin/jmk2
swissChili0db97752022-07-29 21:09:16 -070014-DSOME_OPTION=123``. You can also specify the C compiler, assembler,
15and linker to use with the ``-c``, ``-a``, and ``-l`` flags,
16respectively.
swissChili01ba07f2022-07-03 21:36:42 -070017
18Here is an example Jmk2 file:
19
20.. code-block:: tcl
21
22 init hello # hello is the name of the project
23 srcs hello.c world.c # the source files this project uses
24 type executable # the preset type of project this is
25
26Each line consists of a command (``init``, ``srcs``, ``type``) and its
27arguments. The commands are documented here:
28
29.. function:: init name [target]
30
31 Initializes the project with a given name. The ``name`` is currently
32 unused, but should be set to a descriptive identifier.
33
34 ``target`` is the name of the target that the project
35 generates. By default it is the same as ``name``. For an
36 executable, this could be ``hello`` or ``hello.exe``. For a shared
37 library, ``libhello.so``, etc.
38
39.. function:: preset preset_name
40
41 Applies the preset ``preset_name``. A preset is a function defined
42 in the ``::presets`` namespace which makes some changes to the
43 project state.
44
45 These are the default presets:
46
47 * ``freestanding`` Changes the ``cflags`` to build a freestanding binary (without linking the standard library).
48 * ``optimize`` Changes the ``cflags`` and ``asmflags`` to enable \
49 compile-time optimizations.
50 * ``32`` Tells the compilers to produce a 32 bit build.
51 * ``debug`` Tells the compilers to enable debug information in the \
52 resulting builds (enables DWARF symbols).
53 * ``warn`` Enables useful warnings and ``-Werror``.
54 * ``nasm`` Sets ``nasm`` as the default assembler.
55
56.. function:: presets preset_a [preset_b]...
57
58 Applies all the given presets in order. Identical to calling
59 ``preset`` once for each argument.
60
61.. function:: cflag string
62
63 Adds ``string`` to the ``::cflags`` variable, which will be passed
64 to the C compiler.
65
66.. function:: cflags string_a [string_b]...
67
68 Adds multiple strings to the ``::cflags`` variable, the same as
69 calling ``cflags`` repeatedly.
70
71.. function:: asmflag, asmflags
72
73 Same as ``cflag``, ``cflags`` but for the ``::asmflags`` variable.
74
75.. function:: option name default_value
76
77 If the option ``name`` has not been specified when invoking
78 ``bin/jmk2``, sets the value of the option to
79 ``default_value``. Options can be read with
80 ``::options(option_name)``.
81
82TODO: finish!