1
0
aedrix-kernel/Makefile

88 lines
2.6 KiB
Makefile
Raw Normal View History

2012-09-03 23:44:36 -04:00
# Aedrix root Makefile
# Copyright (C) 2012 Aaron Lindsay <aaron@aclindsay.com>
# Config options for the code itself (should be separated from the Makefile sometime)
ARCH = arm
# Config options concerning the build process itself
2012-09-25 22:58:50 -04:00
VERBOSE ?= 0 # 1 shows all compiler flags, 0 shows cleaner output
V = $(if $(VERBOSE:1=),@) # Use this to prefix commands that should only be shown when VERBOSE==1
2012-09-03 23:44:36 -04:00
# Define the tools to be used
TOOL_PREFIX = arm-elf-
AS = $(TOOL_PREFIX)as
CC = $(TOOL_PREFIX)gcc
LD = $(TOOL_PREFIX)ld
2012-09-25 22:58:50 -04:00
OBJCOPY = $(TOOL_PREFIX)objcopy
OBJDUMP = $(TOOL_PREFIX)objdump
2012-09-03 23:44:36 -04:00
# Define the flags we'll need for our tools
INCLUDES = -I include
KCFLAGS = -g -Wall -Wextra -Werror -nostdlib -nostartfiles -fno-builtin -std=gnu99 $(INCLUDES)
KLDFLAGS = -T link.ld -L /usr/lib/gcc/arm-elf/4.7.0/
EXTRA_LIBS = -lgcc
2012-09-03 23:44:36 -04:00
# Define KOBJS as a 'simply expanded' variable
KOBJS :=
# Initialize sub-directory Makefile inclusion
BASEDIR = $(shell pwd)
SUBDIRS := boot kernel devices
ifneq (,$(SUBDIRS))
include $(patsubst %,%/kernel.mk,$(SUBDIRS))
endif
2012-09-03 23:44:36 -04:00
2012-09-25 22:58:50 -04:00
.PHONY: all clean boot boot-gdb
2012-09-21 11:48:31 -04:00
all: aedrix-kernel.img aedrix-kernel.elf
2012-09-03 23:44:36 -04:00
aedrix-kernel.elf: $(KOBJS)
2012-09-25 22:58:50 -04:00
@echo ' LD $@'
$(V)$(LD) $(KLDFLAGS) -o $@ $(KOBJS) $(EXTRA_LIBS)
2012-09-03 23:44:36 -04:00
aedrix-kernel.objdump: aedrix-kernel.elf
2012-09-25 22:58:50 -04:00
@echo 'OBJDUMP $@'
$(V)$(OBJDUMP) -D $< > $@
aedrix-kernel.img: aedrix-kernel.elf
2012-09-25 22:58:50 -04:00
@echo 'OBJCOPY $@'
$(V)$(OBJCOPY) $< -O binary $@
2012-09-03 23:44:36 -04:00
%.o: %.c
2012-09-25 22:58:50 -04:00
@echo ' CC $@'
$(V)$(CC) $(KCFLAGS) -MD -c -o $@ $<
@# Automatic dependency generation fixups (http://mad-scientist.net/make/autodep.html)
@cp $*.d $(*D)/.$(*F).d; \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $(*D)/.$(*F).d; \
rm -f $*.d
2012-09-03 23:44:36 -04:00
%.o: %.S
2012-09-25 22:58:50 -04:00
@echo ' AS $@'
$(V)$(CC) $(KCFLAGS) -MD -c -o $@ $<
@# Automatic dependency generation fixups (http://mad-scientist.net/make/autodep.html)
@cp $*.d $(*D)/.$(*F).d; \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $(*D)/.$(*F).d; \
rm -f $*.d
2012-09-03 23:44:36 -04:00
clean:
2012-09-25 22:58:50 -04:00
@echo ' CLEAN *.o'
$(V)rm -f $(KOBJS)
@echo ' CLEAN .*.d'
$(V)rm -f $(DEPENDENCY_FILES)
2012-09-25 22:58:50 -04:00
@echo ' CLEAN aedrix-kernel.elf'
$(V)rm -f aedrix-kernel.elf
@echo ' CLEAN aedrix-kernel.objdump'
$(V)rm -f aedrix-kernel.objdump
@echo ' CLEAN aedrix-kernel.img'
$(V)rm -f aedrix-kernel.img
boot: aedrix-kernel.img
$(V)qemu-system-arm -m 1024 -M vexpress-a9 -kernel aedrix-kernel.img -serial stdio
boot-gdb: aedrix-kernel.img
$(V)qemu-system-arm -m 1024 -M vexpress-a9 -kernel aedrix-kernel.img -serial stdio -S -s
DEPENDENCY_FILES = $(foreach file,$(KOBJS), $(dir $(file)).$(notdir $(basename $(file))).d)
-include $(DEPENDENCY_FILES)