OBJDUMP := $(CROSS_COMPILE)objdump
NM := $(CROSS_COMPILE)nm
STRIP := $(CROSS_COMPILE)strip
+KERNEL_LD ?= kernel.ld
# These may have bogus values if there is no compiler. The kernel and user
# build targets will check cc-exists. Hopefully no cleaning targets rely on
gcc-lib := $(shell $(CC) -print-libgcc-file-name 2>/dev/null)
NOSTDINC_FLAGS += -nostdinc -isystem \
$(shell $(CC) -print-file-name=include 2>/dev/null)
-XCC_TARGET_ROOT := $(dir $(shell which $(CC)))../$(patsubst %-,%,\
- $(CROSS_COMPILE))
+XCC_TARGET_ROOT := $(dir $(shell which $(CC) 2> /dev/null))../$(patsubst %-,%,\
+ $(CROSS_COMPILE))
-CFLAGS_KERNEL += -O2 -pipe -MD -gstabs
+CFLAGS_KERNEL += -O2 -pipe -MD
CFLAGS_KERNEL += -std=gnu99 -fgnu89-inline
CFLAGS_KERNEL += -fno-strict-aliasing -fno-omit-frame-pointer
CFLAGS_KERNEL += -fno-stack-protector
ifeq ($(CONFIG_64BIT),y)
CFLAGS_KERNEL += -m64
else
-CFLAGS_KERNEL += -m32
+CFLAGS_KERNEL += -m32 -gstabs
endif
# TODO: do we need this, or can we rely on the compiler's defines?
# KFS_PATH. Future rules related to KFS will have issues (mkdir with no
# argument, or a find of the entire pwd). It's also possible someone provided
# an empty path. To deal with both, we'll just have a sensible default.
-kfs-paths := $(patsubst "%",%,$(CONFIG_KFS_PATHS))
+kfs-paths := $(subst $\",,$(CONFIG_KFS_PATHS))
ifeq ($(kfs-paths),)
kfs-paths := kern/kfs
endif
arch-y := $(patsubst %/, %/built-in.o, $(arch-y))
kbuild_akaros_main := $(core-y) $(arch-y)
-akaros-deps := $(kbuild_akaros_main) kern/arch/$(ARCH)/kernel.ld
+akaros-deps := $(kbuild_akaros_main) kern/arch/$(ARCH)/$(KERNEL_LD)
kern_cpio := $(OBJDIR)/kern/initramfs.cpio
kern_cpio_obj := $(kern_cpio).o
kern_initramfs_files := $(shell mkdir -p $(kfs-paths); \
find $(kfs-paths))
+# Need to make an empty cpio, then append each kfs-path's contents
$(kern_cpio) initramfs: $(kern_initramfs_files)
@echo " Building initramfs:"
@if [ "$(CONFIG_KFS_CPIO_BIN)" != "" ]; then \
sh $(CONFIG_KFS_CPIO_BIN); \
fi
+ @cat /dev/null | cpio --quiet -oH newc -O $(kern_cpio)
$(Q)for i in $(kfs-paths); do cd $$i; \
echo " Adding $$i to initramfs..."; \
- find -L . | cpio --quiet -oH newc > \
- $(CURDIR)/$(kern_cpio); \
+ find -L . | cpio --quiet -oAH newc -O $(CURDIR)/$(kern_cpio); \
cd $$OLDPWD; \
done;
ld_emulation = $(shell $(OBJDUMP) -i | grep -v BFD | grep ^[a-z] |head -n1)
ld_arch = $(shell $(OBJDUMP) -i | grep -v BFD | grep "^ [a-z]" | head -n1)
+# Our makefile doesn't detect a change in subarch, and old binary objects that
+# don't need to be updated won't get rebuilt, but they also can't link with the
+# new subarch (32 bit vs 64 bit). If we detect the wrong type, we'll force a
+# rebuild.
+existing-cpio-emul := $(shell objdump -f $(kern_cpio_obj) 2> /dev/null | \
+ grep format | sed 's/.*format //g')
+ifneq ($(existing-cpio-emul),)
+ifneq ($(existing-cpio-emul),$(ld_emulation))
+$(kern_cpio_obj): cpio-rebuild
+cpio-rebuild:
+ $(Q)rm $(kern_cpio_obj)
+endif
+endif
+
$(kern_cpio_obj): $(kern_cpio)
- $(Q)$(OBJCOPY) -I binary -B $(ld_arch) -O $(ld_emulation) $^ $@
+ $(Q)$(OBJCOPY) -I binary -B $(ld_arch) -O $(ld_emulation) $< $@
+
+existing-ext2b-emul := $(shell objdump -f $(kern_cpio_obj) 2> /dev/null | \
+ grep format | sed 's/.*format //g')
+ifneq ($(existing-ext2b-emul),)
+ifneq ($(existing-ext2b-emul),$(ld_emulation))
+$(ext2_bdev_obj): ext2b-rebuild
+ext2b-rebuild:
+ $(Q)rm $(ext2_bdev_obj)
+endif
+endif
-# If no ext2, this will be (empty) : (empty)
$(ext2_bdev_obj): $(ext2-bdev)
- $(Q)$(OBJCOPY) -I binary -B $(ld_arch) -O $(ld_emulation) $^ $@
+ $(Q)$(OBJCOPY) -I binary -B $(ld_arch) -O $(ld_emulation) $< $@
+# Not the worlds most elegant link command. link-kernel takes the obj output
+# name, then the linker script, then everything else you'd dump on the ld
+# command line, including linker options and objects to link together.
+#
+# After the script is done, we run the arch-specific command directly.
quiet_cmd_link-akaros = LINK $@
- cmd_link-akaros = $(LD) -T kern/arch/$(ARCH)/kernel.ld -o $@ \
- $(akaros-deps) \
- $(gcc-lib) \
- $(kern_cpio_obj) \
- $(ext2_bdev_obj) ; \
- $(OBJDUMP) -S $@ > $@.asm
+ cmd_link-akaros = $(CONFIG_SHELL) scripts/link-kernel.sh $@ \
+ kern/arch/$(ARCH)/$(KERNEL_LD) $(LDFLAGS_KERNEL) \
+ $(akaros-deps) $(gcc-lib) $(kern_cpio_obj) \
+ $(ext2_bdev_obj); \
+ $(ARCH_POST_LINK_CMD)
# For some reason, the if_changed doesn't work with FORCE (like it does in
# Linux). It looks like it can't find the .cmd file or something (also
XCC_SO_FILES = $(addprefix $(XCC_TARGET_ROOT)/lib/, *.so*)
$(OBJDIR)/.dont-force-fill-kfs:
- @rm -rf $(addprefix $(FIRST_KFS_PATH)/lib, $(notdir $(XCC_SO_FILES)))
+ $(Q)rm -rf $(addprefix $(FIRST_KFS_PATH)/lib/, $(notdir $(XCC_SO_FILES)))
@echo "Cross Compiler 'so' files removed from KFS"
@$(MAKE) -f tests/Makefile unfill-kfs
@touch $(OBJDIR)/.dont-force-fill-kfs
fill-kfs: $(OBJDIR)/.dont-force-fill-kfs install-libs
@mkdir -p $(FIRST_KFS_PATH)/lib
- @cp -uP $(XCC_SO_FILES) $(FIRST_KFS_PATH)/lib
+ $(Q)cp -uP $(XCC_SO_FILES) $(FIRST_KFS_PATH)/lib
@echo "Cross Compiler 'so' files installed to KFS"
@$(MAKE) -f tests/Makefile fill-kfs