libk  Check-in [d27f92e3b7]

Overview
Comment:restructure file naming conventions and conclusively fix longstanding architectural build system problems with loads and loads of variables and a shit ton of function calls
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d27f92e3b7e88d34291cddd71dd199a5fa7a95341818b125443a2e615e19e1cb
User & Date: lexi on 2019-06-28 04:32:40
Other Links: manifest | tags
Context
2019-06-28
04:35
fix useless params check-in: f5e894f1c4 user: lexi tags: trunk
04:32
restructure file naming conventions and conclusively fix longstanding architectural build system problems with loads and loads of variables and a shit ton of function calls check-in: d27f92e3b7 user: lexi tags: trunk
01:59
add {,un}install rule check-in: 2ed2a90fe5 user: lexi tags: trunk
Changes

Deleted kcore/boot.c version [6007ea2ce5].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <k/core.h>
extern stat entry(kenv);

stat _boot(unsigned int argc, char** argv) {
	kenv e = { 
		// todo: determine terminal class and set term vs ansi correctly!
		{ {kiostream_term, 0}, {kiostream_term, 1} }, // chan std
		{ {kiostream_closed},  {kiostream_term, 2} }, // chan err
		argc, argv,
		null // no environment yet
	};
	return entry(e);
}
	
<
<
<
<
<
<
<
<
<
<
<
<
<
<




























Added kcore/boot.rt.c version [6007ea2ce5].





























>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <k/core.h>
extern stat entry(kenv);

stat _boot(unsigned int argc, char** argv) {
	kenv e = { 
		// todo: determine terminal class and set term vs ansi correctly!
		{ {kiostream_term, 0}, {kiostream_term, 1} }, // chan std
		{ {kiostream_closed},  {kiostream_term, 2} }, // chan err
		argc, argv,
		null // no environment yet
	};
	return entry(e);
}
	

Added kcore/boot.rt.x86.lin.64.s version [2671a43f32].



































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
; vim: ft=nasm
bits 64
%include "../arch/x86.lin.64.s"
global _start:function
extern _boot
extern entry;

_start:
	mov rbp, rsp
	mov rdi, [rbp + 0] ; argc
	lea rsi, [rbp + 8] ; argv

	call _boot

	mov sys.reg.1, sys.reg.ret
	mov sys.reg.0, sys.exit
	sys.call

Deleted kcore/boot.x86.lin.64.s version [2671a43f32].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
; vim: ft=nasm
bits 64
%include "../arch/x86.lin.64.s"
global _start:function
extern _boot
extern entry;

_start:
	mov rbp, rsp
	mov rdi, [rbp + 0] ; argc
	lea rsi, [rbp + 8] ; argv

	call _boot

	mov sys.reg.1, sys.reg.ret
	mov sys.reg.0, sys.exit
	sys.call
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


































Added kcore/def.h version [5f84d85008].











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <k/type.h>
/* <k/def.h>
 * ~ lexi hale <lexi@hale.su>
 * define flags so we can reason about
 * our environment. */

#if (KVos == lin)  ||\
    (KVos == fbsd) ||\
    (KVos == obsd) ||\
    (KVos == nbsd) ||\
    (KVos == dar) ||\
    (KVos == and)  
#   define KFenv_unix
#endif

#if defined(KFenv_unix)  ||\
           (KVos == hai) ||\
           (KVos == mgw)
#   define KFenv_posix
#endif

Added kcore/def.win.i version [11ccc3c2e7].





>
>
1
2
#define KVos win
typedef u32 stat;

Modified kcore/makefile from [a535931ecd] to [121a62ca71].

23
24
25
26
27
28
29
30
31

32
33
34
35
36
37
	cp $< $@

# generating C source in make… yaaay
define arch =
${TMP}/type.$(1).%.$(2).i: type.$(1).$(2).i def.%.i ${TMP}
	echo '#ifndef KItype' > $$@
	echo '#define KItype' >> $$@
	cat def.$$*.i >> $$@
	cat $$< >> $$@

	echo '#endif' >> $$@
endef

$(eval $(call arch,x86,32))
$(eval $(call arch,x86,64))








<

>






23
24
25
26
27
28
29

30
31
32
33
34
35
36
37
	cp $< $@

# generating C source in make… yaaay
define arch =
${TMP}/type.$(1).%.$(2).i: type.$(1).$(2).i def.%.i ${TMP}
	echo '#ifndef KItype' > $$@
	echo '#define KItype' >> $$@

	cat $$< >> $$@
	cat def.$$*.i >> $$@
	echo '#endif' >> $$@
endef

$(eval $(call arch,x86,32))
$(eval $(call arch,x86,64))

Added kgraft/attach.exe.c version [572a900790].









