blob: ca78a0ddec51c7806d49f4b221b79e97c766c023 [file] [log] [blame] [raw]
# 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 -O1 -fno-common -ffreestanding
ifdef KERNEL_RELEASE
ifdef ARCH
ifeq ($(ARCH),i386)
EMULATION = -melf_i386
else ifeq ($(ARCH),amd64)
EMULATION = -melf_x86_64
else ifeq ($(ARCH),powerpc32)
ARCH = powerpc
EMULATION = -melf32ppc
else ifeq ($(ARCH),powerpc64)
ARCH = powerpc
EMULATION = -melf64ppc
else ifeq ($(ARCH),arm)
#EMULATION = -marmelf
else ifeq ($(ARCH),sparc64)
EMULATION = -melf64_sparc
endif
CFLAGS += -nostdinc -Ikfreebsd/$(KERNEL_RELEASE) -Ikfreebsd/$(KERNEL_RELEASE)/$(ARCH)
ifdef EMULATION
ifeq ($(LD),ld)
ifneq ($(findstring -m,$(LDFLAGS)),-m)
LD = ld $(EMULATION)
endif
endif
endif
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)
#KERNEL_RELEASE = $(shell uname -r | sed 's/\..+//')
KERNEL_RELEASE = $(shell uname -r | grep -Eo '^[0-9]+')
else
$(error KERNEL_RELEASE undefined and current running kernel is not kFreeBSD)
endif
endif
ifeq ($(shell [ $(KERNEL_RELEASE) -lt 10 ] && echo 1),1)
LDFLAGS += --shared
LDFLAGS += -u __start_set_sysinit_set -u __start_set_sysuninit_set \
-u __start_set_sysctl_set -u __start_set_modmetadata_set \
-u __stop_set_sysinit_set -u __stop_set_sysuninit_set \
-u __stop_set_sysctl_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