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