1 # Makefile -- For the Direct Rendering Manager module (drm)
3 # Based on David Woodhouse's mtd build.
5 # Modified to handle the DRM requirements and builds on a wider range of
6 # platforms in a flexible way by David Dawes. It's not clear, however,
7 # that this approach is simpler than the old one.
9 # The purpose of this Makefile is to handle setting up everything
10 # needed for an out-of-kernel source build. Makefile.kernel contains
11 # everything required for in-kernel source builds. It is included into
12 # this file, so none of that should be duplicated here.
14 # $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/Makefile.linux,v 1.40 2003/08/17 17:12:25 dawes Exp $
18 # By default, the build is done against the running linux kernel source.
19 # To build against a different kernel source tree, set LINUXDIR:
21 # make LINUXDIR=/path/to/kernel/source
24 # To build only some modules, either set DRM_MODULES to the list of modules,
25 # or specify the modules as targets:
27 # make r128.o radeon.o
31 # make DRM_MODULES="r128 radeon"
39 RUNNING_REL := $(shell uname -r)
41 LINUXDIR := $(shell if [ -e /lib/modules/$(RUNNING_REL)/source ]; then \
42 echo /lib/modules/$(RUNNING_REL)/source; \
43 else echo /lib/modules/$(RUNNING_REL)/build; fi)
50 MACHINE := $(shell uname -m)
52 # Modules for all architectures
53 MODULE_LIST := drm.0 tdfx.o r128.o radeon.o mga.o sis.o savage.o via.o mach64.o
55 # Modules only for ix86 architectures
56 ifneq (,$(findstring 86,$(MACHINE)))
58 MODULE_LIST += i830.o i810.o i915.o
61 ifneq (,$(findstring sparc64,$(MACHINE)))
66 DRM_MODULES ?= $(MODULE_LIST)
68 # These definitions are for handling dependencies in the out of kernel build.
70 DRMSHARED = drm.h drm_sarea.h
71 DRMHEADERS = drmP.h drm_compat.h drm_os_linux.h drm_module.h $(DRMSHARED)
72 COREHEADERS = drm_core.h
74 TDFXHEADERS = tdfx_drv.h $(DRMHEADERS)
75 TDFXSHARED = tdfx_drv.h
76 R128HEADERS = r128_drv.h r128_drm.h $(DRMHEADERS)
77 R128SHARED = r128_drv.h r128_drm.h r128_cce.c r128_state.c r128_irq.c
78 RADEONHEADERS = radeon_drv.h radeon_drm.h $(DRMHEADERS)
79 RADEONSHARED = radeon_drv.h radeon_drm.h radeon_cp.c radeon_irq.c \
80 radeon_mem.c radeon_state.c
81 MGAHEADERS = mga_drv.h mga_drm.h mga_ucode.h $(DRMHEADERS)
82 MGASHARED = mga_dma.c mga_drm.h mga_drv.h mga_irq.c mga_state.c \
83 mga_ucode.h mga_warp.c
84 I810HEADERS = i810_drv.h i810_drm.h $(DRMHEADERS)
85 I830HEADERS = i830_drv.h i830_drm.h $(DRMHEADERS)
86 I915HEADERS = i915_drv.h i915_drm.h $(DRMHEADERS)
87 I915SHARED = i915_drv.h i915_drm.h i915_irq.c i915_mem.c i915_dma.c
88 SISHEADERS= sis_drv.h sis_drm.h $(DRMHEADERS)
89 SISSHARED= sis_drv.h sis_drm.h sis_ds.c sis_ds.h sis_mm.c
90 SAVAGEHEADERS= savage_drv.h savage_drm.h $(DRMHEADERS)
91 VIAHEADERS = via_drm.h via_drv.h via_mm.h via_ds.h \
92 via_3d_reg.h $(DRMHEADERS)
93 VIASHARED = via_drm.h via_drv.h via_mm.h via_ds.h \
94 via_3d_reg.h via_drv.c via_ds.c via_irq.c via_map.c \
96 MACH64HEADERS = mach64_drv.h mach64_drm.h $(DRMHEADERS)
97 MACH64SHARED = mach64_drv.h mach64_drm.h mach64_dma.c \
98 mach64_irq.c mach64_state.c
99 FFBHEADERS = ffb_drv.h $(DRMHEADERS)
101 SHAREDSRC = $(DRMSHARED) $(MGASHARED) $(R128SHARED) $(RADEONSHARED) \
102 $(SISSHARED) $(TDFXSHARED) $(VIASHARED) $(MACH64SHARED) \
105 PROGS = dristat drmstat
107 CLEANFILES = *.o *.ko $(PROGS) .depend .*.flags .*.d .*.cmd *.mod.c linux drm_pciids.h .tmp_versions
109 # VERSION is not defined from the initial invocation. It is defined when
110 # this Makefile is invoked from the kernel's root Makefile.
116 # SuSE has the version.h and autoconf.h headers for the current kernel
117 # in /boot as /boot/vmlinuz.version.h and /boot/vmlinuz.autoconf.h.
118 # Check these first to see if they match the running kernel.
120 BOOTVERSION_PREFIX = /boot/vmlinuz.
122 V := $(shell if [ -f $(BOOTVERSION_PREFIX)version.h ]; then \
123 grep UTS_RELEASE $(BOOTVERSION_PREFIX)version.h | \
126 ifeq ($(V),"$(RUNNING_REL)")
128 GETCONFIG := MAKEFILES=$(shell pwd)/.config
132 # On Red Hat we need to check if there is a .config file in the kernel
133 # source directory. If there isn't, we need to check if there's a
134 # matching file in the configs subdirectory.
136 ifneq ($(HAVECONFIG),y)
137 HAVECONFIG := $(shell if [ -e $(LINUXDIR)/.config ]; then echo y; fi)
140 ifneq ($(HAVECONFIG),y)
141 REL_BASE := $(shell echo $(RUNNING_REL) | sed 's/-.*//')
142 REL_TYPE := $(shell echo $(RUNNING_REL) | sed 's/[0-9.-]//g')
144 RHCONFIG := configs/kernel-$(REL_BASE)-$(MACHINE).config
146 RHCONFIG := configs/kernel-$(REL_BASE)-$(MACHINE)-$(REL_TYPE).config
148 HAVECONFIG := $(shell if [ -e $(LINUXDIR)/$(RHCONFIG) ]; then echo y; fi)
149 ifneq ($(HAVECONFIG),y)
154 ifneq ($(HAVECONFIG),y)
155 ifneq ($(0),$(LINUXDIR))
158 HAVECONFIG := $(shell if [ -e $(O)/.config ]; then echo y; fi)
161 ifneq ($(HAVECONFIG),y)
162 $(error Cannot find a kernel config file)
167 CLEANCONFIG := $(shell if cmp -s $(LINUXDIR)/.config .config; then echo y; fi)
168 ifeq ($(CLEANCONFIG),y)
169 CLEANFILES += $(LINUXDIR)/.config .config $(LINUXDIR)/tmp_include_depends
175 make -C $(LINUXDIR) $(GETCONFIG) SUBDIRS=`pwd` DRMSRCDIR=`pwd` modules
177 ifeq ($(HEADERFROMBOOT),1)
179 BOOTHEADERS = version.h autoconf.h
182 CLEANFILES += $(BOOTHEADERS) $(BOOTCONFIG)
184 includes:: $(BOOTHEADERS) $(BOOTCONFIG)
186 version.h: $(BOOTVERSION_PREFIX)version.h
190 autoconf.h: $(BOOTVERSION_PREFIX)autoconf.h
194 .config: $(BOOTVERSION_PREFIX)config
199 # This prepares an unused Red Hat kernel tree for the build.
201 includes:: $(LINUXDIR)/.config $(LINUXDIR)/tmp_include_depends .config
203 $(LINUXDIR)/.config: $(LINUXDIR)/$(RHCONFIG)
207 .config: $(LINUXDIR)/$(RHCONFIG)
211 $(LINUXDIR)/tmp_include_depends:
215 # Make sure that the shared source files are linked into this directory.
218 SHAREDDIR := ../shared-core
220 HASSHARED := $(shell if [ -d $(SHAREDDIR) ]; then echo y; fi)
222 ifeq ($(HASSHARED),y)
223 includes:: $(SHAREDSRC) drm_pciids.h
225 drm_pciids.h: $(SHAREDDIR)/drm_pciids.txt
226 sh ../scripts/create_linux_pci_lists.sh < $(SHAREDDIR)/drm_pciids.txt
229 @if [ -r $(SHAREDDIR)/$@ ]; then \
230 (rm -f $@; set -x; ln -s $(SHAREDDIR)/$@ $@); fi
232 CLEANFILES += $(SHAREDSRC)
245 make DRM_MODULES=$@ modules
247 # Build test utilities
249 PRGCFLAGS = $(CFLAGS) -g -ansi -pedantic -DPOSIX_C_SOURCE=199309L \
250 -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE \
253 DRMSTATLIBS = -L../../.. -L.. -ldrm -lxf86_os \
254 -L../../../../dummylib -ldummy -lm
259 $(CC) $(PRGCFLAGS) $< -o $@
262 $(CC) $(PRGCFLAGS) $< -o $@ $(DRMSTATLIBS)
266 # Check for kernel versions that we don't support.
268 BELOW24 := $(shell if [ $(VERSION) -lt 2 -o $(PATCHLEVEL) -lt 4 ]; then \
272 $(error Only 2.4.x and later kernels are supported \
273 ($(VERSION).$(PATCHLEVEL).$(SUBLEVEL)))
277 ifndef CONFIG_X86_CMPXCHG
278 $(error CONFIG_X86_CMPXCHG needs to be enabled in the kernel)
282 # This needs to go before all other include paths.
285 # Check for Red Hat's 4-argument do_munmap().
286 DOMUNMAP := $(shell grep do_munmap $(LINUXDIR)/include/linux/mm.h | \
289 ifneq ($(DOMUNMAP),0)
290 EXTRA_CFLAGS += -DDO_MUNMAP_4_ARGS
293 # Check for 5-argument remap_page_range() in RH9 kernel, and 2.5.x kernels
294 RPR := $(shell grep remap_page_range $(LINUXDIR)/include/linux/mm.h | \
298 EXTRA_CFLAGS += -DREMAP_PAGE_RANGE_5_ARGS
301 # Check for 4-argument vmap() in some 2.5.x and 2.4.x kernels
302 VMAP := $(shell grep -A1 'vmap.*count,$$' $(LINUXDIR)/include/linux/vmalloc.h | \
306 EXTRA_CFLAGS += -DVMAP_4_ARGS
309 # Check for PAGE_AGP definition
310 PAGE_AGP := $(shell cat $(LINUXDIR)/include/asm/agp.h 2>/dev/null | \
313 ifneq ($(PAGE_AGP),0)
314 EXTRA_CFLAGS += -DHAVE_PAGE_AGP
318 # Start with all modules turned off.
319 CONFIG_DRM_GAMMA := n
324 CONFIG_DRM_RADEON := n
329 CONFIG_DRM_SAVAGE := n
331 CONFIG_DRM_MACH64 := n
333 # Enable module builds for the modules requested/supported.
335 ifneq (,$(findstring tdfx,$(DRM_MODULES)))
338 ifneq (,$(findstring r128,$(DRM_MODULES)))
341 ifneq (,$(findstring radeon,$(DRM_MODULES)))
342 CONFIG_DRM_RADEON := m
344 ifneq (,$(findstring sis,$(DRM_MODULES)))
347 ifneq (,$(findstring via,$(DRM_MODULES)))
350 ifneq (,$(findstring mach64,$(DRM_MODULES)))
351 CONFIG_DRM_MACH64 := m
353 ifneq (,$(findstring ffb,$(DRM_MODULES)))
357 # These require AGP support
360 ifneq (,$(findstring mga,$(DRM_MODULES)))
363 ifneq (,$(findstring i810,$(DRM_MODULES)))
366 ifneq (,$(findstring i830,$(DRM_MODULES)))
369 ifneq (,$(findstring i915,$(DRM_MODULES)))
372 ifneq (,$(findstring savage,$(DRM_MODULES)))
373 CONFIG_DRM_SAVAGE := m
377 include $(DRMSRCDIR)/Makefile.kernel
380 $(drm-objs): $(DRMHEADERS) $(COREHEADERS)
381 $(tdfx-objs): $(TDFXHEADERS)
382 $(r128-objs): $(R128HEADERS)
383 $(mga-objs): $(MGAHEADERS)
384 $(i810-objs): $(I810HEADERS)
385 $(i830-objs): $(I830HEADERS)
386 $(i915-objs): $(I830HEADERS)
387 $(radeon-objs): $(RADEONHEADERS)
388 $(sis-objs): $(SISHEADERS)
389 $(ffb-objs): $(FFBHEADERS)
390 $(savage-objs): $(SAVAGEHEADERS)
391 $(via-objs): $(VIAHEADERS)
392 $(mach64-objs): $(MACH64HEADERS)