blob: b4543985e8311c4a0a222cf731cb6dc85714529a [file] [log] [blame]
swissChili2b5acc82021-03-13 17:06:42 -08001divert(-1)
2
3dnl
4dnl JMK (Jay MaKe) build system
5dnl
6
7define(`foreach', `pushdef(`$1')_foreach($@)popdef(`$1')')
8define(`_arg1', `$1')
9define(`_foreach', `ifelse(`$2', `()', `',
10 `define(`$1', _arg1$2)$3`'$0(`$1', (shift$2), `$3')')')
11
12
13
14define(init,
15`jmk_project := $1
16jmk_target = ifelse(`$#', 2, $2, $1)
17ROOT := jmk_root
18ASM ?= nasm
19CC ?= gcc
20LD ?= ld
21CFLAGS += -I$(ROOT)/include
22
23all: $(jmk_target)')
24
25dnl preset applies a certain configuration preset to the project
26define(preset,
27 `ifelse($1, `freestanding',
28 `CFLAGS += -nostdlib -nostdinc -fno-builtin -fno-stack-protector -ffreestanding',
29 $1, `optimize', `CFLAGS += -O2',
30 $1, `debug', `CFLAGS += -g',
31 $1, `32', `CFLAGS += -m32',
32 $1, `warn', `CFLAGS += -Wall -Wno-unused-function -Wno-unused-variable',
33 $1, `nasm', `ASM = nasm'
34 )')
35
36dnl this is really, really terrible, but to my knowledge there is no
37dnl other way to escape a $. The manual says nothing about this.
38define(ident, $1)
39define(dollar_at, `ident($)ident(@)')
40
41dnl archetype enables a language archetype
42define(archetype,
43 `ifelse($1, c, `.c.o:
44 $(CC) -c $< -o dollar_at $(CFLAGS)',
45 $1, asm, `.s.o:
46 $(ASM) $(ASMFLAGS) $< -o dollar_at'
47 )'
48)
49
50dnl depends declares an external dependency
51define(`depends', `
52jmk_lib_path_$1 = $2
53jmk_lib_target_$1 = ifelse($3, `', $1.a, $3)
54jmk_libs_phony += $(jmk_lib_path_$1)/$(jmk_lib_target_$1)
55
56$(jmk_lib_path_$1)/$(jmk_lib_target_$1):
57 $(MAKE) -C $(jmk_lib_path_$1) $(jmk_lib_target_$1)')
58
59dnl lib is used to list an external dependency declared with depends()
60define(`lib', `$(jmk_lib_path_$1)/$(jmk_lib_target_$1)')
61
62define(`phony', `jmk_custom_phony += $1')
63
64dnl type is used to specify the target type
65define(type,
66 `ifelse($1, executable,
67`$(jmk_target): $(OBJECTS)
68 $(CC) -o dollar_at $^ $(CFLAGS)',
69 $1, static_lib,
70`$(jmk_target): $(OBJECTS)
71 ar rcs dollar_at $^',
72 $1, custom_link,
73`$(jmk_target): $(OBJECTS)
74 $(LD) $(LDFLAGS) -o dollar_at $^'
75 )')
76
77dnl finish is required at the end of the Jmk file to generate some
78dnl final declarations
79
80define(finish,
81`clean:
82 rm -f *.o *.a *.so $(jmk_target)
83
84Makefile: Jmk
85 cd "jmk_build_dir" && jmk_build_cmd
86
87.PHONY: $(jmk_libs_phony) $(jmk_custom_phony) clean all')
88
89divert(0)dnl