mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joel Becker <Joel.Becker@oracle.com>
To: Sam Ravnborg <sam@ravnborg.org>
Cc: Timur Tabi <timur.tabi@ammasso.com>,
	Christopher Li <lkml@chrisli.org>,
	linux-kernel@vger.kernel.org
Subject: Re: Kbuild trick
Date: Sat, 21 May 2005 13:41:29 -0700	[thread overview]
Message-ID: <20050521204129.GP22946@ca-server1.us.oracle.com> (raw)
In-Reply-To: <20050521051217.GA8191@mars.ravnborg.org>

[-- Attachment #1: Type: text/plain, Size: 712 bytes --]

On Sat, May 21, 2005 at 07:12:17AM +0200, Sam Ravnborg wrote:
> > svn cat -r 2205 http://oss.oracle.com/projects/ocfs2/src/trunk/Kbuild-24.make
> 
> Care to post a copy?

	That would be too logical.  Here you go.  The first file is a
sample Makefile for both 2.6 and 2.4, stripped out of our history.  Any
mistakes are mine.  The second is Kbuild-24.make.  The files expect
KERNELDIR and KERNELINC to be set, and a 2.4 build needs to set GCCINC
as well.  Use your favorite autoconf/anti-autoconf system.

Joel

-- 

"Well-timed silence hath more eloquence than speech."  
         - Martin Fraquhar Tupper

Joel Becker
Senior Member of Technical Staff
Oracle
E-mail: joel.becker@oracle.com
Phone: (650) 506-8127

[-- Attachment #2: Makefile --]
[-- Type: text/plain, Size: 583 bytes --]


obj-m	+= myfs.o
myfs-objs := inode.o super.o

EXTRA_CFLAGS += -DSOMETHING

ifeq ($(KERNELRELEASE),)
# Called as "make" part of makefile.  This executes kbuild

all: build-myfs

clean: clean-myfs

install: install-myfs

ifneq ($(KERNEL_26),)
# This is a 2.6 kenrel, forward to kbuild

build-myfs:
	$(MAKE) -C $(KERNELDIR) M=`pwd` modules

clean-myfs:
	$(MAKE) -C $(KERNELDIR) M=`pwd` clean

install-myfs:
	$(MAKE) -C $(KERNELDIR) M=`pwd` modules_install
else
# This is a 2.4 kernel, use our own

include Kbuild-24.make

endif

else
# Called from 2.6 kbuild

STAMP_DIR = `pwd`

endif

[-- Attachment #3: Kbuild-24.make --]
[-- Type: text/plain, Size: 2610 bytes --]


#
# This is a Makefile for 2.4 external module builds.  Red Hat
# Enterprise Linux does not support the usual:
#
#     make -C /lib/modules/`uname -r`/build SUBDIRS=`pwd` modules
#
# So we must hand-roll our compile lines.  This is in a seperate
# file to keep the regular Makefile readable.
#
# This uses the Makebo schema.  So, the compile parts are filled in.
# All Makefiles using this code should set MODULE_CFLAGS and
# MODULE_DEFINES for any extra cflags/defines needed.
#

WARNINGS = -Wall -Wstrict-prototypes
OPTIMIZE = -O2

KERNEL_DEFINES = -D__KERNEL__ -DMODULE -DLINUX -DEXPORT_SYMTAB
KERNEL_CFLAGS = -pipe -nostdinc -fno-strict-aliasing -fno-common \
	-fomit-frame-pointer
KERNEL_LDADD = -nostdlib

#
# These arch-specific flags would normally be provided by the
# kbuild system.  Hope we got them right.
#

ifeq ($(PROCESSOR),ppc64)
  MACH_CFLAGS += -m64 -fsigned-char -fno-builtin -msoft-float \
	-mminimal-toc
  MACH_LDADD += -m elf64ppc
endif
ifeq ($(PROCESSOR),x86_64)
  MACH_CFLAGS += -m64 -mcmodel=kernel
endif
ifeq ($(PROCESSOR),s390x)
  MACH_CFLAGS += -fno-strength-reduce -fpic
  MACH_LDADD += -m elf64_s390
endif



INCLUDES = -I. -I$(KERNELINC) -I$(GCCINC)
DEFINES = $(KERNEL_DEFINES)
CFLAGS = $(OPTIMIZE) $(KERNEL_CFLAGS) $(MACH_CFLAGS) $(MODVERSIONS) \
	$(WARNINGS) $(EXTRA_CFLAGS) $(CFLAGS_$(*F).o)
LDADD = $(KERNEL_LDADD) $(MACH_LDADD)

#
# Ripping off some kbuild 2.6 tricks
#

# Modules that have multiple parts.
multi-used-m := $(sort $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs))), $(m))))
multi-objs-m := $(foreach m, $(multi-used-m), $($(m:.o=-objs)))

# Modules that don't.
single-used-m := $(sort $(filter-out $(multi-used-m), $(obj-m)))
link_multi_deps = $($(@:.o=-objs))

#
# It's impossible, AFAICT, to generate the dependancies for each
# individual object:parts set.  In fact, kbuild 2.6 doesn't try either.
# They use a simpler trick...they force the rebuild like this, but
# call if_changed on each target to avoid the useless rebuilds.
# This is a 2.4 hack, so I don't care that much :-)
#
$(multi-used-m): $(multi-objs-m)
	$(CC) -Wl,-r -o $@ $(LDADD) $(link_multi_deps)

build-modules: $(single-used-m) $(multi-used-m)


# Kbuild uses INSTALL_MOD_PATH for rooted installs.  Makebo uses
# DESTDIR.  Folks really should set INSTALL_MOD_PATH, but in case they
# don't...
INSTALL_MOD_PATH ?= $(DESTDIR)
MODLIB = $(INSTALL_MOD_PATH)$(MODULEDIR)

install-modules: $(obj-m)
	$(TOPDIR)/mkinstalldirs $(MODLIB)/$(INSTALL_MOD_DIR)
	for file in $(obj-m); do \
	  $(INSTALL_DATA) $$file $(MODLIB)/$(INSTALL_MOD_DIR)/$$file; \
	done

clean-modules:
	rm -f *.o *.p *.s


  parent reply	other threads:[~2005-05-21 20:41 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-17 21:46 sparse error: unable to open 'stdarg.h' Timur Tabi
2005-05-17 20:11 ` Christopher Li
2005-05-18 14:08   ` Timur Tabi
2005-05-18 12:38     ` Christopher Li
2005-05-18 15:51       ` Timur Tabi
2005-05-18 13:24         ` Christopher Li
2005-05-18 16:45           ` Timur Tabi
2005-05-18 18:22             ` Sam Ravnborg
2005-05-18 18:23               ` Timur Tabi
2005-05-20 19:37                 ` Kbuild trick Sam Ravnborg
2005-05-20 23:43                   ` Joel Becker
2005-05-21  5:12                     ` Sam Ravnborg
2005-05-21  5:48                       ` randy_dunlap
2005-05-21 20:41                       ` Joel Becker [this message]
2005-05-21 10:59                   ` Kedar Sovani
2005-05-22  7:28                     ` Sam Ravnborg
2005-05-17 22:39 ` sparse error: unable to open 'stdarg.h' Timur Tabi
2005-05-18 18:22   ` Sam Ravnborg
2005-05-18 22:14     ` Timur Tabi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050521204129.GP22946@ca-server1.us.oracle.com \
    --to=joel.becker@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkml@chrisli.org \
    --cc=sam@ravnborg.org \
    --cc=timur.tabi@ammasso.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome