^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) # This file is included by the global makefile so that you can add your own
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) # architecture-specific flags and dependencies.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) # Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) # Licensed under the GPL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) # select defconfig based on actual architecture
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) ifeq ($(SUBARCH),x86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) ifeq ($(shell uname -m),x86_64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) KBUILD_DEFCONFIG := x86_64_defconfig
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) KBUILD_DEFCONFIG := i386_defconfig
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) KBUILD_DEFCONFIG := $(SUBARCH)_defconfig
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) ARCH_DIR := arch/um
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) OS := $(shell uname -s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) # We require bash because the vmlinux link and loader script cpp use bash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) # features.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) SHELL := /bin/bash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) core-y += $(ARCH_DIR)/kernel/ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) $(ARCH_DIR)/drivers/ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) $(ARCH_DIR)/os-$(OS)/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) MODE_INCLUDE += -I$(srctree)/$(ARCH_DIR)/include/shared/skas
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) HEADER_ARCH := $(SUBARCH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) ifneq ($(filter $(SUBARCH),x86 x86_64 i386),)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) HEADER_ARCH := x86
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) ifdef CONFIG_64BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) KBUILD_CFLAGS += -mcmodel=large
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) HOST_DIR := arch/$(HEADER_ARCH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) include $(ARCH_DIR)/Makefile-skas
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) include $(HOST_DIR)/Makefile.um
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) core-y += $(HOST_DIR)/um/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) SHARED_HEADERS := $(ARCH_DIR)/include/shared
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) ARCH_INCLUDE := -I$(srctree)/$(SHARED_HEADERS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) ARCH_INCLUDE += -I$(srctree)/$(HOST_DIR)/um/shared
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) KBUILD_CPPFLAGS += -I$(srctree)/$(HOST_DIR)/um
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) # -Dvmap=kernel_vmap prevents anything from referencing the libpcap.o symbol so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) # named - it's a common symbol in libpcap, so we get a binary which crashes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) # Same things for in6addr_loopback and mktime - found in libc. For these two we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) # only get link-time error, luckily.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) # -Dlongjmp=kernel_longjmp prevents anything from referencing the libpthread.a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) # embedded copy of longjmp, same thing for setjmp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) # These apply to USER_CFLAGS to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) KBUILD_CFLAGS += $(CFLAGS) $(CFLAGS-y) -D__arch_um__ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) $(ARCH_INCLUDE) $(MODE_INCLUDE) -Dvmap=kernel_vmap \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) -Dlongjmp=kernel_longjmp -Dsetjmp=kernel_setjmp \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) -Din6addr_loopback=kernel_in6addr_loopback \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) -Din6addr_any=kernel_in6addr_any -Dstrrchr=kernel_strrchr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) KBUILD_AFLAGS += $(ARCH_INCLUDE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -I%,,$(KBUILD_CFLAGS))) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) $(ARCH_INCLUDE) $(MODE_INCLUDE) $(filter -I%,$(CFLAGS)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) -D_FILE_OFFSET_BITS=64 -idirafter $(srctree)/include \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) -idirafter $(objtree)/include -D__KERNEL__ -D__UM_HOST__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #This will adjust *FLAGS accordingly to the platform.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) include $(ARCH_DIR)/Makefile-os-$(OS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) KBUILD_CPPFLAGS += -I$(srctree)/$(HOST_DIR)/include \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) -I$(srctree)/$(HOST_DIR)/include/uapi \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) -I$(objtree)/$(HOST_DIR)/include/generated \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) -I$(objtree)/$(HOST_DIR)/include/generated/uapi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) # -Derrno=kernel_errno - This turns all kernel references to errno into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) # kernel_errno to separate them from the libc errno. This allows -fno-common
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) # in KBUILD_CFLAGS. Otherwise, it would cause ld to complain about the two different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) # errnos.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) # These apply to kernelspace only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) # strip leading and trailing whitespace to make the USER_CFLAGS removal of these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) # defines more robust
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) KERNEL_DEFINES = $(strip -Derrno=kernel_errno -Dsigprocmask=kernel_sigprocmask \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) -Dmktime=kernel_mktime $(ARCH_KERNEL_DEFINES))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) KBUILD_CFLAGS += $(KERNEL_DEFINES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) PHONY += linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) all: linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) linux: vmlinux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) @echo ' LINK $@'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) $(Q)ln -f $< $@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) define archhelp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) echo '* linux - Binary kernel image (./linux) - for backward'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) echo ' compatibility only, this creates a hard link to the'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) echo ' real kernel binary, the "vmlinux" binary you'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) echo ' find in the kernel root.'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) endef
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) archheaders:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) $(Q)$(MAKE) -f $(srctree)/Makefile ARCH=$(HEADER_ARCH) asm-generic archheaders
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) archprepare:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) $(Q)$(MAKE) $(build)=$(HOST_DIR)/um include/generated/user_constants.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) LINK-$(CONFIG_LD_SCRIPT_STATIC) += -static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) LINK-$(CONFIG_LD_SCRIPT_DYN) += -Wl,-rpath,/lib $(call cc-option, -no-pie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) CFLAGS_NO_HARDENING := $(call cc-option, -fno-PIC,) $(call cc-option, -fno-pic,) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) -fno-stack-protector $(call cc-option, -fno-stack-protector-all)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) # Options used by linker script
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) export LDS_START := $(START)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) export LDS_ELF_ARCH := $(ELF_ARCH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) export LDS_ELF_FORMAT := $(ELF_FORMAT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) # The wrappers will select whether using "malloc" or the kernel allocator.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) LINK_WRAPS = -Wl,--wrap,malloc -Wl,--wrap,free -Wl,--wrap,calloc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) LD_FLAGS_CMDLINE = $(foreach opt,$(KBUILD_LDFLAGS),-Wl,$(opt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) # Used by link-vmlinux.sh which has special support for um link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) export CFLAGS_vmlinux := $(LINK-y) $(LINK_WRAPS) $(LD_FLAGS_CMDLINE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) # When cleaning we don't include .config, so we don't include
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) # TT or skas makefiles and don't clean skas_ptregs.h.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) CLEAN_FILES += linux x.i gmon.out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) MRPROPER_FILES += arch/$(SUBARCH)/include/generated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) archclean:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) @find . \( -name '*.bb' -o -name '*.bbg' -o -name '*.da' \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) -o -name '*.gcov' \) -type f -print | xargs rm -f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) export HEADER_ARCH SUBARCH USER_CFLAGS CFLAGS_NO_HARDENING OS DEV_NULL_PATH