Makefile revision e91f2a55ed5a30342ec79ce273f3f4bad8283336
fa9e4066f08beec538e775443c5be79dd423fcabahrens# $Revision$
fa9e4066f08beec538e775443c5be79dd423fcabahrens# VirtualBox Guest Additions Module Makefile.
fa9e4066f08beec538e775443c5be79dd423fcabahrens# Copyright (C) 2006-2010 Oracle Corporation
fa9e4066f08beec538e775443c5be79dd423fcabahrens# This file is part of VirtualBox Open Source Edition (OSE), as
fa9e4066f08beec538e775443c5be79dd423fcabahrens# available from http://www.virtualbox.org. This file is free software;
fa9e4066f08beec538e775443c5be79dd423fcabahrens# you can redistribute it and/or modify it under the terms of the GNU
fa9e4066f08beec538e775443c5be79dd423fcabahrens# General Public License (GPL) as published by the Free Software
fa9e4066f08beec538e775443c5be79dd423fcabahrens# Foundation, in version 2 as it comes in the "COPYING" file of the
fa9e4066f08beec538e775443c5be79dd423fcabahrens# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
fa9e4066f08beec538e775443c5be79dd423fcabahrens# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
fa9e4066f08beec538e775443c5be79dd423fcabahrens# First, figure out which architecture we're targeting and the build type.
fa9e4066f08beec538e775443c5be79dd423fcabahrens# (We have to support basic cross building (ARCH=i386|x86_64).)
fa9e4066f08beec538e775443c5be79dd423fcabahrens# While at it, warn about BUILD_* vars found to help with user problems.
fa9e4066f08beec538e775443c5be79dd423fcabahrensifeq ($(filter-out x86_64 amd64 AMD64,$(shell uname -m)),)
283b84606b6fc326692c03273de1774e8c122f9aGeorge.Wilsonifneq ($(filter-out amd64 x86,$(BUILD_TARGET_ARCH)),)
283b84606b6fc326692c03273de1774e8c122f9aGeorge.Wilson $(warning Ignoring unknown BUILD_TARGET_ARCH value '$(BUILD_TARGET_ARCH)'.)
614409b5be5411058e7e9b6cc93dddaff9fb13f7ahrens ifneq ($(BUILD_TARGET_ARCH),$(BUILD_TARGET_ARCH_DEF))
c33e334fd3eb2b3d91c4b9667d7a465b6924e8d3Matthew Ahrens $(warning Using BUILD_TARGET_ARCH='$(BUILD_TARGET_ARCH)' from the $(origin BUILD_TARGET_ARCH).)
614409b5be5411058e7e9b6cc93dddaff9fb13f7ahrensifneq ($(filter-out release profile debug strict,$(BUILD_TYPE)),)
614409b5be5411058e7e9b6cc93dddaff9fb13f7ahrens $(warning Ignoring unknown BUILD_TYPE value '$(BUILD_TYPE)'.)
f94275ce205810a201404c5f35f4cc96057022b1Adam Leventhal $(warning Using BUILD_TYPE='$(BUILD_TYPE)' from the $(origin BUILD_TYPE).)
f94275ce205810a201404c5f35f4cc96057022b1Adam Leventhal# override is required by the Debian guys
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock # building from this directory
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock # kernel base directory
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
fa9e4066f08beec538e775443c5be79dd423fcabahrens $(error Error: unable to find the sources of your current Linux kernel. \
a3f829ae41ece20e7f5f63604e177aeeb8b24628Bill Moore $(warning Warning: using /usr/src/linux as the source directory of your \
a3f829ae41ece20e7f5f63604e177aeeb8b24628Bill Moore ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
fa9e4066f08beec538e775443c5be79dd423fcabahrens $(error Error: KERN_DIR does not point to a directory)
6f708f7c79bbe8e239e0f588bb846b4ccbc14bf3Jeff Bonwick ifneq ($(shell if test -d $(KERN_INCL); then echo yes; fi),yes)
6f708f7c79bbe8e239e0f588bb846b4ccbc14bf3Jeff Bonwick $(error Error: unable to find the include directory for your current Linux \
6f708f7c79bbe8e239e0f588bb846b4ccbc14bf3Jeff Bonwick kernel. Specify KERN_INCL=<directory> and run Make again)
fa9e4066f08beec538e775443c5be79dd423fcabahrens # module install dir, only for current kernel
e05725b117836db173257fae43fb0746eb857fb5bonwick ifneq ($(filter install install_rpm,$(MAKECMDGOALS)),)
f94275ce205810a201404c5f35f4cc96057022b1Adam Leventhal MODULE_DIR_TST := /lib/modules/$(shell uname -r)
a3f829ae41ece20e7f5f63604e177aeeb8b24628Bill Moore ifeq ($(shell if test -d $(MODULE_DIR_TST); then echo yes; fi),yes)
6f708f7c79bbe8e239e0f588bb846b4ccbc14bf3Jeff Bonwick $(error Unable to find the folder to install the additions driver to)
fa9e4066f08beec538e775443c5be79dd423fcabahrens # guess kernel version (24 or 26)
fa9e4066f08beec538e775443c5be79dd423fcabahrens ifeq ($(shell if grep '"2\.4\.' $(KERN_INCL)/linux/version.h > /dev/null; then echo yes; fi),yes)
a3f829ae41ece20e7f5f63604e177aeeb8b24628Bill Mooreelse # neq($(KERNELRELEASE),)
8ad4d6dd86f5bc65fb3afa566c8133f3bac21648Jeff Bonwick # building from kbuild (make -C <kernel_directory> M=`pwd`)
f94275ce205810a201404c5f35f4cc96057022b1Adam Leventhal # guess kernel version (24 or 26)
f94275ce205810a201404c5f35f4cc96057022b1Adam Leventhal ifeq ($(shell if echo "$(VERSION).$(PATCHLEVEL)." | grep '2\.4\.' > /dev/null; then echo yes; fi),yes)
f94275ce205810a201404c5f35f4cc96057022b1Adam Leventhal# debug - show guesses.
f94275ce205810a201404c5f35f4cc96057022b1Adam Leventhal$(warning dbg: KERN_VERSION = $(KERN_VERSION))
f94275ce205810a201404c5f35f4cc96057022b1Adam Leventhal# Compiler options
f94275ce205810a201404c5f35f4cc96057022b1Adam Leventhal INCL := $(addprefix -I,$(KERN_INCL) $(EXTRA_INCL))
f94275ce205810a201404c5f35f4cc96057022b1Adam Leventhal INCL += $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
f94275ce205810a201404c5f35f4cc96057022b1Adam Leventhal INCL += $(addprefix -I$(KBUILD_EXTMOD)/vboxguest,/ /include /r0drv/linux)
f94275ce205810a201404c5f35f4cc96057022b1Adam Leventhal -DVBOX -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_GUEST -DIN_GUEST_R0 \
f94275ce205810a201404c5f35f4cc96057022b1Adam Leventhal -DIN_MODULE -DRT_WITH_VBOX -DVBGL_VBOXGUEST -DVBOX_WITH_HGCM
f94275ce205810a201404c5f35f4cc96057022b1Adam Leventhal KFLAGS += -DRT_ARCH_AMD64 -DVBOX_WITH_64_BITS_GUESTS
f94275ce205810a201404c5f35f4cc96057022b1Adam LeventhalCFLAGS := -O2 -DVBOX_LINUX_2_4 -DEXPORT_SYMTAB $(INCL) $(KFLAGS) $(KDEBUG)
f94275ce205810a201404c5f35f4cc96057022b1Adam Leventhal# 2.4 Module linking
f94275ce205810a201404c5f35f4cc96057022b1Adam Leventhal# 2.6 and later
f94275ce205810a201404c5f35f4cc96057022b1Adam LeventhalEXTRA_CFLAGS += -include $(KBUILD_EXTMOD)/include/VBox/VBoxGuestMangling.h $(INCL) $(KFLAGS) $(KDEBUG)
f94275ce205810a201404c5f35f4cc96057022b1Adam Leventhal $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C $(KERN_DIR) SUBDIRS=$(CURDIR) SRCROOT=$(CURDIR) modules
614409b5be5411058e7e9b6cc93dddaff9fb13f7ahrens install -m 0664 -o root -g root $(MODULE).$(MODULE_EXT) $(MODULE_DIR); \
283b84606b6fc326692c03273de1774e8c122f9aGeorge.Wilson @if ! readelf -p __ksymtab_strings vboxguest.ko | grep -E "\[.*\] *(RT|g_..*RT.*)"; then \
fa9e4066f08beec538e775443c5be79dd423fcabahrens echo "All exported IPRT symbols are properly renamed!"; \
6f708f7c79bbe8e239e0f588bb846b4ccbc14bf3Jeff Bonwick echo "error: Some exported IPRT symbols was not properly renamed! See above." >&2; \
a3f829ae41ece20e7f5f63604e177aeeb8b24628Bill Moore for f in . linux r0drv generic r0drv/linux r0drv/generic VBox \
f94275ce205810a201404c5f35f4cc96057022b1Adam Leventhal common/alloc common/err common/log common/math/gcc common/misc common/string common/time; \
f94275ce205810a201404c5f35f4cc96057022b1Adam Leventhal do rm -f $$f/*.o $$f/.*.cmd $$f/.*.flags; done