@@ -5,33 +5,43 @@ 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} -nostdlib ${COMPLIB} -L${OUT} -lk + obj: $(cobjects:%.c=${OUT}/$(mod).%.o) \ $(sobjects:%.s=${OUT}/$(mod).%.o) -tool: $(tools:exe.%.c=${OUT}/$(mod).%) +tool: $(tools:exe.%.c=${OUT}/$(mod).%) \ + ${OUT}/libk.a + +def: $(headers:%=${OUT}/k/%) dbg: @echo tools = $(tools) @echo TARGET = ${TARGET} @echo cobjects = $(cobjects) @echo sobjects = $(sobjects) + @echo headers = $(headers) @echo mod = $(mod) ${OUT}/$(mod).%.o: %.c - $(CC) -c $< -o $@ + $(CC) $(cflags) -c $< -o $@ -${OUT}/k/$(bare).h: $(bare).h +${OUT}/k/%.h: %.h cp $< $@ ${OUT}/$(mod).%: exe.%.c - $(CC) $< -o $@ + $(CC) $(cflags) $< -o $@ + +${TMP}: + mkdir -p ${TMP} #- assembly # compiling the assembly code will be faster but a lot more # complex, given the nature of assembly and the large number of @@ -46,8 +56,12 @@ # $(1) = arch tuple arch = ${OUT}/$(mod).%.$(1).o: %.$(1).s # invoke with $(call arch,tuple). do not # put spaces between either term though! + +ifeq ($(debug),yes) +yasm-flags = -gdwarf2 +endif #-- linux # linux uses the ELF{32,64} binary format, and generating these # from yasm is trivial. linux only supports one ABI per format, @@ -54,13 +68,13 @@ # at least with ELF, so that's all we need to do. #${OUT}/$(mod).%.x86.lin.32.o: %.x86.lin.32.s $(call arch,x86.lin.32) - yasm -gdwarf2 -felf32 $< -o $@ + yasm $(yasm-flags) -felf32 -i${TMP} $< -o $@ #${OUT}/$(mod).%.x86.lin.64.o: %.x86.lin.64.s $(call arch,x86.lin.64) - yasm -gdwarf2 -felf64 $< -o $@ + yasm $(yasm-flags) -felf64 -i${TMP} $< -o $@ #-- freebsd # the freebsd ABI is different, so it will require different code # (though there might be ways to minimize that). freebsd uses the