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