2012-09-03 23:44:36 -04:00
|
|
|
# Aedrix root Makefile
|
2012-09-26 23:59:58 -04:00
|
|
|
# Copyright (C) 2012, Aaron Lindsay <aaron@aclindsay.com>
|
2012-09-03 23:44:36 -04:00
|
|
|
|
|
|
|
# Config options for the code itself (should be separated from the Makefile sometime)
|
2012-11-15 00:30:17 -05:00
|
|
|
ARCH ?= arm
|
|
|
|
#ARCH_KCFLAGS defined (if at all) in arch/$(ARCH)/kernel.mk
|
|
|
|
#CROSS_COMPILE defined (if at all) in arch/$(ARCH)/kernel.mk
|
2012-09-03 23:44:36 -04:00
|
|
|
|
|
|
|
# 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
|
2012-11-15 00:30:17 -05:00
|
|
|
AS = $(CROSS_COMPILE)as
|
|
|
|
CC = $(CROSS_COMPILE)gcc
|
|
|
|
LD = $(CROSS_COMPILE)ld
|
|
|
|
OBJCOPY = $(CROSS_COMPILE)objcopy
|
|
|
|
OBJDUMP = $(CROSS_COMPILE)objdump
|
2012-09-03 23:44:36 -04:00
|
|
|
|
|
|
|
# Define the flags we'll need for our tools
|
2012-10-14 23:02:14 -04:00
|
|
|
INCLUDES = -I include -I arch/$(ARCH)/include
|
2012-11-15 00:30:17 -05:00
|
|
|
KCFLAGS = -g -Wall -Wextra -Werror -nostdlib -nostartfiles -fno-builtin -std=gnu99 $(ARCH_KCFLAGS) -include config.h $(INCLUDES)
|
2014-09-08 19:42:05 -04:00
|
|
|
KLDFLAGS = -T arch/$(ARCH)/kernel.ld $(ARCH_KLDFLAGS)
|
2012-11-15 00:30:17 -05:00
|
|
|
EXTRA_LIBS = $(ARCH_EXTRA_LIBS)
|
2012-09-03 23:44:36 -04:00
|
|
|
|
2012-10-03 00:19:28 -04:00
|
|
|
# Include the config file so we don't compile/link unnecessary objects
|
|
|
|
include config
|
|
|
|
|
2012-09-26 15:35:52 -04:00
|
|
|
# Define KOBJS as a 'simply expanded' variable
|
|
|
|
KOBJS :=
|
|
|
|
|
|
|
|
# Initialize sub-directory Makefile inclusion
|
|
|
|
BASEDIR = $(shell pwd)
|
2012-10-14 23:02:14 -04:00
|
|
|
SUBDIRS := arch/$(ARCH) kernel drivers
|
2012-09-26 15:35:52 -04:00
|
|
|
ifneq (,$(SUBDIRS))
|
|
|
|
include $(patsubst %,%/kernel.mk,$(SUBDIRS))
|
|
|
|
endif
|
2012-09-03 23:44:36 -04:00
|
|
|
|
2014-09-08 21:27:01 -04:00
|
|
|
.PHONY: all tags clean boot boot-gdb
|
2012-09-21 11:48:31 -04:00
|
|
|
|
2012-09-17 23:34:16 -04:00
|
|
|
all: aedrix-kernel.img aedrix-kernel.elf
|
2012-09-03 23:44:36 -04:00
|
|
|
|
2012-09-17 23:34:16 -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
|
|
|
|
2012-09-23 01:22:49 -04:00
|
|
|
aedrix-kernel.objdump: aedrix-kernel.elf
|
2012-09-25 22:58:50 -04:00
|
|
|
@echo 'OBJDUMP $@'
|
|
|
|
$(V)$(OBJDUMP) -D $< > $@
|
2012-09-23 01:22:49 -04:00
|
|
|
|
2012-09-17 23:34:16 -04:00
|
|
|
aedrix-kernel.img: aedrix-kernel.elf
|
2012-09-25 22:58:50 -04:00
|
|
|
@echo 'OBJCOPY $@'
|
|
|
|
$(V)$(OBJCOPY) $< -O binary $@
|
2012-09-17 23:34:16 -04:00
|
|
|
|
2012-10-03 00:19:28 -04:00
|
|
|
%.o: %.c config.h
|
2012-09-25 22:58:50 -04:00
|
|
|
@echo ' CC $@'
|
2012-09-26 23:35:52 -04:00
|
|
|
$(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
|
|
|
|
2012-10-03 00:19:28 -04:00
|
|
|
%.o: %.S config.h
|
2012-09-25 22:58:50 -04:00
|
|
|
@echo ' AS $@'
|
2012-09-26 23:35:52 -04:00
|
|
|
$(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
|
|
|
|
2012-10-03 00:19:28 -04:00
|
|
|
config.h: config
|
2012-10-03 07:35:10 -04:00
|
|
|
@# Generate config header file from make-style include
|
2012-10-03 00:19:28 -04:00
|
|
|
@echo ' CONFIG config.h'
|
|
|
|
@cp config config.h
|
2012-10-03 07:35:10 -04:00
|
|
|
@sed -i '/^\s*#/d' config.h
|
|
|
|
@sed -i 's/#.*$$//g' config.h
|
2012-10-03 00:19:28 -04:00
|
|
|
@sed -i '/^\s*\(CONFIG_[A-Z0-9_]\+\)\s*=\s*[nN]/d' config.h
|
|
|
|
@sed -i 's/^\s*\(CONFIG_[A-Z0-9_]\+\)\s*=\s*[yY]/#define \1/g' config.h
|
2013-01-01 23:53:18 -05:00
|
|
|
@sed -i 's/^\s*\(CONFIG_[A-Z0-9_]\+\)\s*=\s*\([0-9]\+\)/#define \1 \2/g' config.h
|
2012-10-03 00:19:28 -04:00
|
|
|
|
2014-09-08 21:27:01 -04:00
|
|
|
tags:
|
|
|
|
@echo ' CTAGS tags'
|
|
|
|
$(V)ctags -R $(SUBDIRS)
|
|
|
|
|
2012-09-03 23:44:36 -04:00
|
|
|
clean:
|
2012-10-03 00:19:28 -04:00
|
|
|
@echo ' CLEAN config.h'
|
|
|
|
$(V)rm -f config.h
|
2012-09-25 22:58:50 -04:00
|
|
|
@echo ' CLEAN *.o'
|
|
|
|
$(V)rm -f $(KOBJS)
|
2012-09-26 23:35:52 -04:00
|
|
|
@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
|
2014-09-08 21:27:01 -04:00
|
|
|
@echo ' CLEAN tags'
|
|
|
|
$(V)rm -f tags
|
2012-09-25 22:58:50 -04:00
|
|
|
|
2012-11-15 00:30:17 -05:00
|
|
|
boot-elf: aedrix-kernel.elf
|
|
|
|
$(V)$(ARCH_QEMU_CMD) -kernel aedrix-kernel.elf -serial stdio
|
|
|
|
boot-img: aedrix-kernel.img
|
|
|
|
$(V)$(ARCH_QEMU_CMD) -kernel aedrix-kernel.img -serial stdio
|
|
|
|
boot-hda: aedrix-boot.img
|
|
|
|
$(V)$(ARCH_QEMU_CMD) -hda aedrix-boot.img -serial stdio
|
|
|
|
boot-elf-gdb: aedrix-kernel.elf
|
|
|
|
$(V)$(ARCH_QEMU_CMD) -kernel aedrix-kernel.elf -serial stdio -S -s
|
|
|
|
boot-img-gdb: aedrix-kernel.img
|
|
|
|
$(V)$(ARCH_QEMU_CMD) -kernel aedrix-kernel.img -serial stdio -S -s
|
|
|
|
boot-hda-gdb: aedrix-boot.img
|
|
|
|
$(V)$(ARCH_QEMU_CMD) -hda aedrix-boot.img -serial stdio -S -s
|
2012-09-26 23:35:52 -04:00
|
|
|
|
|
|
|
DEPENDENCY_FILES = $(foreach file,$(KOBJS), $(dir $(file)).$(notdir $(basename $(file))).d)
|
|
|
|
-include $(DEPENDENCY_FILES)
|