blob: 0262ba03fbb281005e5ebb67aad4653044a377ff [file] [log] [blame]
swissChili04a856e2021-03-13 22:14:18 -08001.TH jmk 5 "13 March 2021" "1" "JMK format"
2.SH SYNOPSIS
3The JMK format is processed by jmk(1) to generate a Makefile.
4.SH DESCRIPTION
5jmk(1) is a simple M4 script which provides a handful of macros.
6These macros can be used to automate many tedious parts of creating
7makefiles.
8.SH OVERVIEW
9The following macros are provided by JMK:
10
11.B
12init(project, [target])
13.NB
14.RS
15Initialize the project named <project> to build the target <target>.
16If <target> is not provided, it defaults to <project>.
17.B
18Example:
19.NB
20
21.EX
22init(kernel, kernel.elf)
23# or
24init(my_lib, my_lib.a)
25.EE
26.RE
27
28.B
29preset(preset_name)
30.NB
31.RS
32Apply a preset to the project.
33Currently the following presets are available:
34
35freestanding: Applies CFLAGS suitable for freestanding targets.
36
37optimize: Applies -O2 optimization level
38
39debug: Applies -g
40
4132: Sets target architecture to 32 bit
42
43warn: Enables all warnings except unused-function and unused-variable.
44
45nasm: Forces the assembler to be nasm.
46
47.B
48Example:
49.NB
50
51.EX
52preset(32)
53preset(debug)
54CFLAGS += -my-flag
55.EE
56.RE
57
58.B
59archetype(archetype_name)
60.NB
61.RS
62Applies a given archetype to the project.
63An archetype provides support to compile a certain language or type of program.
64The two archetypes available by default are
65.B
66c
67.NB
68and
69.B
70asm,
71.NB
72whose meanings are self explanatory.
73.B
74Example:
75.NB
76
77.EX
78archetype(c)
79archetype(asm)
80.EE
81.RE
82
83.B
84depends(name, directory, [target])
85.NB
86.RS
87Register the target called <target> located in <directory> as a dependency named <name>.
88By default, <target> is set to the last segment of the directory path plus .a.
89E.g.: for foo/bar <target> would be bar.a by default.
90This is usually used in conjunction with lib().
91
92Internally this will generate a target for this library that will call make on the
93other project in order to build the target.
94See lib() for examples.
95.RE
96
97.B
98lib(dependency_name)
99.NB
100.RS
101Lib expands to the path to the dependency called <dependency_name> as defined by depends().
102This can, for example, be used in OBJECTS to specify the project's dependency on another
103(sub)project, or it can be used anywhere you would need to refer to the path of the
104target generated by that project.
105Despite the name, lib can be used for any type of dependency, not just for libraries.
106.B
107Example:
108.NB
109
110.EX
111depends(libc, $(ROOT)/src/libc, libc.a)
112OBJECTS = main.o lib(libc)
113.EE
114.RE
115
116.B
117phony(target)
118.NB
119.RS
120Adds <target> to the list of .PHONY targets.
121.RE
122
123.B
124type(type)
125.NB
126.RS
127Sets the project type and generates the actual target for the project.
128If you need to build your final target in a way unsupported by default, feel free to omit
129this and write the target by hand. <type> can be one of executable, static_lib or
130custom_link.
131The first two cases will build an executable and library respectively, using $(CC) and ar.
132custom_link will invoke $(LD), passing LDFLAGS.
133
134Note that the objects to include in the target are to be specified in OBJECTS,
135and should be built either automatically by an included archetype, or manually.
136.RE
137
138.B
139finish
140.NB
141.RS
142Include this at the end of every Jmk file, this generates some targets like .PHONY
143and clean, as well as setting up automatic Makefile regeneration.
144.RE
145
146.SH EXAMPLE
147Here is a full example of a JMK project:
148
149.EX
150init(kernel, kernel.elf)
151
152preset(freestanding)
153preset(optimize)
154preset(32)
155preset(nasm)
156
157LDFLAGS += -Tlink.ld
158
159archetype(c)
160archetype(asm)
161
162depends(some_driver, dri/some/driver/, driver.a)
163
164OBJECTS = boot.o main.o other.o something.o lib(some_driver)
165
166type(custom_link)
167
168qemu: kernel.elf
169 qemu-system-i386 $<
170
171finish
172.EE
173.SH SEE ALSO
174jmk(1), building(9)