112 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			Makefile
		
	
	
	
	
	
			
		
		
	
	
			112 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			Makefile
		
	
	
	
	
	
| # 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
 | |
| #ARCH_KCFLAGS defined (if at all) in arch/$(ARCH)/kernel.mk
 | |
| #CROSS_COMPILE defined (if at all) in arch/$(ARCH)/kernel.mk
 | |
| 
 | |
| # Config options concerning the build process itself
 | |
| 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
 | |
| 
 | |
| # Define the tools to be used
 | |
| AS = $(CROSS_COMPILE)as
 | |
| CC = $(CROSS_COMPILE)gcc
 | |
| LD = $(CROSS_COMPILE)ld
 | |
| OBJCOPY = $(CROSS_COMPILE)objcopy
 | |
| OBJDUMP = $(CROSS_COMPILE)objdump
 | |
| 
 | |
| # Define the flags we'll need for our tools
 | |
| INCLUDES = -I include -I arch/$(ARCH)/include
 | |
| KCFLAGS = -g -Wall -Wextra -Werror -nostdlib -nostartfiles -fno-builtin -std=gnu99 $(ARCH_KCFLAGS) -include config.h $(INCLUDES)
 | |
| KLDFLAGS = -T arch/$(ARCH)/kernel.ld $(ARCH_KLDFLAGS)
 | |
| EXTRA_LIBS = $(ARCH_EXTRA_LIBS)
 | |
| 
 | |
| # Include the config file so we don't compile/link unnecessary objects
 | |
| include config
 | |
| 
 | |
| # Define KOBJS as a 'simply expanded' variable
 | |
| KOBJS :=
 | |
| 
 | |
| # Initialize sub-directory Makefile inclusion
 | |
| BASEDIR = $(shell pwd)
 | |
| SUBDIRS := arch/$(ARCH) kernel drivers
 | |
| ifneq (,$(SUBDIRS))
 | |
| 	include $(patsubst %,%/kernel.mk,$(SUBDIRS))
 | |
| endif
 | |
| 
 | |
| .PHONY: all clean boot boot-gdb
 | |
| 
 | |
| all: aedrix-kernel.img aedrix-kernel.elf
 | |
| 
 | |
| aedrix-kernel.elf: $(KOBJS)
 | |
| 	@echo '     LD   $@'
 | |
| 	$(V)$(LD) $(KLDFLAGS) -o $@ $(KOBJS) $(EXTRA_LIBS)
 | |
| 
 | |
| aedrix-kernel.objdump: aedrix-kernel.elf
 | |
| 	@echo 'OBJDUMP   $@'
 | |
| 	$(V)$(OBJDUMP) -D $< > $@
 | |
| 
 | |
| aedrix-kernel.img: aedrix-kernel.elf
 | |
| 	@echo 'OBJCOPY   $@'
 | |
| 	$(V)$(OBJCOPY) $< -O binary $@
 | |
| 
 | |
| %.o: %.c config.h
 | |
| 	@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
 | |
| 
 | |
| %.o: %.S config.h
 | |
| 	@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
 | |
| 
 | |
| config.h: config
 | |
| 	@# Generate config header file from make-style include
 | |
| 	@echo ' CONFIG   config.h'
 | |
| 	@cp config config.h
 | |
| 	@sed -i '/^\s*#/d' config.h
 | |
| 	@sed -i 's/#.*$$//g' config.h
 | |
| 	@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
 | |
| 	@sed -i 's/^\s*\(CONFIG_[A-Z0-9_]\+\)\s*=\s*\([0-9]\+\)/#define \1 \2/g' config.h
 | |
| 
 | |
| clean:
 | |
| 	@echo '  CLEAN   config.h'
 | |
| 	$(V)rm -f config.h
 | |
| 	@echo '  CLEAN   *.o'
 | |
| 	$(V)rm -f $(KOBJS)
 | |
| 	@echo '  CLEAN   .*.d'
 | |
| 	$(V)rm -f $(DEPENDENCY_FILES)
 | |
| 	@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-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
 | |
| 
 | |
| DEPENDENCY_FILES = $(foreach file,$(KOBJS), $(dir $(file)).$(notdir $(basename $(file))).d)
 | |
| -include $(DEPENDENCY_FILES)
 |