| # Give user a chance to cross-compile this module on other kernels |
| |
| # This script assume you has defined correct CC, LD, CFLAGS and LDFLAGS |
| # to build the module that match the ARCH |
| |
| ifeq ($(CC),cc) |
| CC := gcc |
| endif |
| |
| CFLAGS += -Wall -D_KERNEL -DKLD_MODULE -O1 -fno-common -ffreestanding |
| |
| ifdef KERNEL_RELEASE |
| ifdef ARCH |
| ifeq ($(ARCH),i386) |
| EMULATION := elf_i386 |
| else ifeq ($(ARCH),amd64) |
| EMULATION := elf_x86_64 |
| else ifeq ($(ARCH),powerpc32) |
| ARCH := powerpc |
| EMULATION := elf32ppc |
| else ifeq ($(ARCH),powerpc64) |
| ARCH := powerpc |
| EMULATION := elf64ppc |
| else ifeq ($(ARCH),arm) |
| #EMULATION := armelf |
| else ifeq ($(ARCH),sparc64) |
| EMULATION := elf64_sparc |
| endif |
| CFLAGS += -nostdinc -Ikfreebsd/$(KERNEL_RELEASE) -Ikfreebsd/$(KERNEL_RELEASE)/$(ARCH) |
| ifdef EMULATION |
| ifeq ($(LD),ld) |
| ifneq ($(findstring -m,$(LDFLAGS)),-m) |
| ifeq ($(findstring $(EMULATION)_fbsd,$(shell ld -V)),$(EMULATION)_fbsd) |
| EMULATION := $(EMULATION)_fbsd |
| endif |
| LD := ld -m $(EMULATION) |
| endif # LDFLAGS |
| endif # LD |
| endif # EMULATION |
| else |
| $(error ARCH must be also defined when defining KERNEL_RELEASE) |
| endif |
| else |
| #KERNEL_NAME = $(shell uname -s) |
| #ifeq ($(shell uname -s),FreeBSD) |
| ifeq ($(findstring FreeBSD,$(shell uname -s)),FreeBSD) |
| ifdef ARCH |
| $(warning Ignoring ARCH definition) |
| endif |
| #KERNEL_RELEASE = $(shell uname -r | sed 's/\..+//') |
| KERNEL_RELEASE = $(shell uname -r | grep -Eo '^[0-9]+') |
| ARCH = $(shell uname -m) |
| else |
| $(error KERNEL_RELEASE undefined and current running kernel is not kFreeBSD) |
| endif |
| endif |
| |
| ifeq ($(ARCH),i386) |
| CFLAGS += -mpreferred-stack-boundary=2 |
| endif |
| |
| ifeq ($(filter $(ARCH),amd64 mips),) |
| LDFLAGS += --shared \ |
| -u __start_set_sysinit_set -u __stop_set_sysinit_set \ |
| -u __start_set_sysuninit_set -u __stop_set_sysuninit_set \ |
| -u __start_set_sysctl_set -u __stop_set_sysctl_set \ |
| -u __start_set_modmetadata_set -u __stop_set_modmetadata_set |
| else |
| LDFLAGS += -r |
| endif |
| LDFLAGS += -d --warn-common |
| |
| myfault.ko: myfault.o |
| $(LD) $(LDFLAGS) $^ -o $@ |
| |
| myfault.o: myfault.c |
| $(CC) $(CFLAGS) -c $^ -o $@ |
| |
| clean: |
| rm -f myfault.ko myfault.o |