#----------------------------------------------------------------- # Makefile # # This file defines an 'implicit rule' to be used by the # 'make' utility when we want to compile a Linux module. # (It allows us to avoid typing the lengthy pathname for # the nonstandard subdirectory where the kernel's header # files are located, assuming this 'Makefile' resides in # your current working directory.) # # Usage: $ make .o # # E.g., compile 'mymodule.c' using: $ make mymodule.o # # # Reference: Stallman and McGrath, "GNU Make" (The Free # Software Foundation, Incorporated, 1988). # # programmer: ALLAN CRUSE # written on: 18 JAN 2003 # revised on: 09 JUL 2004 -- to incorporate 'uname' command #----------------------------------------------------------------- # which compiler to use CC = gcc # which control flags to use CFLAGS = -O # where to find the kernel header files INCLUDE = /lib/modules/$(shell uname -r)/build/include # a pattern rule that defines our own implicit rule # invoked by using: make mod.o # %.o : %.c %.h $(CC) -c $(CFLAGS) -I$(INCLUDE) $(<) # # Here '$(<)' is the value of the automatic variable '<' # which refers to the first of this rule's dependencies # [see Stallman and McGrath, pages 106-107]. # Added 01/20/2003: a pattern rule that defines another # implicit rule, used by 'make' in case the dependency- # list above is not matched by existing files (i.e., no # header-file for our module). If this 'fallback' rule # is omitted, then 'make' resorts to its own 'built-in' # pattern rule, which unfortunately omits including the # essential headers needed to compile a kernel module. %.o : %.c $(CC) -c $(CFLAGS) -I$(INCLUDE) $(<)