nuclear@65: ifneq ($(shell uname -m), i386) nuclear@72: # -m32 instructs the compiler to produce 32bit code nuclear@65: ccemu = -m32 nuclear@65: nuclear@65: ifeq ($(shell uname -s), FreeBSD) nuclear@66: ldemu = -m elf_i386_fbsd nuclear@65: else nuclear@66: ldemu = -m elf_i386 nuclear@65: endif nuclear@65: endif nuclear@65: nuclear@0: # collect all of our C and assembly source files nuclear@10: csrc = $(wildcard src/boot/*.c) $(wildcard src/*.c) $(wildcard src/klibc/*.c) nuclear@10: asmsrc = $(wildcard src/boot/*.S) $(wildcard src/*.S) $(wildcard src/klibc/*.S) nuclear@7: dep = $(asmsrc:.S=.d) $(csrc:.c=.d) nuclear@0: nuclear@0: # each source file will generate one object file nuclear@2: obj = $(asmsrc:.S=.o) $(csrc:.c=.o) nuclear@0: nuclear@0: CC = gcc nuclear@0: nuclear@72: inc = -Isrc -Isrc/klibc -Isrc/boot -Iinclude nuclear@16: nuclear@0: # -nostdinc instructs the compiler to ignore standard include directories nuclear@72: CFLAGS = $(ccemu) -Wall -g -nostdinc -fno-builtin $(inc) -DKERNEL nuclear@65: ASFLAGS = $(ccemu) -g -nostdinc -fno-builtin $(inc) nuclear@0: nuclear@0: bin = kernel.elf nuclear@0: nuclear@0: # default target: make an ELF binary by linking the object files nuclear@1: # we need to specify where to assume the text section (code) is going nuclear@1: # in memory, as well as the kernel entry point (kentry). nuclear@0: $(bin): $(obj) nuclear@65: ld $(ldemu) -o $@ -Ttext 0x100000 -e kentry $(obj) -Map link.map nuclear@0: nuclear@38: %.s: %.c nuclear@38: $(CC) $(CFLAGS) -S -o $@ $< nuclear@38: nuclear@7: -include $(dep) nuclear@7: nuclear@7: %.d: %.c nuclear@7: @$(CPP) $(CFLAGS) -MM -MT $(@:.d=.o) $< >$@ nuclear@7: nuclear@7: %.d: %.S nuclear@7: @$(CPP) $(ASFLAGS) -MM -MT $(@:.d=.o) $< >$@ nuclear@7: nuclear@0: .PHONY: clean nuclear@0: clean: nuclear@0: rm -f $(obj) $(bin) nuclear@7: nuclear@7: .PHONY: cleandep nuclear@7: cleandep: nuclear@7: rm -f $(dep)