simplified example Makefile

(now the same one as in my eduOS repo)
This commit is contained in:
Steffen Vogel 2014-08-14 20:18:52 +02:00
parent 2f0dc49a7e
commit a5087905df

View file

@ -2,9 +2,10 @@ NAME = metalsvm
# For 64bit support, you have define BIT as 64
# Note: do not forget to 'make veryclean' after changing BIT!!!
BIT=64
BIT = 64
ARCH = x86
SMP=1
SMP = 2
DEBUG = 1
TOPDIR = $(shell pwd)
LWIPDIRS = lwip/src/arch lwip/src/api lwip/src/core lwip/src/core/ipv4 lwip/src/netif
@ -46,23 +47,22 @@ else ifeq ($(BIT), 64)
QEMU = qemu-system-x86_64
endif
INCLUDE = -I$(TOPDIR)/include \
-I$(TOPDIR)/arch/$(ARCH)/include \
-I$(TOPDIR)/lwip/src/include \
-I$(TOPDIR)/lwip/src/include/ipv4 \
-I$(TOPDIR)/drivers
# Compiler options for final code
CFLAGS = -g -O2 -m$(BIT) -Wall -fomit-frame-pointer -ffreestanding -fstrength-reduce -finline-functions $(INCLUDE) $(STACKPROT)
# Compiler options for debuging
#CFLAGS = -g -O -m$(BIT) -Wall -fomit-frame-pointer -ffreestanding $(INCLUDE) $(STACKPROT)
GDBFLAGS = -x script.gdb
QEMUFLAGS = -smp $(SMP) -serial tcp::12346,server \
-nographic -monitor stdio \
-net nic,model=rtl8139 \
-net user,hostfwd=tcp::12345-:4711
NASMFLAGS = -felf$(BIT) -g -i$(TOPDIR)/include/metalsvm/
CFLAGS = -m$(BIT) -Wall -ffreestanding $(INCLUDE) $(STACKPROT)
ARFLAGS = rsv
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')
LDFLAGS = -T link$(BIT).ld -z max-page-size=0x1000 --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
@ -71,12 +71,21 @@ KEEP_DEBUG = --only-keep-debug
# The Multiboot spec can only boot elf32 binaries
OUTPUT_FORMAT = -O elf32-i386
CFLAGS_FOR_NEWLIB = -m$(BIT) -O2 $(STACKPROT)
CFLAGS_FOR_NEWLIB = -m$(BIT) $(STACKPROT)
LDFLAGS_FOR_NEWLIB = -m$(BIT)
CFLAGS_FOR_TOOLS = -m$(BIT) -O2 -Wall
LDFLAGS_FOR_TOOLS =
NASMFLAGS_FOR_NEWLIB = -felf$(BIT)
# Setup debugging flags here
ifndef DEBUG
CFLAGS += -O2 -fomit-frame-pointer -fstrength-reduce -finline-functions
CFLAGS_FOR_NEWLIB += -O2
else
CFLAGS += -O0 -gdwarf-2
CFLAGS_FOR_NEWLIB += -O0 -gdwarf-2
endif
ifeq ($(BIT), 32)
CFLAGS += -march=i586
CFLAGS_FOR_NEWLIB += -march=i586
@ -115,7 +124,7 @@ newlib:
READELF_FOR_TARGET=$(READELF_FOR_TARGET) -C newlib
tools:
$(MAKE) CFLAGS="$(CFLAGS_FOR_TOOLS)" LDFLAGS="$(LDFLAGS_FOR_TOOLS)" -C tools
$(MAKE) ARCH=$(ARCH) BIT=$(BIT) CFLAGS="$(CFLAGS_FOR_TOOLS)" LDFLAGS="$(LDFLAGS_FOR_TOOLS)" -C tools
$(NAME).elf:
$Q$(LD_FOR_TARGET) $(LDFLAGS) -o $(NAME).elf $^
@ -125,26 +134,22 @@ $(NAME).elf:
$Q$(OBJCOPY_FOR_TARGET) $(STRIP_DEBUG) $(OUTPUT_FORMAT) $(NAME).elf
qemu: newlib tools $(NAME).elf
$(QEMU) -monitor stdio -serial tcp::12346,server,nowait -smp $(SMP) -net nic,model=rtl8139 -net user,hostfwd=tcp::12345-:4711 -kernel metalsvm.elf -initrd tools/initrd.img
qemudbg: newlib tools $(NAME).elf
$(QEMU) -s -S -nographic -monitor stdio -serial tcp::12346,server -smp $(SMP) -net nic,model=rtl8139 -net user,hostfwd=tcp::12345-:4711 -kernel metalsvm.elf -initrd tools/initrd.img
gdb: $(NAME).elf
$(GDB) -q -x script.gdb
$(QEMU) $(QEMUFLAGS) -kernel metalsvm.elf -initrd tools/initrd.img
debug: newlib tools $(NAME).elf
killall $(QEMU) || true
killall $(GDB) || true
sleep 1
gnome-terminal --working-directory=$(TOPDIR) \
--tab --title=Shell --command="bash -c 'sleep 1 && telnet localhost 12345'" \
--tab --title=QEmu --command="make qemudbg" \
--tab --title=GDB --command="make gdb" \
--tab --title=Debug --command="bash -c 'sleep 1 && telnet localhost 12346'"
$(TERM) -e $(GDB) $(GDBFLAGS) &
$(TERM) -e telnet localhost 12346 &
$(TERM) -e telnet localhost 12345 &
$(QEMU) $(QEMUFLAGS) -s -S -kernel metalsvm.elf -initrd tools/initrd.img
hwdebug: newlib tools $(NAME).elf
killall -qw mongoose cu || true
mongoose -p 8080 &
hwreset push reset 300
cu -s 115200 -l /dev/ttyUSB0
clean:
$Q$(RM) $(NAME).elf $(NAME).sym *~
$Q$(RM) $(NAME).elf $(NAME).sym *~ core core.*
$Q$(MAKE) -C tools clean
@echo Cleaned.