2012-05-21 15:04:05 +02:00
|
|
|
TOPDIR = $(shell pwd)
|
2011-02-09 19:15:10 +00:00
|
|
|
ARCH = x86
|
2012-06-10 08:05:24 +02:00
|
|
|
# For 64bit support, you have define BIT as 64
|
2012-05-23 08:03:06 +02:00
|
|
|
BIT=32
|
2011-03-31 12:50:42 -07:00
|
|
|
NAME = metalsvm
|
2011-05-29 13:02:04 -07:00
|
|
|
LWIPDIRS = lwip/src/arch lwip/src/api lwip/src/core lwip/src/core/ipv4 lwip/src/netif
|
2011-08-27 12:10:05 +02:00
|
|
|
DRIVERDIRS = drivers/net drivers/char
|
2011-10-02 14:44:05 +02:00
|
|
|
KERNDIRS = libkern kernel mm fs apps arch/$(ARCH)/kernel arch/$(ARCH)/mm arch/$(ARCH)/scc $(LWIPDIRS) $(DRIVERDIRS)
|
2011-02-16 09:38:14 +00:00
|
|
|
SUBDIRS = $(KERNDIRS)
|
2012-02-28 12:48:25 +01:00
|
|
|
STACKPROT = -fno-stack-protector
|
2010-07-31 15:53:30 +00:00
|
|
|
|
2011-11-19 12:18:39 +01:00
|
|
|
# Set your own cross compiler tool chain prefix here
|
2012-02-28 12:48:25 +01:00
|
|
|
CROSSCOMPREFIX =
|
2011-11-19 12:18:39 +01:00
|
|
|
|
|
|
|
# Uncomment both lines if compiling for the SCC!
|
2012-02-28 12:48:25 +01:00
|
|
|
#CROSSCOMPREFIX = i386-unknown-linux-gnu-
|
|
|
|
#STACKPROT =
|
|
|
|
|
|
|
|
CC_FOR_TARGET = $(CROSSCOMPREFIX)gcc
|
|
|
|
CXX_FOR_TARGET = $(CROSSCOMPREFIX)g++
|
|
|
|
GCC_FOR_TARGET = $(CROSSCOMPREFIX)gcc
|
|
|
|
CPP_FOR_TARGET = $(CROSSCOMPREFIX)cpp
|
|
|
|
AR_FOR_TARGET = $(CROSSCOMPREFIX)ar
|
|
|
|
AS_FOR_TARGET = $(CROSSCOMPREFIX)as
|
|
|
|
LD_FOR_TARGET = $(CROSSCOMPREFIX)ld
|
|
|
|
NM_FOR_TARGET = $(CROSSCOMPREFIX)nm
|
|
|
|
OBJDUMP_FOR_TARGET = $(CROSSCOMPREFIX)objdump
|
|
|
|
OBJCOPY_FOR_TARGET = $(CROSSCOMPREFIX)objcopy
|
|
|
|
RANLIB_FOR_TARGET = $(CROSSCOMPREFIX)ranlib
|
|
|
|
STRIP_FOR_TARGET = $(CROSSCOMPREFIX)strip
|
|
|
|
READELF_FOR_TARGET = $(CROSSCOMPREFIX)readelf
|
2011-03-18 05:17:56 +01:00
|
|
|
|
2012-02-28 12:48:25 +01:00
|
|
|
MAKE = make
|
|
|
|
RM = rm -rf
|
2011-11-21 03:37:19 -08:00
|
|
|
NASM = nasm
|
2012-06-10 08:05:24 +02:00
|
|
|
# For 64bit code, you have to use qemu-system-x86_64
|
2012-05-21 15:04:05 +02:00
|
|
|
QEMU = qemu-system-i386
|
2012-02-28 12:48:25 +01:00
|
|
|
EMU = qemu
|
|
|
|
GDB = gdb
|
2011-11-21 03:37:19 -08:00
|
|
|
|
2012-06-10 08:05:24 +02:00
|
|
|
# For 64bit support, you have to define -felf64 instead of -felf32
|
2012-05-21 15:04:05 +02:00
|
|
|
NASMFLAGS = -felf32 -g -i$(TOPDIR)/include/metalsvm/
|
2011-02-09 19:15:10 +00:00
|
|
|
INCLUDE = -I$(TOPDIR)/include -I$(TOPDIR)/arch/$(ARCH)/include -I$(TOPDIR)/lwip/src/include -I$(TOPDIR)/lwip/src/include/ipv4 -I$(TOPDIR)/drivers
|
2012-06-10 08:05:24 +02:00
|
|
|
# For 64bit support, you have to define "-m64 -mno-red-zone" instead of "-m32 -march=i586"
|
2011-03-22 22:11:43 +01:00
|
|
|
# Compiler options for final code
|
2012-06-10 08:05:24 +02:00
|
|
|
CFLAGS = -g -m32 -march=i586 -Wall -O2 -fstrength-reduce -fomit-frame-pointer -finline-functions -ffreestanding $(INCLUDE) $(STACKPROT)
|
2012-05-21 15:04:05 +02:00
|
|
|
# Compiler options for debuging
|
2012-06-10 08:05:24 +02:00
|
|
|
#CFLAGS = -g -O -m32 -march=i586 -Wall -DWITH_FRAME_POINTER -ffreestanding $(INCLUDE) $(STACKPROT)
|
2011-02-09 19:15:10 +00:00
|
|
|
ARFLAGS = rsv
|
2012-05-23 08:09:08 +02:00
|
|
|
LDFLAGS = -T link$(BIT).ld -z max-page-size=4096 --defsym __BUILD_DATE=$(shell date +'%Y%m%d') --defsym __BUILD_TIME=$(shell date +'%H%M%S')
|
2011-03-18 05:17:56 +01:00
|
|
|
STRIP_DEBUG = --strip-debug
|
|
|
|
KEEP_DEBUG = --only-keep-debug
|
2012-05-29 20:47:45 +02:00
|
|
|
OUTPUT_FORMAT = -O elf32-i386
|
2012-06-10 08:05:24 +02:00
|
|
|
# For 64bit support, you have to define -m64 instead of "-m32 -march=i586"
|
2012-05-23 08:03:06 +02:00
|
|
|
CFLAGS_FOR_NEWLIB = -m32 -march=i586 -O2 $(STACKPROT)
|
2012-06-10 08:05:24 +02:00
|
|
|
# For 64bit support, you have to define -m64 instead of "-m32 -march=i586"
|
2012-05-23 08:03:06 +02:00
|
|
|
LDFLAGS_FOR_NEWLIB = -m32 -march=i586
|
2012-07-10 21:47:03 +02:00
|
|
|
# For 64bit support, you have to define -m64 instead of "-m32"
|
|
|
|
CFLAGS_FOR_TOOLS = -m32 -O2 -Wall
|
|
|
|
LDFLAGS_FOR_TOOLS =
|
2012-06-10 08:05:24 +02:00
|
|
|
# For 64bit support, you have to define -felf64 instead of -felf32
|
2012-05-23 08:03:06 +02:00
|
|
|
NASMFLAGS_FOR_NEWLIB = -felf32
|
2010-07-31 15:53:30 +00:00
|
|
|
|
2011-02-09 19:15:10 +00:00
|
|
|
# Prettify output
|
|
|
|
V = 0
|
|
|
|
ifeq ($V,0)
|
|
|
|
Q = @
|
|
|
|
P = > /dev/null
|
|
|
|
endif
|
2010-07-31 15:53:30 +00:00
|
|
|
|
2011-02-09 19:15:10 +00:00
|
|
|
default: all
|
|
|
|
|
2011-03-31 12:50:42 -07:00
|
|
|
all: newlib tools $(NAME).elf
|
2011-02-09 19:15:10 +00:00
|
|
|
|
2011-02-16 09:38:14 +00:00
|
|
|
newlib:
|
2012-05-23 08:03:06 +02:00
|
|
|
$(MAKE) ARCH=$(ARCH) BIT=$(BIT) LDFLAGS="$(LDFLAGS_FOR_NEWLIB)" CFLAGS="$(CFLAGS_FOR_NEWLIB)" NASMFLAGS="$(NASMFLAGS_FOR_NEWLIB)" CC_FOR_TARGET=$(CC_FOR_TARGET) \
|
2011-03-18 05:17:56 +01:00
|
|
|
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
|
2012-05-21 15:04:05 +02:00
|
|
|
|
2011-02-16 15:27:21 +01:00
|
|
|
tools:
|
2012-07-10 21:47:03 +02:00
|
|
|
$(MAKE) CFLAGS="$(CFLAGS_FOR_TOOLS)" LDFLAGS="$(LDFLAGS_FOR_TOOLS)" -C tools
|
2011-02-16 15:27:21 +01:00
|
|
|
|
2011-03-31 12:50:42 -07:00
|
|
|
$(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
|
2012-05-29 20:47:45 +02:00
|
|
|
$Q$(OBJCOPY_FOR_TARGET) $(STRIP_DEBUG) $(OUTPUT_FORMAT) $(NAME).elf
|
2010-07-31 15:53:30 +00:00
|
|
|
|
2011-03-31 12:50:42 -07:00
|
|
|
qemu: newlib tools $(NAME).elf
|
2012-05-21 15:04:05 +02:00
|
|
|
$(QEMU) -monitor stdio -smp 2 -net nic,model=rtl8139 -net user,hostfwd=tcp::12345-:4711 -net dump -kernel metalsvm.elf -initrd tools/initrd.img
|
2011-02-17 09:24:48 +01:00
|
|
|
|
2011-05-16 13:26:49 +02:00
|
|
|
qemudbg: newlib tools $(NAME).elf
|
2012-05-21 15:04:05 +02:00
|
|
|
$(QEMU) -s -S -smp 2 -net nic,model=rtl8139 -net user,hostfwd=tcp::12345-:4711 -net dump -kernel metalsvm.elf -initrd tools/initrd.img
|
2011-05-16 13:26:49 +02:00
|
|
|
|
|
|
|
gdb: $(NAME).elf
|
|
|
|
make qemudbg > /dev/null &
|
|
|
|
$(GDB) -x script.gdb
|
|
|
|
|
2010-07-31 15:53:30 +00:00
|
|
|
clean:
|
2011-03-31 12:50:42 -07:00
|
|
|
$Q$(RM) $(NAME).elf $(NAME).sym *~
|
2011-02-16 15:27:21 +01:00
|
|
|
$Q$(MAKE) -C tools clean
|
2011-02-09 19:15:10 +00:00
|
|
|
@echo Cleaned.
|
|
|
|
|
2011-02-16 09:38:14 +00:00
|
|
|
veryclean: clean
|
|
|
|
$Q$(MAKE) -C newlib veryclean
|
|
|
|
@echo Very cleaned
|
2011-02-09 19:15:10 +00:00
|
|
|
|
|
|
|
#depend:
|
|
|
|
# for i in $(SUBDIRS); do $(MAKE) -k -C $$i depend; done
|
|
|
|
|
|
|
|
%.o : %.c
|
|
|
|
@echo [CC] $@
|
2011-03-18 05:17:56 +01:00
|
|
|
$Q$(CC_FOR_TARGET) -c -D__KERNEL__ $(CFLAGS) -o $@ $<
|
2011-02-09 19:15:10 +00:00
|
|
|
@echo [DEP] $*.dep
|
2012-05-21 15:04:05 +02:00
|
|
|
$Q$(CPP_FOR_TARGET) -MF $*.dep -MT $*.o -MM -D__KERNEL__ $(CFLAGS) $<
|
2011-02-09 19:15:10 +00:00
|
|
|
|
2012-05-22 13:38:41 +02:00
|
|
|
include/metalsvm/config.inc: include/metalsvm/config.h
|
|
|
|
@echo "; This file is generated automatically from the config.h file." > include/metalsvm/config.inc
|
|
|
|
@echo "; Before editing this, you should consider editing config.h." >> include/metalsvm/config.inc
|
|
|
|
@awk '/^#define MAX_CORES/{ print "%define MAX_CORES", $$3 }' include/metalsvm/config.h >> include/metalsvm/config.inc
|
2010-07-31 15:53:30 +00:00
|
|
|
|
2012-05-22 13:38:41 +02:00
|
|
|
%.o : %.asm include/metalsvm/config.inc
|
2011-02-09 19:15:10 +00:00
|
|
|
@echo [ASM] $@
|
2011-02-16 09:38:14 +00:00
|
|
|
$Q$(NASM) $(NASMFLAGS) -o $@ $<
|
2010-07-31 15:53:30 +00:00
|
|
|
|
2011-02-16 15:27:21 +01:00
|
|
|
.PHONY: default all clean emu gdb newlib tools
|
2011-02-09 19:15:10 +00:00
|
|
|
|
|
|
|
include $(addsuffix /Makefile,$(SUBDIRS))
|