144 lines
4.4 KiB
Makefile
Executable file
144 lines
4.4 KiB
Makefile
Executable file
TOPDIR = $(shell pwd)
|
|
ARCH = x86
|
|
TERM = xterm
|
|
BIT = 32
|
|
NAME = eduos
|
|
KERNDIRS = libkern kernel mm fs arch/$(ARCH)/kernel arch/$(ARCH)/mm
|
|
SUBDIRS = $(KERNDIRS)
|
|
|
|
STACKPROT =
|
|
|
|
CC_FOR_TARGET = @CC_FOR_TARGET@
|
|
CXX_FOR_TARGET = @CXX_FOR_TARGET@
|
|
GCC_FOR_TARGET = @GCC_FOR_TARGET@
|
|
CPP_FOR_TARGET = @CPP_FOR_TARGET@
|
|
AR_FOR_TARGET = @AR_FOR_TARGET@
|
|
AS_FOR_TARGET = @AS_FOR_TARGET@
|
|
LD_FOR_TARGET = @LD_FOR_TARGET@
|
|
NM_FOR_TARGET = @NM_FOR_TARGET@
|
|
OBJDUMP_FOR_TARGET = @OBJDUMP_FOR_TARGET@
|
|
OBJCOPY_FOR_TARGET = @OBJCOPY_FOR_TARGET@
|
|
RANLIB_FOR_TARGET = @RANLIB_FOR_TARGET@
|
|
STRIP_FOR_TARGET = @STRIP_FOR_TARGET@
|
|
READELF_FOR_TARGET = @READELF_FOR_TARGET@
|
|
NASM = nasm
|
|
QEMU = qemu-system-i386
|
|
QEMUFLAGS = -smp 2 -monitor stdio \
|
|
-net nic,model=rtl8139 \
|
|
-net user,hostfwd=tcp::12345-:7
|
|
QEMUDEBUGFLAGS = -monitor none -daemonize \
|
|
-net nic,model=rtl8139 \
|
|
-net user,hostfwd=tcp::12345-:7
|
|
QEMUSERIALFLAGS = -device pci-serial,chardev=tS0 \
|
|
-chardev socket,host=localhost,port=4555,server,id=tS0
|
|
|
|
NASMFLAGS = -felf32 -g -i$(TOPDIR)/include/eduos/
|
|
INCLUDE = -I$(TOPDIR)/include -I$(TOPDIR)/arch/$(ARCH)/include
|
|
# Compiler options for final code
|
|
CFLAGS = -g -m32 -march=i586 -Wall -O2 -fno-builtin -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc $(INCLUDE) -fno-stack-protector
|
|
# Compiler options for debugging
|
|
#CFLAGS = -g -O -m32 -march=i586 -Wall -fno-builtin -DWITH_FRAME_POINTER -nostdinc $(INCLUDE) -fno-stack-protector
|
|
AR = ar
|
|
ARFLAGS = rsv
|
|
RM = rm -rf
|
|
LDFLAGS = -T link.ld -z max-page-size=4096 --defsym __BUILD_DATE=$(shell date +'%Y%m%d') --defsym __BUILD_TIME=$(shell date +'%H%M%S')
|
|
STRIP_DEBUG = --strip-debug
|
|
KEEP_DEBUG = --only-keep-debug
|
|
|
|
CFLAGS_FOR_NEWLIB = -m$(BIT) $(STACKPROT)
|
|
LDFLAGS_FOR_NEWLIB = -m$(BIT)
|
|
NASMFLAGS_FOR_NEWLIB = -felf$(BIT)
|
|
CFLAGS_FOR_TOOLS = -m$(BIT) -O2 -Wall
|
|
LDFLAGS_FOR_TOOLS =
|
|
|
|
# Prettify output
|
|
V = 0
|
|
ifeq ($V,0)
|
|
Q = @
|
|
P = > /dev/null
|
|
endif
|
|
|
|
default: all
|
|
|
|
all: newlib tools $(NAME).elf
|
|
|
|
newlib:
|
|
$Q$(MAKE) ARCH=$(ARCH) BIT=$(BIT) \
|
|
LDFLAGS="$(LDFLAGS_FOR_NEWLIB)" \
|
|
CFLAGS="$(CFLAGS_FOR_NEWLIB)" \
|
|
NASMFLAGS="$(NASMFLAGS_FOR_NEWLIB)" \
|
|
CC_FOR_TARGET=$(CC_FOR_TARGET) \
|
|
CXX_FOR_TARGET=$(CXX_FOR_TARGET) \
|
|
GCC_FOR_TARGET=$(GCC_FOR_TARGET) \
|
|
AR_FOR_TARGET=$(AR_FOR_TARGET) \
|
|
AS_FOR_TARGET=$(AS_FOR_TARGET) \
|
|
LD_FOR_TARGET=$(LD_FOR_TARGET) \
|
|
NM_FOR_TARGET=$(NM_FOR_TARGET) \
|
|
OBJDUMP_FOR_TARGET=$(OBJDUMP_FOR_TARGET) \
|
|
OBJCOPY_FOR_TARGET=$(OBJCOPY_FOR_TARGET) \
|
|
RANLIB_FOR_TARGET=$(RANLIB_FOR_TARGET) \
|
|
STRIP_FOR_TARGET=$(STRIP_FOR_TARGET) \
|
|
READELF_FOR_TARGET=$(READELF_FOR_TARGET) -C newlib
|
|
|
|
$(NAME).elf:
|
|
$Q$(LD_FOR_TARGET) $(LDFLAGS) -o $(NAME).elf $^
|
|
@echo [OBJCOPY] $(NAME).sym
|
|
$Q$(OBJCOPY_FOR_TARGET) $(KEEP_DEBUG) $(NAME).elf $(NAME).sym
|
|
@echo [OBJCOPY] $(NAME).elf
|
|
$Q$(OBJCOPY_FOR_TARGET) $(STRIP_DEBUG) $(NAME).elf
|
|
|
|
tools:
|
|
$Q$(MAKE) ARCH=$(ARCH) BIT=$(BIT) CFLAGS="$(CFLAGS_FOR_TOOLS)" LDFLAGS="$(LDFLAGS_FOR_TOOLS)" -C tools
|
|
|
|
clean:
|
|
$Q$(RM) $(NAME).elf $(NAME).sym *~
|
|
$Q$(MAKE) -C newlib clean
|
|
$Q$(MAKE) -C tools clean
|
|
@echo Cleaned.
|
|
|
|
veryclean: clean
|
|
$Q$(RM) qemu-vlan0.pcap
|
|
$Q$(MAKE) -C newlib veryclean
|
|
$Q$(MAKE) -C tools veryclean
|
|
@echo Very cleaned
|
|
|
|
qemu: $(NAME).elf
|
|
$(QEMU) $(QEMUFLAGS) -kernel $(NAME).elf -initrd tools/initrd.img
|
|
|
|
uart: $(NAME).elf
|
|
$(QEMU) $(QEMUFLAGS) $(QEMUSERIALFLAGS) -kernel $(NAME).elf -append uart=io:0xc110
|
|
|
|
debug: $(NAME).elf
|
|
$(TERM) -e $(GDB) $(GDBFLAGS) &
|
|
$(QEMU) $(QEMUDEBUGFLAGS) -s -S -kernel $(NAME).elf
|
|
|
|
doc:
|
|
@doxygen
|
|
@echo Create documentation...
|
|
|
|
test:
|
|
@echo "Nothing to test"
|
|
|
|
include/eduos/config.inc: include/eduos/config.h
|
|
@echo "; This file is generated automatically from the config.h file." > include/eduos/config.inc
|
|
@echo "; Before editing this, you should consider editing config.h." >> include/eduos/config.inc
|
|
@awk '/^#define KERNEL_STACK_SIZE/{ print "%define KERNEL_STACK_SIZE", $$3 }' include/eduos/config.h >> include/eduos/config.inc
|
|
@awk '/^#define VIDEO_MEM_ADDR/{ print "%define VIDEO_MEM_ADDR", $$3 }' include/eduos/stddef.h >> include/eduos/config.inc
|
|
|
|
%.o : %.c
|
|
@echo [CC] $@
|
|
$Q$(CC_FOR_TARGET) -c -D__KERNEL__ $(CFLAGS) -o $@ $<
|
|
@echo [DEP] $*.dep
|
|
$Q$(CC_FOR_TARGET) -MF $*.dep -MT $*.o -MM $(CFLAGS) $<
|
|
|
|
%.o : %.asm include/eduos/config.inc
|
|
@echo [ASM] $@
|
|
$Q$(NASM) $(NASMFLAGS) -o $@ $<
|
|
|
|
%.o : %.S
|
|
@echo [GCC-ASM] $@
|
|
$Q$(CC_FOR_TARGET) $(CFLAGS) -c -o $@ $<
|
|
|
|
.PHONY: default all clean emu gdb newlib tools test
|
|
|
|
include $(addsuffix /Makefile,$(SUBDIRS))
|