Differences From
Artifact [0ee3372ddd]:
1 1 export OUT = $(PWD)/out
2 2
3 3 export ARCH = x86
4 4 export OS = lin
5 5 export BITS = 64
6 +export TMP = $(PWD)/tmp
6 7
7 8 export TARGET = $(ARCH).$(OS).$(BITS)
8 9
9 10 moddirs = $(wildcard k*)
10 -modules = $(moddirs:k%=%)
11 -headers = $(moddirs:k%=$(OUT)/k/%.h)
12 -objects = $(modules:%=$(OUT)/k%.o)
13 -makefiles = $(moddirs:%=%/makefile)
14 -
15 11 binaries = $(wildcard */exe.*.c)
16 12 binmods = $(sort $(dir $(binaries)))
17 13
18 -all: obj defs tool
14 +posix-oses = lin fbsd dar and hai mgw
15 +
16 +ifeq ($(findstring $(OS),$(posix-oses)),$(OS))
17 +export POSIX = yes
18 +else
19 +export POSIX = no
20 +endif
21 +
22 +# include libgcc.a in gcc builds, just in case
23 +ifeq ($(CC),gcc)
24 +export COMPLIB = -lgcc
25 +endif
26 +
27 +all: defs obj tool
19 28 obj: $(moddirs:%=%.obj)
20 -defs: $(headers)
21 -tool: $(binmods:%=%.tool)
29 +defs: $(moddirs:%=%.def)
30 +tool: $(OUT)/libk.a $(binmods:%=%.tool)
31 +clean:
32 + rm -rf $(TMP) $(OUT)
22 33
23 -lists = moddirs modules headers objects makefiles binaries binmods
34 +lists = moddirs objects binaries binmods POSIX
24 35 dbg:
25 36 @echo -e lists: $(foreach var, $(lists), "\\n - \\e[1m$(var)\\e[m = $($(var))")
26 37
27 38 %.obj: %/makefile ${TARGET}.calls $(OUT)
28 39 cd $* && $(MAKE) obj
29 40
30 41 %.tool: %/makefile $(OUT)
31 42 cd $* && $(MAKE) tool
32 43
33 44 %.dbg: %/makefile $(OUT)
34 45 cd $* && $(MAKE) dbg
46 +
47 +%.def: %/makefile $(OUT) $(OUT)/k
48 + cd $* && $(MAKE) def
35 49
36 50 %.calls: arch/makefile
37 - cd arch && make calls.$*.s
51 + cd arch && $(MAKE) $(TMP)/calls.$*.s
38 52
39 -$(OUT)/libk.so: mods $(OUT)
40 - $(CC) -shared -o $@ $(objects)
53 +$(OUT)/libk.so: obj $(OUT)
54 + $(CC) -shared -nostdlib $(COMPLIB) -o $@ $(OUT)/*.o
41 55
42 -$(OUT)/libk.a: mods $(OUT)
43 - # using `ar c` and ranlib here instead of
44 - # `ar cs` in case `ar` isn't the GNU version
45 - ar c $@ $(objects)
56 +$(OUT)/libk.a: obj $(OUT)
57 + # using `ar rc` and ranlib here instead of
58 + # `ar rcs` in case `ar` isn't the GNU version
59 + ar rc $@ $(OUT)/*.o
46 60 ranlib $@
47 61
48 -$(OUT)/k/%.h: k%/makefile $(OUT)/k
49 - cd k$* && $(MAKE) $@
50 -
51 62 $(OUT) $(OUT)/k:
52 63 mkdir -p $@