On Tue, Jan 20, 2004 at 20:40:37 -0000, Saqib Shaikh wrote: > Hi > > I'm an experienced programmer in userspace, but am relatively new to kernel > programming. I'm attempting to write a module, and can't find any good > documentation about what should go in the makefile. In particular, what > flags are required for the compiler? I've included my first attempt at a > makefile below: > > CC = gcc > TARGET = acsint > DEFS = -DLINUX -DMODULE -D__KERNEL__ > INC = -I/usr/src/linux/include > -I/usr/lib/gcc-lib/i386-redhat-linux/3.2/include -nostdinc > CFLAGS = -c -O2 -pipe -Wall ${DEFS} ${INC} > > ${TARGET}.o: ${TARGET}.c > > clean: > rm -f ${TARGET}.o > > Any help appreciated Should it be an in-tree (ie. integrated with rest of kernel), or off-tree build. If you want to do an in-tree build, you will need to fill in appropriate variables in the kernel Makefile. If you want to do an off-tree build, you will need to get proper CFLAGS for kernel. The safest way to do it is to call kernel makefile as follows: make -s script "SCRIPT=echo \$(CFLAGS)" (with -C to kernel source directory etc...) Then the appropriate command for compiling is: cc -DLINUX -DMODULE $(CFLAGS) -o $@ $< And then for linking is: ld -r -o $@ $+ Note, that the result of linking should have .o suffix. How you call the intermediate object is up to you. ------------------------------------------------------------------------------- Jan 'Bulb' Hudec <bulb@ucw.cz> -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/