#
# - There are a few other TODOs sprinkled throughout the makefile.
+# Allow people to override our setting of the --no-print-directory option in
+# their Makelocal. This is useful, for example, to allow emacs to find the
+# correct file when errors are encountered using its builtin 'M-x compile'
+# command.
+VERSION = 0
+PATCHLEVEL = 1
+SUBLEVEL = 0
+EXTRAVERSION =
+VERNAME = Nanwan
+
+KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
+
+export KERNELVERSION VERNAME
+
+NO_PRINT_DIRECTORY ?= --no-print-directory
+
+# Save the ability to export the parent's original environment for future use
+export_parent_env := $(shell export | sed 's/$$/;/')
+
+# Save the ability to clear the current environment for future use
+clear_current_env := for c in $$(env | cut -d '=' -f 1); do unset $$c; done;
+
+define export_user_variables
+ CROSS_COMPILE="$(CROSS_COMPILE)"\
+ CROSS_INCLUDE="$(XCC_TARGET_INCLUDE)"\
+ ROS_CFLAGS="$(CFLAGS_USER)"\
+ ROS_LDFLAGS="$(LDFLAGS_USER)"
+endef
+
+# Define a set of commands to reset the environment to the parent's environment
+# and then run a local make target
+define make_as_parent
+ $(clear_current_env)\
+ $(export_parent_env)\
+ $(call export_user_variables)\
+ $(MAKE) $(NO_PRINT_DIRECTORY) $(1)
+endef
+
# Do not:
# o use make's built-in rules and variables
# (this increases performance and avoids hard-to-debug behaviour);
# o print "Entering directory ...";
-MAKEFLAGS += -rR --no-print-directory
+MAKEFLAGS += -rR $(NO_PRINT_DIRECTORY)
# That's our default target when none is given on the command line
# This can be overriden with a Makelocal
PHONY := all
all: akaros-kernel
+# Export the location of this top level directory
+AKAROS_ROOT = $(CURDIR)
+export AKAROS_ROOT
+
# Setup dumping ground for object files and any temporary files we need to
# generate for non-kbuild targets
OBJDIR ?= obj
+# Don't need to export these, since the Makelocal is included.
+KERNEL_OBJ := $(OBJDIR)/kern/akaros-kernel
+CMP_KERNEL_OBJ := $(KERNEL_OBJ).gz
+
# Symlinks
# =========================================================================
# We have a few symlinks so that code can include <arch/whatever.h>. This
PHONY += symlinks clean_symlinks
clean_symlinks: objclean
- @rm -f kern/include/arch kern/boot user/parlib/include/arch
+ @rm -f kern/include/arch kern/boot user/parlib/include/parlib/arch
arch-link := $(notdir $(shell readlink kern/include/arch))
valid-arches := $(notdir $(wildcard kern/arch/*))
@echo Making symlinks...
$(Q)ln -fs ../arch/$(ARCH) kern/include/arch
$(Q)ln -fs arch/$(ARCH)/boot kern/boot
- $(Q)ln -fs $(ARCH) user/parlib/include/arch
+ $(Q)ln -fs $(ARCH) user/parlib/include/parlib/arch
$(Q)$(MAKE) -f $(srctree)/Makefile clean
else
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) 2> /dev/null))../$(patsubst %-,%,\
- $(CROSS_COMPILE))
+XCC_TARGET_ROOT := $(shell $(CC) --print-sysroot 2> /dev/null)
+XCC_TARGET_LIB := $(XCC_TARGET_ROOT)/usr/lib/
+XCC_TARGET_INCLUDE := $(XCC_TARGET_ROOT)/usr/include/
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
-CFLAGS_KERNEL += -Wall -Wno-format -Wno-unused
+CFLAGS_KERNEL += -Wall -Wno-format -Wno-unused -Werror
CFLAGS_KERNEL += -DROS_KERNEL
CFLAGS_KERNEL += -include include/generated/autoconf.h -include include/common.h
CFLAGS_KERNEL += -fplan9-extensions
export AKAROSINCLUDE CROSS_COMPILE
export CC CPP AS AR LD OBJCOPY OBJDUMP NM STRIP
export CFLAGS_KERNEL AFLAGS_KERNEL
-export NOSTDINC_FLAGS XCC_TARGET_ROOT
+export NOSTDINC_FLAGS XCC_TARGET_ROOT XCC_TARGET_LIB XCC_TARGET_INCLUDE
export KBUILD_BUILTIN KBUILD_CHECKSRC
-CFLAGS_USER += -O2 -std=gnu99 -fno-stack-protector -fgnu89-inline
+CFLAGS_USER += -O2 -std=gnu99 -fno-stack-protector -fgnu89-inline \
+ -Wsystem-headers
CXXFLAGS_USER += -O2
+CFLAGS_USER_LIBS += -fPIC -static -fno-omit-frame-pointer -g
-export CFLAGS_USER CXXFLAGS_USER
+export CFLAGS_USER CXXFLAGS_USER CFLAGS_USER_LIBS
# Akaros include stuff (includes custom make targets and user overrides)
# =========================================================================
# kernel build output. Right now, it's only passed down to tests/
dummy-1 := $(shell mkdir -p $(OBJDIR)/kern/)
-# Don't need to export these, since the Makelocal is included.
-KERNEL_OBJ := $(OBJDIR)/kern/akaros-kernel
-CMP_KERNEL_OBJ := $(KERNEL_OBJ).gz
+# Machinery to create the kernel build info source
+export BUILD_INFO_FILE
# Since we're doing this outside of the dot-config part, some targets, such as
# clean, won't read in our .config/auto.conf, and won't know about the
endif
FIRST_KFS_PATH = $(firstword $(kfs-paths))
+ABS_KFS_PATH = $(abspath $(FIRST_KFS_PATH))
-export OBJDIR FIRST_KFS_PATH
+export OBJDIR FIRST_KFS_PATH ABS_KFS_PATH
# Avoiding implicit rules
$(srctree)/Makelocal: ;
# We have all-arch-dirs and all-dirs, so that we can still clean even without
# an arch symlink.
-core-y += kern/src/ kern/drivers/ $(AKAROS_EXTERNAL_DIRS)
+core-y += kern/src/ kern/drivers/ kern/lib/ $(AKAROS_EXTERNAL_DIRS)
arch-y += kern/arch/$(ARCH)/
akaros-dirs := $(patsubst %/,%,$(filter %/, $(core-y) $(arch-y)))
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)
+ld_emulation = $(shell $(OBJDUMP) -i 2>/dev/null | \
+ grep -v BFD | grep ^[a-z] | head -n1)
+ld_arch = $(shell $(OBJDUMP) -i 2>/dev/null |\
+ 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
# List all userspace directories here, and state any dependencies between them,
# such as how pthread depends on parlib.
-user-dirs = parlib pthread benchutil iplib ndblib
+user-dirs = parlib pthread benchutil iplib ndblib vmm perfmon
+benchutil: parlib
pthread: parlib benchutil
iplib: parlib
ndblib: iplib
+vmm: parlib benchutil
PHONY += install-libs $(user-dirs)
install-libs: $(user-dirs) symlinks cc-exists
$(user-dirs):
- @cd user/$@ && $(MAKE) && $(MAKE) install
+ @$(MAKE) -C user/$@ DEPLIBS="$^" && $(MAKE) -C user/$@ install
+user: $(user-dirs)
PHONY += userclean $(clean-user-dirs)
clean-user-dirs := $(addprefix _clean_user_,$(user-dirs))
-userclean: $(clean-user-dirs) testclean
+userclean: $(clean-user-dirs) testclean utestclean
$(clean-user-dirs):
- @cd user/$(patsubst _clean_user_%,%,$@) && $(MAKE) clean
+ @$(MAKE) -C user/$(patsubst _clean_user_%,%,$@) clean
tests/: tests
tests: install-libs
@$(MAKE) -f tests/Makefile
+PHONY += utest
+utest: $(user-dirs)
+ @$(MAKE) -C user/$@
+
testclean:
@$(MAKE) -f tests/Makefile clean
+utestclean:
+ @$(MAKE) -C user/utest clean
+
# KFS related stuff
PHONY += fill-kfs unfill-kfs
-XCC_SO_FILES = $(addprefix $(XCC_TARGET_ROOT)/lib/, *.so*)
+xcc-gcc-libs = $(XCC_TARGET_ROOT)/../lib/
+xcc-so-files = $(addprefix $(XCC_TARGET_LIB), *.so*) \
+ $(addprefix $(xcc-gcc-libs), *.so*)
$(OBJDIR)/.dont-force-fill-kfs:
- $(Q)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
+ @$(MAKE) -f tests/Makefile uninstall
+ @echo "Apps from /test removed from KFS"
+ @$(MAKE) -C user/utest uninstall
+ @echo "User space tests removed from KFS"
@touch $(OBJDIR)/.dont-force-fill-kfs
-fill-kfs: $(OBJDIR)/.dont-force-fill-kfs install-libs
+fill-kfs: $(OBJDIR)/.dont-force-fill-kfs install-libs tests
@mkdir -p $(FIRST_KFS_PATH)/lib
- $(Q)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
+ @$(MAKE) -f tests/Makefile install
+ @echo "Apps from /test installed to KFS"
+ @$(MAKE) -C user/utest install
+ @echo "User space tests installed to KFS"
# Use doxygen to make documentation for ROS (Untested since 2010 or so)
doxygen-dir := $(CUR_DIR)/Documentation/doxygen
realclean: userclean mrproper doxyclean objclean
+# Bundled apps
+# =========================================================================
+
+app-dirs = tools/apps/snc
+tagged-app-dirs := $(subst /,__,$(app-dirs))
+app-dirs-install := $(addprefix _install_,$(tagged-app-dirs))
+app-dirs-clean := $(addprefix _clean_,$(tagged-app-dirs))
+
+PHONY += $(app-dirs-install) $(app-dirs-clean)
+
+$(app-dirs-install):
+ @$(MAKE) -C $(patsubst _install_%,%,$(subst __,/,$@)) install
+
+$(app-dirs-clean):
+ @$(MAKE) -C $(patsubst _clean_%,%,$(subst __,/,$@)) clean
+
+PHONY += apps-install
+apps-install: $(app-dirs-install)
+ @$(call make_as_parent, -C tools/apps/busybox)
+ @$(call make_as_parent, -C tools/profile/perf install)
+
+PHONY += apps-clean
+apps-clean: $(app-dirs-clean)
+ @$(call make_as_parent, -C tools/apps/busybox clean)
+ @$(call make_as_parent, -C tools/profile/perf clean)
+
+# Cross Compiler
+# =========================================================================
+
+xcc_build_dir := tools/compilers/gcc-glibc
+xcc_target := $(ARCH)
+ifeq ($(xcc_target),x86)
+ xcc_target := $(xcc_target)_64
+endif
+xcc_cleans := $(shell $(MAKE) -C $(xcc_build_dir) -pn |\
+ grep "VALID_CLEANS := " |\
+ sed -e 's/VALID_CLEANS := //')
+xcc_subcmds := $(shell $(MAKE) -C $(xcc_build_dir) -pn |\
+ grep "VALID_SUBCMDS := " |\
+ sed -e 's/VALID_SUBCMDS := //')
+xcc_clean_goals := $(patsubst %, xcc-%, $(xcc_cleans))
+xcc_subcmd_goals := $(patsubst %, xcc-%, $(xcc_subcmds))
+
+PHONY += xcc
+xcc: xcc-build
+
+PHONY += $(xcc_clean_goals)
+$(xcc_clean_goals):
+ @target="$(patsubst xcc-%,%,$(@))";\
+ $(call make_as_parent, -C $(xcc_build_dir) $${target})
+
+PHONY += $(xcc_subcmd_goals)
+$(xcc_subcmd_goals):
+ @subcmd="$(patsubst xcc-%,%,$(@))";\
+ target="$(xcc_target) $${subcmd}";\
+ $(call make_as_parent, -C $(xcc_build_dir) $${target})
+
+PHONY += xcc-upgrade
+xcc-upgrade: xcc
+ @$(MAKE) userclean
+ @$(MAKE) install-libs
+ @$(MAKE) testclean utestclean
+ @$(MAKE) tests utest
+ @$(call make_as_parent, apps-clean)
+ @$(call make_as_parent, apps-install)
+ @$(MAKE) fill-kfs
+ @$(MAKE) akaros-kernel
+
+PHONY += xcc-upgrade-from-scratch
+xcc-upgrade-from-scratch: xcc-clean xcc-uninstall
+ @$(call make_as_parent, xcc-upgrade)
+
# Cleaning
# =========================================================================
# This is mostly the Linux kernel cleaning. We could hook in to the userspace