>
>
>
>
1
2
3
4
#include <k/core.h>
stat entry(kenv e) {
	return 0;
}

Deleted kgraft/exe.attach.c version [572a900790].

1
2
3
4
#include <k/core.h>
stat entry(kenv e) {
	return 0;
}
<
<
<
<








Modified kio/io.h from [824a86b217] to [aa4095c969].

4
5
6
7
8
9
10

11

12
13
14
15
16
17
18
..
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52






53
 * ~ lexi hale <lexi@hale.su>
 * this header declares IO primitive functions and
 * structures. it is the same for all platforms.
 * platform-specific code is found in the *.platform.h
 * files.
 */


#include <k/type.h>


typedef enum kiostream_kind {
	kiostream_closed,
	  // this kiostream cannot be written to
	kiostream_file,
	  // this kiostream represents a file
	kiostream_sock,
................................................................................
typedef struct kiochan {
	kiostream in;
	  // text can be read from this stream
	kiostream out;
	  // text can be written to this stream
} kiochan;

unsigned long long kiosend(kiochan); // send data to a channel
unsigned long long kiorecv(kiochan); // receive data from a channel

typedef enum kiocond {
	kiocond_ok,
	  // success
    kiocond_fail,
	  // action failed
} kiocond;







#endif







>

>







 







<
<
<







>
>
>
>
>
>

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
..
38
39
40
41
42
43
44



45
46
47
48
49
50
51
52
53
54
55
56
57
58
 * ~ lexi hale <lexi@hale.su>
 * this header declares IO primitive functions and
 * structures. it is the same for all platforms.
 * platform-specific code is found in the *.platform.h
 * files.
 */

#include <k/str.h>
#include <k/type.h>
#include <k/mem.h>

typedef enum kiostream_kind {
	kiostream_closed,
	  // this kiostream cannot be written to
	kiostream_file,
	  // this kiostream represents a file
	kiostream_sock,
................................................................................
typedef struct kiochan {
	kiostream in;
	  // text can be read from this stream
	kiostream out;
	  // text can be written to this stream
} kiochan;




typedef enum kiocond {
	kiocond_ok,
	  // success
    kiocond_fail,
	  // action failed
} kiocond;

kiocond kiosend(kiochan, ksraw, sz*); // send data to a channel
kiocond kiorecv(kiochan, ksraw*); // receive data from a channel
kmptr kiorecvall(kiochan, kmcell*, kmkind); // automatically allocate a bufer for a channel
  // kmkind is only used if kmcell* is NULL
kiocond kiocon(kiochan, kiochan); // connect one channel to another

#endif

Added kio/kio_posix_fd_write.fn.x86.lin.32.s version [7b77d86bab].





























>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
bits 32
global kio_posix_fd_write

%include "../arch/x86.lin.32.s"
; vim: ft=nasm

kio_posix_fd_write:
	mov sys.reg.0, sys.call.write
	mov sys.reg.1, [esp + 4] ; holy god but this took the most
	mov sys.reg.2, [esp + 8] ; stupidly long time to fucking
	mov sys.reg.3, [esp + 12]; figure out
	sys.call
	ret

Added kio/kio_posix_fd_write.fn.x86.lin.64.s version [b72b3eff18].





























>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
bits 64
global kio_posix_fd_write

%include "../arch/x86.lin.64.s"
; vim: ft=nasm

kio_posix_fd_write:
	mov sys.reg.0, sys.write
	; mov sys.reg.1, ccall.reg.0 - nop
	; mov sys.reg.2, ccall.reg.1 - nop
	; mov sys.reg.3, ccall.reg.2 - nop
	sys.call
	ret

Deleted kio/kio_posix_fd_write.x86.lin.32.s version [7b77d86bab].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
bits 32
global kio_posix_fd_write

%include "../arch/x86.lin.32.s"
; vim: ft=nasm

kio_posix_fd_write:
	mov sys.reg.0, sys.call.write
	mov sys.reg.1, [esp + 4] ; holy god but this took the most
	mov sys.reg.2, [esp + 8] ; stupidly long time to fucking
	mov sys.reg.3, [esp + 12]; figure out
	sys.call
	ret

<
<
<
<
<
<
<
<
<
<
<
<
<
<




























Deleted kio/kio_posix_fd_write.x86.lin.64.s version [b72b3eff18].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
bits 64
global kio_posix_fd_write

%include "../arch/x86.lin.64.s"
; vim: ft=nasm

kio_posix_fd_write:
	mov sys.reg.0, sys.write
	; mov sys.reg.1, ccall.reg.0 - nop
	; mov sys.reg.2, ccall.reg.1 - nop
	; mov sys.reg.3, ccall.reg.2 - nop
	sys.call
	ret

<
<
<
<
<
<
<
<
<
<
<
<
<
<




























Added kio/send.fn.c version [430158e543].



































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
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
#include <k/io.h>
#include <k/core.h>
#include <k/def.h>
/* send.c - kiosend()
 * ~ lexi hale <lexi@hale.su>
 * kiosend() writes to a channel with an open out stream
 */

// we define all platform functions here,
// whether or not they're for the correct
// platform - only the ones actually called
// by the generated code will be linked
extern sz kio_posix_fd_write(int fd, const char* buf, sz len);

kiocond kiosend(kiochan target, ksraw string, sz* len) {
#	ifdef KFenv_posix
		sz size = kio_posix_fd_write(target.out.platform_fd, string.ptr, string.size);
		if (size == -1) return kiocond_fail; //TODO: retrieve errno and offer more specific errors
#	else
#		if KVos == win
#			error windows IO send function not yet defined
#		else
			_Pragma("GCC diagnostic error \"" // fancy error for gcc
				"IO send fn for platform " #KVos " not defined"
			"\""))
#			error IO send fn not defined for platform
			   // boring error for plebs
#		endif
#	endif

	if (len != null) *len = size;
	return kiocond_ok;
}

Modified libk.md from [523e766d88] to [3c28c4d693].

99
100
101
102
103
104
105
106




107
108
109
110
111
112
113
114
115
116
117
118
119
120
121

libk uses a strict directory structure for code, and deviations from this structure will not be tolerated without extremely good reason.

total segregation is maintained between source code, temporary files, and output objects. source is found in module directories (`k*/`). the destination for temporary files and output objects are retargetable via the `make` parameters `TMP= OUT=`, but default to `tmp/` and `out/`, which are excluded from repo with fossil's `ignore-glob` setting.

all libk code is dispersed into modules: `kcore` for internals, `kio` for I/O, `kgraft` for binary packing, etc. each module has a folder in the root directory. (libk does not have submodules.) inside each module's directory should be a header with the same name as the module (see **naming conventions** above).

each function should be kept in a separate file within its module's directory. when OS or architecture-specific code is needed, the file's name should be a list of one or more of the fields [arch, OS, bits, format] separated by a `.` -- for instance, the 32-bit x86 haiku version of a function called `write` defined in assembly would be named `write.x86.hai.32.s`. however, if a function has an extraordinarily large number of versions, they may instead be stored in a folder with the same name as the function.





each module should have a header named the same thing as the module except without the `k` prefix. (e.g. the header for `kio` is `kio/io.h`) located in its folder. this is the header that the end-user will be importing, and should handle any user-defined flags to present the API the user has selected.

each module directory should contain a makefile that can build that module. see **makefiles** below. all makefiles should be named `makefile` (**not** `Makefile`).

each module should contain a markdown file. this file's name should be the name of the parent directory suffixed with `.md`; for instance, `kterm` should contain the file `kterm/kterm.md`. this file should document the module as thoroughly as possible 

each module may contain any number of files of the name `exe.*.c`. this files will be treated as *tools* by the build system and compiled as executables, rather than libraries. they should be compiled to `out/$module.$tool`

the repository root and each module may also contain the directory `misc`. this directory may be used to store miscellaneous data such as ABI references, developer discussions, and roadmaps. if the `misc` directory is deleted, this must not affect the library or build system's function in any way - that is, nothing outside a `misc` folder may reference a `misc` folder or anything inside it, including documentation. the `misc` directory should be removed when its contents are no longer needed. in most cases, the repository wiki and forum should be used instead of the `misc` folder.

the folder `arch` in the root of the repository contains syscall tables and ABI implementations for various architectures.

## makefiles








|
>
>
>
>







|







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
124
125

libk uses a strict directory structure for code, and deviations from this structure will not be tolerated without extremely good reason.

total segregation is maintained between source code, temporary files, and output objects. source is found in module directories (`k*/`). the destination for temporary files and output objects are retargetable via the `make` parameters `TMP= OUT=`, but default to `tmp/` and `out/`, which are excluded from repo with fossil's `ignore-glob` setting.

all libk code is dispersed into modules: `kcore` for internals, `kio` for I/O, `kgraft` for binary packing, etc. each module has a folder in the root directory. (libk does not have submodules.) inside each module's directory should be a header with the same name as the module (see **naming conventions** above).

each function should be kept in a separate file within its module's directory. the file's name should consist of the dot-separated fields [name, class, "c"] for C sources, or [name, class, arch, OS, bits, format, "s"] for assembly sources, where "name" is the name of the function without the module prefix and "class" is `rt` if the file is part of the libk runtime, or `fn` otherwise. this distinction is necessary because while the static library `libk.a` can include runtime objects, the shared library `libk.so` cannot. examples:

 * a C file in the module `kstr` named `kscomp` would be named `kstr/comp.fn.c`
 * a runtime assembly file called `boot` in the module `kcore` for x86-64 linux would be named `kcore/boot.rt.x86.lin.64.s`
 * the 32-bit x86 haiku version of a function called `kiowrite` defined in assembly would be named `kio/write.fn.x86.hai.32.s`.

each module should have a header named the same thing as the module except without the `k` prefix. (e.g. the header for `kio` is `kio/io.h`) located in its folder. this is the header that the end-user will be importing, and should handle any user-defined flags to present the API the user has selected.

each module directory should contain a makefile that can build that module. see **makefiles** below. all makefiles should be named `makefile` (**not** `Makefile`).

each module should contain a markdown file. this file's name should be the name of the parent directory suffixed with `.md`; for instance, `kterm` should contain the file `kterm/kterm.md`. this file should document the module as thoroughly as possible 

each module may contain any number of files of the name `*.exe.c`. this files will be treated as *tools* by the build system and compiled as executables, rather than libraries. they should be compiled to `out/$module.$tool`

the repository root and each module may also contain the directory `misc`. this directory may be used to store miscellaneous data such as ABI references, developer discussions, and roadmaps. if the `misc` directory is deleted, this must not affect the library or build system's function in any way - that is, nothing outside a `misc` folder may reference a `misc` folder or anything inside it, including documentation. the `misc` directory should be removed when its contents are no longer needed. in most cases, the repository wiki and forum should be used instead of the `misc` folder.

the folder `arch` in the root of the repository contains syscall tables and ABI implementations for various architectures.

## makefiles

Modified makefile from [6234448ba2] to [dc16a02cfa].

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 $@

Modified modmake from [86d81e4675] to [3c50b488d5].

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
..
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# vim: ft=make

mod = $(notdir $(PWD))
src = $(wildcard *.c) $(wildcard *.s)
bare = $(mod:k%=%)
headers = $(wildcard *.h) $(gen-headers)

tools    = $(filter     exe.%.c,   $(src))
nontools = $(filter-out exe.%.c,   $(src))
cobjects = $(filter     %.c,       $(nontools))
sobjects = $(filter %.${TARGET}.s, $(nontools))

cflags = -isystem ${OUT} -fPIC -nostdlib ${COMPLIB} -L${OUT} -lk

obj: $(cobjects:%.c=${OUT}/$(mod).%.o) \
	 $(sobjects:%.s=${OUT}/$(mod).%.o)
tool: $(tools:exe.%.c=${OUT}/$(mod).%) \
	  ${OUT}/libk.a

def: $(headers:%=${OUT}/k/%)

dbg:
	@echo tools = $(tools)
	@echo TARGET = ${TARGET}
................................................................................

${OUT}/$(mod).%.o: %.c
	$(CC) $(cflags) -c $< -o $@

${OUT}/k/%.h: %.h
	cp $< $@

${OUT}/$(mod).%: exe.%.c
	$(CC) $(cflags) $< -o $@

${TMP}:
	mkdir -p ${TMP}

#- assembly
# compiling  the assembly  code will  be  faster but  a lot  more







|
|







|







 







|







4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
..
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# vim: ft=make

mod = $(notdir $(PWD))
src = $(wildcard *.c) $(wildcard *.s)
bare = $(mod:k%=%)
headers = $(wildcard *.h) $(gen-headers)

tools    = $(filter     %.exe.c,   $(src))
nontools = $(filter-out %.exe.c,   $(src))
cobjects = $(filter     %.c,       $(nontools))
sobjects = $(filter %.${TARGET}.s, $(nontools))

cflags = -isystem ${OUT} -fPIC -nostdlib ${COMPLIB} -L${OUT} -lk

obj: $(cobjects:%.c=${OUT}/$(mod).%.o) \
	 $(sobjects:%.s=${OUT}/$(mod).%.o)
tool: $(tools:%.exe.c=${OUT}/$(mod).%) \
	  ${OUT}/libk.a

def: $(headers:%=${OUT}/k/%)

dbg:
	@echo tools = $(tools)
	@echo TARGET = ${TARGET}
................................................................................

${OUT}/$(mod).%.o: %.c
	$(CC) $(cflags) -c $< -o $@

${OUT}/k/%.h: %.h
	cp $< $@

${OUT}/$(mod).%: %.exe.c
	$(CC) $(cflags) $< -o $@

${TMP}:
	mkdir -p ${TMP}

#- assembly
# compiling  the assembly  code will  be  faster but  a lot  more