3

I'm trying to follow a guide to compile a program for Debian in FreeBSD. I have the following makefile:

obj-m += kernelinfo.o
all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

I'm confused as to how I would compile this on FreeBSD since I do not have a /lib/modules folder on the machine. I have installed all of the default headers on FreeBSD in the /usr/src/ directory but I can't find a modules folder. I'm guessing the Makefile needs to be translated for FreeBSD, though I am very new to Linux and so I have no idea. Any help is much appreciated.

2 Answers2

3

This looks like it may be from a Linux kernel module. You will probably not be able to compile or use the code associated with the Linux kernel module on FreeBSD, as it's written specifically for Linux, and the Linux kernel is totally different from the FreeBSD kernel.

In short, it's not the Makefile that needs translating, but the kernel module source code that needs porting over to FreeBSD. This is not a trivial undertaking and requires knowledge of both the Linux and FreeBSD kernels.

See also Conceptual difference between Linux and (Free)BSD Kernel

Kusalananda
  • 333,661
1

For the sake of completeness, the easiest way to translate the $(shell ...) construct in this case into something that bmake would understand is to replace it with a subshell that gets expanded interpreted by shell instead of make. In particular, you could replace

clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

with

clean:
    make -C /lib/modules/$$(uname -r)/build M=$(PWD) clean