4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
..
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
..
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
..
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
export OS = lin
export BITS = 64
export TMP = $(PWD)/tmp
export TARGET = $(ARCH).$(OS).$(BITS)
moddirs = $(wildcard k*)
binaries = $(wildcard */exe.*.c)
binmods = $(sort $(dir $(binaries)))
header-dir = /usr/include
lib-dir = /usr/lib
posix-oses = lin fbsd dar and hai mgw
ifeq ($(findstring $(OS),$(posix-oses)),$(OS))
export POSIX = yes
................................................................................
endif
# include libgcc.a in gcc builds, just in case
ifeq ($(CC),gcc)
export COMPLIB = -lgcc
endif
all: defs obj tool lib.static lib.shared
lib.static: defs obj $(OUT)/libk.a
lib.shared: defs obj $(OUT)/libk.so
obj: $(moddirs:%=%.obj)
defs: $(moddirs:%=%.def)
tool: $(OUT)/libk.a $(binmods:%=%.tool)
clean:
rm -rf $(TMP) $(OUT)
................................................................................
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 objects binaries binmods POSIX
dbg:
@echo -e lists: $(foreach var, $(lists), "\\n - \\e[1m$(var)\\e[m = $($(var))")
%.obj: %/makefile ${TARGET}.calls $(OUT)
cd $* && $(MAKE) obj
%.tool: %/makefile $(OUT)
................................................................................
%.def: %/makefile $(OUT) $(OUT)/k
cd $* && $(MAKE) def
%.calls: arch/makefile
cd arch && $(MAKE) $(TMP)/calls.$*.s
$(OUT)/libk.so: obj $(OUT) $(OUT)/boot.o
ld -shared $(COMPLIB) -o $@ $(filter-out kcore.boot.%, $(wildcard *.o))
# $(CC) -shared -fPIC -nostdlib $(COMPLIB) -o $@ $(OUT)/*.o
$(OUT)/boot.o: $(OUT)/kcore.boot.o $(OUT)/kcore.boot.$(TARGET).o
ld -r $^ -o $(OUT)/boot.o
$(OUT)/libk.a: obj $(OUT)
# using `ar rc` and ranlib here instead of
# `ar rcs` in case `ar` isn't the GNU version
ar rc $@ $(OUT)/*.o
ranlib $@
$(OUT) $(OUT)/k:
mkdir -p $@
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
|
|
|
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
..
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
..
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
..
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
export OS = lin
export BITS = 64
export TMP = $(PWD)/tmp
export TARGET = $(ARCH).$(OS).$(BITS)
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),$(addprefix $(OUT)/$(dir).,$(notdir $(wildcard $(dir)/$1)))))
cfnsources = $(call collect,*.fn.c)
sfnsources = $(call collect,*.fn.${TARGET}.s)
crtsources = $(call collect,*.rt.c)
srtsources = $(call collect,*.rt.${TARGET}.s)
fnsources = $(cfnsources) $(sfnsources)
rtsources = $(crtsources) $(srtsources)
sources = $(fnsources) $(rtsources)
cfnobjects = $(cfnsources:%.c=%.o)
sfnobjects = $(sfnsources:%.s=%.o)
crtobjects = $(crtsources:%.c=%.o)
srtobjects = $(srtsources:%.s=%.o)
fnobjects = $(cfnobjects) $(sfnobjects)
rtobjects = $(crtobjects) $(srtobjects)
objects = $(fnobjects) $(rtobjects)
header-dir = /usr/include
lib-dir = /usr/lib
posix-oses = lin fbsd dar and hai mgw
ifeq ($(findstring $(OS),$(posix-oses)),$(OS))
export POSIX = yes
................................................................................
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)/libk.a $(binmods:%=%.tool)
clean:
rm -rf $(TMP) $(OUT)
................................................................................
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 cfnobjects sfnobjects crtobjects srtobjects rtobjects binaries binmods POSIX
dbg:
@echo -e lists: $(foreach var, $(lists), "\\n - \\e[1m$(var)\\e[m = $($(var))")
%.obj: %/makefile ${TARGET}.calls $(OUT)
cd $* && $(MAKE) obj
%.tool: %/makefile $(OUT)
................................................................................
%.def: %/makefile $(OUT) $(OUT)/k
cd $* && $(MAKE) def
%.calls: arch/makefile
cd arch && $(MAKE) $(TMP)/calls.$*.s
$(OUT)/libk.so: $(fnobjects)
ld -shared $(COMPLIB) -o $@ $^
@# $(CC) -shared -fPIC -nostdlib $(COMPLIB) -o $@ $(OUT)/*.o
$(OUT)/boot.o: $(rtobjects)
ld -r $^ -o $(OUT)/boot.o
$(OUT)/libk.a: $(fnobjects) $(rtobjects) obj $(OUT)
@# using `ar rc` and ranlib here instead of
@# `ar rcs` in case `ar` isn't the GNU version
ar rc $@ $(OUT)/*.o
ranlib $@
$(OUT) $(OUT)/k:
mkdir -p $@
|