3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
..
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
...
129
130
131
132
133
134
135
136
137
|
# TODO: calculate these using $(MAKE_HOST)
export ARCH = x86
export OS = lin
export BITS = 64
export ROOT = $(PWD)
export TMP = $(PWD)/gen
ifneq ($(BITS),)
export TARGET = $(ARCH).$(OS).$(BITS)
else
export TARGET = $(ARCH).$(OS)
endif
export m4 = m4
moddirs = $(wildcard k*)
binaries = $(wildcard k*/*.exe.c)
functions = $(wildcard k*/*.fn.c)
assemblies = $(wildcard k*/*.fn.$(TARGET).s)
binmods = $(sort $(dir $(binaries)))
# i'm sorry
collect = $(strip $(foreach dir,$(moddirs),$(wildcard $(dir)/*.$1)))
transform = $(strip $(foreach dir,$(moddirs),$(patsubst $(dir)/%.$1,$(subst @,$(dir),$2),$(wildcard $(dir)/*.$1))))
m-hdr-macs = $(call collect,h.m)
m-c-src-macs = $(call collect,c.m)
m-s-src-macs = $(call collect,$(TARGET).s.m)
m-c-sources = $(call transform,c.m,$(TMP)/@.%.c)
m-s-sources = $(call transform,$(TARGET).s.m,$(TMP)/@.%.$(TARGET).s)
m-headers = $(call transform,h.m,$(OUT)/k/%.h)
m-c-objects = $(call transform,c.m,$(OUT)/@.%.o)
m-s-objects = $(call transform,$(TARGET).s.m,$(OUT)/@.%.$(TARGET).o)
fnobjects = $(call transform,fn.c,$(OUT)/@.%.fn.o) \
$(call transform,fn.c.m,$(OUT)/@.%.fn.o) \
$(call transform,fn.$(TARGET).s,$(OUT)/@.%.fn.$(TARGET).o) \
$(call transform,fn.$(TARGET).s.m,$(OUT)/@.%.fn.$(TARGET).o)
rtobjects = $(call transform,rt.c,$(OUT)/@.%.rt.o) \
$(call transform,rt.c.m,$(OUT)/@.%.rt.o) \
$(call transform,rt.$(TARGET).s,$(OUT)/@.%.rt.$(TARGET).o) \
$(call transform,rt.$(TARGET).s.m,$(OUT)/@.%.rt.$(TARGET).o)
objects = $(fnobjects) $(rtobjects)
header-dir = /usr/include
lib-dir = /usr/lib
unix-oses = lin fbsd dar and
posix-oses = lin fbsd dar and hai mgw
ifeq ($(findstring $(OS),$(unix-oses)),$(OS))
export UNIX = yes
export POSIX = yes
else
export UNIX = no
ifeq ($(findstring $(OS),$(posix-oses)),$(OS))
................................................................................
else
export POSIX = no
endif
endif
# include libgcc.a in gcc builds, just in case
ifeq ($(CC),gcc)
export COMPLIB = -lgcc
endif
all: $(OUT) defs obj tool lib.static $(OUT)/boot.o lib.shared
lib.static: defs obj $(OUT)/libk.a
lib.shared: defs obj $(OUT)/libk.so
obj: $(moddirs:%=%.obj)
defs: $(moddirs:%=%.def)
tool: $(OUT)/boot.o $(OUT)/libk.a $(binmods:%=%.tool)
clean:
rm -rf $(TMP) $(OUT)
install: all
install -d $(header-dir)/k -o root -g wheel
install $(OUT)/k/* $(header-dir)/k/ -o root -g wheel -m 0644
install -d $(lib-dir)/k -o root -g wheel
install $(OUT)/libk.a $(OUT)/libk.so $(OUT)/boot.o \
$(lib-dir)/k/ -o root -g wheel -m 0644
uninstall: $(header-dir)/k $(lib-dir)/k
rm -rf $^
lists = moddirs functions assemblies fnobjects rtobjects binaries binmods POSIX
dbg:
@echo -e lists: $(foreach var, $(lists), "\\n - \\e[1m$(var)\\e[m = $($(var))")
%.obj: %/makefile $(OUT)
cd $* && $(MAKE) obj
%.tool: %/makefile $(OUT)
cd $* && $(MAKE) tool
%.dbg: %/makefile $(OUT)
cd $* && $(MAKE) dbg
%.def: %/makefile $(TMP)/typesize.def \
$(TMP)/system_calls.h \
$(TMP)/system_calls.s \
$(TMP)/error_table.h \
$(OUT) $(OUT)/k
cd $* && $(MAKE) def
.PRECIOUS: $(TMP)/system_calls.%
................................................................................
$(OUT)/libk.a: $(fnobjects) $(rtobjects)
@# using `ar rc` and ranlib here instead of
@# `ar rcs` in case `ar` isn't the GNU version
ar rc $@ $^
ranlib $@
$(OUT) $(OUT)/k $(TMP):
mkdir -p $@
|
>
>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
|
<
|
>
>
>
|
|
>
|
<
|
|
>
|
|
>
>
>
>
>
>
>
>
>
>
>
|
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
..
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
...
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
# TODO: calculate these using $(MAKE_HOST)
export ARCH = x86
export OS = lin
export BITS = 64
export ROOT = $(PWD)
export TMP = $(PWD)/gen
export BUILD = $(shell global/build-id.sh) $(build-host)
ifneq ($(BITS),)
export TARGET = $(ARCH).$(OS).$(BITS)
else
export TARGET = $(ARCH).$(OS)
endif
export m4 = m4
include makerule
moddirs := $(wildcard k*)
binaries := $(wildcard k*/*.exe.c)
functions := $(wildcard k*/*.fn.c)
assemblies := $(wildcard k*/*.fn.$(TARGET).s)
binmods := $(sort $(dir $(binaries)))
# i'm sorry
collect = $(strip $(foreach dir,$(moddirs),$(wildcard $(dir)/*.$1)))
transform = $(strip $(foreach dir,$(moddirs),$(patsubst $(dir)/%.$1,$(subst @,$(dir),$2),$(wildcard $(dir)/*.$1))))
m-hdr-macs := $(call collect,h.m)
m-c-src-macs := $(call collect,c.m)
m-s-src-macs := $(call collect,$(TARGET).s.m)
m-c-sources := $(call transform,c.m,$(TMP)/@.%.c)
m-s-sources := $(call transform,$(TARGET).s.m,$(TMP)/@.%.$(TARGET).s)
m-headers := $(call transform,h.m,$(OUT)/k/%.h)
m-c-objects := $(call transform,c.m,$(OUT)/@.%.o)
m-s-objects := $(call transform,$(TARGET).s.m,$(OUT)/@.%.$(TARGET).o)
fnobjects := $(call transform,fn.c,$(OUT)/@.%.fn.o) \
$(call transform,fn.c.m,$(OUT)/@.%.fn.o) \
$(call transform,fn.$(TARGET).s,$(OUT)/@.%.fn.$(TARGET).o) \
$(call transform,fn.$(TARGET).s.m,$(OUT)/@.%.fn.$(TARGET).o)
rtobjects := $(call transform,rt.c,$(OUT)/@.%.rt.o) \
$(call transform,rt.c.m,$(OUT)/@.%.rt.o) \
$(call transform,rt.$(TARGET).s,$(OUT)/@.%.rt.$(TARGET).o) \
$(call transform,rt.$(TARGET).s.m,$(OUT)/@.%.rt.$(TARGET).o)
docs := $(wildcard k*/*.md)
docs-out := $(patsubst %.md,$(OUT)/doc/man/%.4.gz,$(notdir $(docs)))
objects := $(fnobjects) $(rtobjects)
prefix ?= /usr
d-header = $(prefix)/include
d-lib = $(prefix)/lib
d-share = $(prefix)/share
unix-oses = lin fbsd dar and
posix-oses = lin fbsd dar and hai mgw cyg
ifeq ($(findstring $(OS),$(unix-oses)),$(OS))
export UNIX = yes
export POSIX = yes
else
export UNIX = no
ifeq ($(findstring $(OS),$(posix-oses)),$(OS))
................................................................................
else
export POSIX = no
endif
endif
# include libgcc.a in gcc builds, just in case
ifeq ($(CC),gcc)
export COMPLIB = -lgcc
endif
all: $(OUT) defs obj tool lib.static $(OUT)/boot.o lib.shared
lib.static: defs obj $(OUT)/libk.a
lib.shared: defs obj $(OUT)/libk.so
obj: $(moddirs:%=%.obj)
defs: $(moddirs:%=%.def)
tool: $(OUT)/boot.o $(OUT)/libk.a $(binmods:%=%.tool)
doc: $(docs-out)
clean:
rm -rf $(TMP) $(OUT)
install: all
install -d $(header-dir)/k $(share-dir)/k -o root -g wheel -m 0755
install $(OUT)/k/* $(header-dir)/k/ -o root -g wheel -m 0644
install $(OUT)/libk.a $(OUT)/libk.so \
$(lib-dir) -o root -g wheel -m 0644
install $(OUT)/boot.o $(share-dir)/k/boot.o -o root -g wheel -m 0644
uninstall: $(header-dir)/k $(lib-dir)/k
rm -rf $^
lists = BUILD moddirs functions assemblies fnobjects rtobjects binaries binmods POSIX docs docs-out
dbg:
@echo -e lists: $(foreach var, $(lists), "\\n - \\e[1m$(var)\\e[m = $($(var))")
%.obj: %/makefile $(OUT)/internal.ident.o $(OUT)
cd $* && $(MAKE) obj
%.tool: %/makefile $(OUT)
cd $* && $(MAKE) tool
%.dbg: %/makefile $(OUT)
cd $* && $(MAKE) dbg
%.def: %/makefile $(TMP)/typesize.def \
$(OUT)/k/internal.egroup.h \
$(TMP)/system_calls.h \
$(TMP)/system_calls.s \
$(TMP)/error_table.h \
$(OUT) $(OUT)/k
cd $* && $(MAKE) def
.PRECIOUS: $(TMP)/system_calls.%
................................................................................
$(OUT)/libk.a: $(fnobjects) $(rtobjects)
@# using `ar rc` and ranlib here instead of
@# `ar rcs` in case `ar` isn't the GNU version
ar rc $@ $^
ranlib $@
$(OUT)/man/doc:
mkdir -p $@
$(OUT)/k/internal.egroup.h: global/modules global/genconds.awk $(OUT)/k
awk -f global/genconds.awk <$< >$@
$(TMP)/internal.ident.c: global/modules global/genident.awk $(OUT)/k/internal.egroup.h $(TMP)
awk -f global/genident.awk <$< >$@
$(OUT)/%.o: $(TMP)/%.c $(OUT)
$(CC) $(cflags) -c $< -o $@
$(OUT) $(OUT)/k $(TMP):
mkdir -p $@
|