Re: build -->/usr/src/linux

Jamie Lokier
2001-04-08T23:01:36Z

Miquel van Smoorenburg wrote:
> .. but there should be a cleaner way to get at the CFLAGS used
> to compile the kernel.

There is a way though I'd not call it clean. Here is an extract from
the Makefile I am using for separately-distributed modules. It should
work with kernels 2.0 to 2.4, all supported architectures.

include $(KERNEL_SOURCE)/.config

CPPFLAGS := -DMODULE -D__KERNEL__ -nostdinc -I$(KERNEL_SOURCE)/include
CPPFLAGS += -I$(shell gcc -print-file-name=include)
CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
AFLAGS := -D__ASSEMBLY__ $(CPPFLAGS)

# For older kernels.
ifneq (,$(strip $(shell grep '^[ ]*SMP[ ]*:\?=[ ]*[^ ]' $(KERNEL_SOURCE)/Makefile)))
CONFIG_SMP=y
endif
ifdef CONFIG_SMP
CFLAGS += -D__SMP__
AFLAGS += -D__SMP__
endif

include $(KERNEL_SOURCE)/arch/$(ARCH)/Makefile

CFLAGS += $(shell if $(CC) -fno-strict-aliasing -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-fno-strict-aliasing"; fi)