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
CFLAGS_KERNEL += -std=gnu99 -fgnu89-inline
# 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
ext2_bdev_obj = $(OBJDIR)/kern/$(shell basename $(ext2-bdev)).o
endif
-kern_initramfs_files := $(shell mkdir -p $(kfs-paths); \
- find $(kfs-paths))
+# a bit hacky: we want to make sure the directories exist, and error out
+# otherwise. we also want to error out before the initramfs target, otherwise
+# we might not get the error (if initramfs files are all up to date). the
+# trickiest thing here is that kfs-paths-check could be stale and require an
+# oldconfig. running make twice should suffice.
+kfs-paths-check := $(shell for i in $(kfs-paths); do \
+ if [ ! -d "$$i" ]; then \
+ echo "Can't find KFS directory $$i"; \
+ $(MAKE) -f $(srctree)/Makefile \
+ silentoldconfig > /dev/null; \
+ exit -1; \
+ fi; \
+ done; echo "ok")
+
+ifneq (ok,$(kfs-paths-check))
+$(error $(kfs-paths-check), try make one more time in case of stale configs)
+endif
+
+kern_initramfs_files := $(shell 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 $@ \
- $(LDFLAGS_KERNEL) \
- $(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