1
0

Add simple config system for both #ifdef's and conditional compilation

This commit is contained in:
2012-10-03 00:19:28 -04:00
parent 736155ce99
commit 3876937ae9
5 changed files with 48 additions and 9 deletions

View File

@ -18,10 +18,13 @@ OBJDUMP = $(TOOL_PREFIX)objdump
# Define the flags we'll need for our tools
INCLUDES = -I include
KCFLAGS = -g -Wall -Wextra -Werror -nostdlib -nostartfiles -fno-builtin -std=gnu99 $(INCLUDES)
KCFLAGS = -g -Wall -Wextra -Werror -nostdlib -nostartfiles -fno-builtin -std=gnu99 -include config.h $(INCLUDES)
KLDFLAGS = -T link.ld -L /usr/lib/gcc/arm-elf/4.7.0/
EXTRA_LIBS = -lgcc
# Include the config file so we don't compile/link unnecessary objects
include config
# Define KOBJS as a 'simply expanded' variable
KOBJS :=
@ -48,7 +51,7 @@ aedrix-kernel.img: aedrix-kernel.elf
@echo 'OBJCOPY $@'
$(V)$(OBJCOPY) $< -O binary $@
%.o: %.c
%.o: %.c config.h
@echo ' CC $@'
$(V)$(CC) $(KCFLAGS) -MD -c -o $@ $<
@# Automatic dependency generation fixups (http://mad-scientist.net/make/autodep.html)
@ -57,7 +60,7 @@ aedrix-kernel.img: aedrix-kernel.elf
-e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $(*D)/.$(*F).d; \
rm -f $*.d
%.o: %.S
%.o: %.S config.h
@echo ' AS $@'
$(V)$(CC) $(KCFLAGS) -MD -c -o $@ $<
@# Automatic dependency generation fixups (http://mad-scientist.net/make/autodep.html)
@ -66,7 +69,16 @@ aedrix-kernel.img: aedrix-kernel.elf
-e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $(*D)/.$(*F).d; \
rm -f $*.d
config.h: config
@echo ' CONFIG config.h'
@cp config config.h
@sed -i '/^\w*#/d' 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
clean:
@echo ' CLEAN config.h'
$(V)rm -f config.h
@echo ' CLEAN *.o'
$(V)rm -f $(KOBJS)
@echo ' CLEAN .*.d'