blob: dc21459a9b28fc62a165c123eca276edde63bda7 [file] [log] [blame]
Daryll Straussb6a28bf1999-12-05 23:10:37 +00001# Makefile -- For the Direct Rendering Manager module (drm)
Daryll Straussb6a28bf1999-12-05 23:10:37 +00002#
David Dawesdbb7beb2003-04-17 18:44:38 +00003# Based on David Woodhouse's mtd build.
Daryll Straussb6a28bf1999-12-05 23:10:37 +00004#
David Dawesdbb7beb2003-04-17 18:44:38 +00005# 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.
Gareth Hughese15a24e2000-12-02 06:14:18 +00008#
Michel Daenzer0f32a882004-04-18 22:59:01 +00009# The purpose of this Makefile is to handle setting up everything
David Dawesdbb7beb2003-04-17 18:44:38 +000010# 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.
Gareth Hughese15a24e2000-12-02 06:14:18 +000013#
Alan Hourihanec5168012003-09-12 20:00:59 +000014# $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/Makefile.linux,v 1.40 2003/08/17 17:12:25 dawes Exp $
Gareth Hughes36047532001-02-15 08:12:14 +000015#
David Dawesdbb7beb2003-04-17 18:44:38 +000016
Brian Paul569da5a2000-06-08 14:38:22 +000017#
David Dawesdbb7beb2003-04-17 18:44:38 +000018# By default, the build is done against the running linux kernel source.
19# To build against a different kernel source tree, set LINUXDIR:
20#
Michel Daenzer0f32a882004-04-18 22:59:01 +000021# make LINUXDIR=/path/to/kernel/source
David Dawesdbb7beb2003-04-17 18:44:38 +000022
23#
24# To build only some modules, either set DRM_MODULES to the list of modules,
25# or specify the modules as targets:
26#
Michel Daenzer0f32a882004-04-18 22:59:01 +000027# make r128.o radeon.o
David Dawesdbb7beb2003-04-17 18:44:38 +000028#
29# or:
30#
Michel Daenzer0f32a882004-04-18 22:59:01 +000031# make DRM_MODULES="r128 radeon"
Brian Paul569da5a2000-06-08 14:38:22 +000032#
Daryll Straussb6a28bf1999-12-05 23:10:37 +000033
Alan Hourihaneb3eb34e2003-03-25 11:36:43 +000034SHELL=/bin/sh
35
Daryll Straussb6a28bf1999-12-05 23:10:37 +000036.SUFFIXES:
37
David Dawesdbb7beb2003-04-17 18:44:38 +000038ifndef LINUXDIR
39RUNNING_REL := $(shell uname -r)
Daryll Straussb6a28bf1999-12-05 23:10:37 +000040
David Dawesdbb7beb2003-04-17 18:44:38 +000041LINUXDIR := /lib/modules/$(RUNNING_REL)/build
42endif
Jeff Hartmannba1b1ae2000-04-04 22:08:14 +000043
David Dawesdbb7beb2003-04-17 18:44:38 +000044MACHINE := $(shell uname -m)
Daryll Straussb6a28bf1999-12-05 23:10:37 +000045
David Dawesdbb7beb2003-04-17 18:44:38 +000046# Modules for all architectures
Dave Airlie873e1c42004-04-12 05:27:40 +000047MODULE_LIST := gamma.o tdfx.o r128.o radeon.o mga.o sis.o savage.o via.o mach64.o
Daryll Straussb6a28bf1999-12-05 23:10:37 +000048
David Dawesdbb7beb2003-04-17 18:44:38 +000049# Modules only for ix86 architectures
50ifneq (,$(findstring 86,$(MACHINE)))
Alan Hourihanec5168012003-09-12 20:00:59 +000051ARCHX86 := 1
David Dawesdbb7beb2003-04-17 18:44:38 +000052MODULE_LIST += i830.o i810.o
53endif
Daryll Straussb6a28bf1999-12-05 23:10:37 +000054
David Dawesdbb7beb2003-04-17 18:44:38 +000055# Add ffb.o for sparc??
Daryll Straussb6a28bf1999-12-05 23:10:37 +000056
David Dawesdbb7beb2003-04-17 18:44:38 +000057DRM_MODULES ?= $(MODULE_LIST)
Kevin E Martin5d6ddbc2001-04-05 22:16:12 +000058
David Dawesdbb7beb2003-04-17 18:44:38 +000059# These definitions are for handling dependencies in the out of kernel build.
60
61DRMTEMPLATES = drm_auth.h drm_bufs.h drm_context.h drm_dma.h drm_drawable.h \
Eric Anholt2950f9e2003-10-17 05:13:48 +000062 drm_drv.h drm_fops.h drm_init.h drm_ioctl.h drm_irq.h \
David Dawesdbb7beb2003-04-17 18:44:38 +000063 drm_lock.h drm_memory.h drm_proc.h drm_stub.h drm_vm.h
64
Eric Anholt58641012003-11-05 01:43:47 +000065DRMSHARED = drm.h drm_sarea.h
66DRMHEADERS = drmP.h $(DRMSHARED)
David Dawesdbb7beb2003-04-17 18:44:38 +000067
David Dawes9d603b02003-04-24 02:56:06 +000068GAMMAHEADERS = gamma.h gamma_context.h gamma_drm.h gamma_drv.h gamma_lists.h \
69 gamma_old_dma.h gamma_lock.h $(DRMHEADERS) $(DRMTEMPLATES)
David Dawesdbb7beb2003-04-17 18:44:38 +000070TDFXHEADERS = tdfx.h $(DRMHEADERS) $(DRMTEMPLATES)
Eric Anholtff584762003-10-17 03:14:39 +000071TDFXSHARED = tdfx.h
David Dawesdbb7beb2003-04-17 18:44:38 +000072R128HEADERS = r128.h r128_drv.h r128_drm.h $(DRMHEADERS) $(DRMTEMPLATES)
73R128SHARED = r128.h r128_drv.h r128_drm.h r128_cce.c r128_state.c r128_irq.c
74RADEONHEADERS = radeon.h radeon_drv.h radeon_drm.h $(DRMHEADERS) \
75 $(DRMTEMPLATES)
76RADEONSHARED = radeon.h radeon_drv.h radeon_drm.h radeon_cp.c radeon_irq.c \
77 radeon_mem.c radeon_state.c
78MGAHEADERS = mga.h mga_drv.h mga_drm.h mga_ucode.h $(DRMHEADERS) \
Kevin E Martin5d6ddbc2001-04-05 22:16:12 +000079 $(DRMTEMPLATES)
David Dawesdbb7beb2003-04-17 18:44:38 +000080MGASHARED = mga.h mga_dma.c mga_drm.h mga_drv.h mga_irq.c mga_state.c \
81 mga_ucode.h mga_warp.c
82I810HEADERS = i810.h i810_drv.h i810_drm.h $(DRMHEADERS) $(DRMTEMPLATES)
83I830HEADERS = i830.h i830_drv.h i830_drm.h $(DRMHEADERS) $(DRMTEMPLATES)
Eric Anholt69d038e2003-10-23 05:52:19 +000084SISHEADERS= sis.h sis_drv.h sis_drm.h $(DRMHEADERS)
85SISSHARED= sis.h sis_drv.h sis_drm.h sis_ds.c sis_ds.h sis_mm.c
Felix Kuehling3dea36d2004-02-22 16:20:16 +000086SAVAGEHEADERS= savage.h savage_drv.h savage_drm.h $(DRMHEADERS) \
87 $(DRMTEMPLATES)
Thomas Hellstrom89d67d92004-03-23 21:14:17 +000088VIAHEADERS = via_drm.h via_drv.h via.h via_mm.h via_ds.h \
89 $(DRMHEADERS) $(DRMTEMPLATES)
90VIASHARED = via_drm.h via_drv.h via.h via_mm.h via_ds.h via_drv.c \
91 via_ds.c via_irq.c via_map.c via_mm.c
Dave Airlie873e1c42004-04-12 05:27:40 +000092MACH64HEADERS = mach64.h mach64_drv.h mach64_drm.h $(DRMHEADERS) \
93 $(DRMTEMPLATES)
94MACH64SHARED = mach64.h mach64_drv.h mach64_drm.h mach64_dma.c \
95 mach64_irq.c mach64_state.c
Alan Hourihaneb3eb34e2003-03-25 11:36:43 +000096
Eric Anholtff584762003-10-17 03:14:39 +000097SHAREDSRC = $(DRMSHARED) $(MGASHARED) $(R128SHARED) $(RADEONSHARED) \
Dave Airlie873e1c42004-04-12 05:27:40 +000098 $(SISSHARED) $(TDFXSHARED) $(VIASHARED) $(MACH64SHARED)
David Dawesdbb7beb2003-04-17 18:44:38 +000099
David Dawesc3092ea2003-04-25 00:57:42 +0000100PROGS = dristat drmstat
101
Jon Smirl537ac1a2004-03-16 00:59:24 +0000102CLEANFILES = *.o *.ko $(PROGS) .depend .*.flags .*.d .*.cmd *.mod.c linux
David Dawesdbb7beb2003-04-17 18:44:38 +0000103
104# VERSION is not defined from the initial invocation. It is defined when
105# this Makefile is invoked from the kernel's root Makefile.
106
107ifndef VERSION
108
109ifdef RUNNING_REL
110
111# SuSE has the version.h and autoconf.h headers for the current kernel
112# in /boot as /boot/vmlinuz.version.h and /boot/vmlinuz.autoconf.h.
113# Check these first to see if they match the running kernel.
114
115BOOTVERSION_PREFIX = /boot/vmlinuz.
116
117V := $(shell if [ -f $(BOOTVERSION_PREFIX)version.h ]; then \
118 grep UTS_RELEASE $(BOOTVERSION_PREFIX)version.h | \
119 cut -d' ' -f3; fi)
120
121ifeq ($(V),"$(RUNNING_REL)")
122HEADERFROMBOOT := 1
123GETCONFIG := MAKEFILES=$(shell pwd)/.config
124HAVECONFIG := y
125endif
126
127# On Red Hat we need to check if there is a .config file in the kernel
128# source directory. If there isn't, we need to check if there's a
129# matching file in the configs subdirectory.
130
131ifneq ($(HAVECONFIG),y)
132HAVECONFIG := $(shell if [ -e $(LINUXDIR)/.config ]; then echo y; fi)
133endif
134
135ifneq ($(HAVECONFIG),y)
136REL_BASE := $(shell echo $(RUNNING_REL) | sed 's/-.*//')
137REL_TYPE := $(shell echo $(RUNNING_REL) | sed 's/[0-9.-]//g')
138ifeq ($(REL_TYPE),)
139RHCONFIG := configs/kernel-$(REL_BASE)-$(MACHINE).config
140else
141RHCONFIG := configs/kernel-$(REL_BASE)-$(MACHINE)-$(REL_TYPE).config
142endif
143HAVECONFIG := $(shell if [ -e $(LINUXDIR)/$(RHCONFIG) ]; then echo y; fi)
144ifneq ($(HAVECONFIG),y)
145RHCONFIG :=
146endif
147endif
148
149ifneq ($(HAVECONFIG),y)
150$(error Cannot find a kernel config file)
151endif
152
153endif
154
155CLEANCONFIG := $(shell if cmp -s $(LINUXDIR)/.config .config; then echo y; fi)
156ifeq ($(CLEANCONFIG),y)
157CLEANFILES += $(LINUXDIR)/.config .config $(LINUXDIR)/tmp_include_depends
158endif
159
David Dawesdbb7beb2003-04-17 18:44:38 +0000160all: modules
161
162modules: includes
David Dawesdbb7beb2003-04-17 18:44:38 +0000163 make -C $(LINUXDIR) $(GETCONFIG) SUBDIRS=`pwd` DRMSRCDIR=`pwd` modules
David Dawesdbb7beb2003-04-17 18:44:38 +0000164
165ifeq ($(HEADERFROMBOOT),1)
166
167BOOTHEADERS = version.h autoconf.h
168BOOTCONFIG = .config
169
170CLEANFILES += $(BOOTHEADERS) $(BOOTCONFIG)
171
172includes:: $(BOOTHEADERS) $(BOOTCONFIG)
173
174version.h: $(BOOTVERSION_PREFIX)version.h
175 rm -f $@
176 ln -s $< $@
177
178autoconf.h: $(BOOTVERSION_PREFIX)autoconf.h
179 rm -f $@
180 ln -s $< $@
181
182.config: $(BOOTVERSION_PREFIX)config
183 rm -f $@
184 ln -s $< $@
185endif
186
187# This prepares an unused Red Hat kernel tree for the build.
188ifneq ($(RHCONFIG),)
189includes:: $(LINUXDIR)/.config $(LINUXDIR)/tmp_include_depends .config
190
191$(LINUXDIR)/.config: $(LINUXDIR)/$(RHCONFIG)
192 rm -f $@
193 ln -s $< $@
194
195.config: $(LINUXDIR)/$(RHCONFIG)
196 rm -f $@
197 ln -s $< $@
198
199$(LINUXDIR)/tmp_include_depends:
200 echo all: > $@
201endif
202
203# Make sure that the shared source files are linked into this directory.
204
205
Jon Smirlab66cbc2004-03-17 01:03:26 +0000206SHAREDDIR := ../shared
David Dawesdbb7beb2003-04-17 18:44:38 +0000207
208HASSHARED := $(shell if [ -d $(SHAREDDIR) ]; then echo y; fi)
209
210ifeq ($(HASSHARED),y)
Dave Airlie93bd67e2004-04-21 12:13:31 +0000211includes:: $(SHAREDSRC) drm_pciids.h
212
213drm_pciids.h: $(SHAREDDIR)/drm_pciids.txt
214 sh ../scripts/create_linux_pci_lists.sh < $(SHAREDDIR)/drm_pciids.txt
Alan Hourihaneb3eb34e2003-03-25 11:36:43 +0000215
216$(SHAREDSRC):
David Dawesdbb7beb2003-04-17 18:44:38 +0000217 @if [ -r $(SHAREDDIR)/$@ ]; then \
218 (rm -f $@; set -x; ln -s $(SHAREDDIR)/$@ $@); fi
Alan Hourihaneb3eb34e2003-03-25 11:36:43 +0000219
David Dawesdbb7beb2003-04-17 18:44:38 +0000220CLEANFILES += $(SHAREDSRC)
Jeff Hartmannba1b1ae2000-04-04 22:08:14 +0000221endif
222
David Dawesdbb7beb2003-04-17 18:44:38 +0000223includes:: linux
Daryll Straussb6a28bf1999-12-05 23:10:37 +0000224
David Dawesdbb7beb2003-04-17 18:44:38 +0000225linux:
226 rm -f linux
227 ln -s . linux
Daryll Straussb6a28bf1999-12-05 23:10:37 +0000228
David Dawesdbb7beb2003-04-17 18:44:38 +0000229clean cleandir:
230 rm -f $(CLEANFILES)
Daryll Straussb6a28bf1999-12-05 23:10:37 +0000231
David Dawesdbb7beb2003-04-17 18:44:38 +0000232$(MODULE_LIST)::
Michel Daenzer0f32a882004-04-18 22:59:01 +0000233 make DRM_MODULES=$@ modules
David Dawesdbb7beb2003-04-17 18:44:38 +0000234
David Dawesc3092ea2003-04-25 00:57:42 +0000235# Build test utilities
236
237PRGCFLAGS = $(CFLAGS) -g -ansi -pedantic -DPOSIX_C_SOURCE=199309L \
238 -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE \
239 -I. -I../../..
240
241DRMSTATLIBS = -L../../.. -L.. -ldrm -lxf86_os \
242 -L../../../../dummylib -ldummy -lm
243
244programs: $(PROGS)
245
246dristat: dristat.c
247 $(CC) $(PRGCFLAGS) $< -o $@
248
249drmstat: drmstat.c
250 $(CC) $(PRGCFLAGS) $< -o $@ $(DRMSTATLIBS)
251
David Dawesdbb7beb2003-04-17 18:44:38 +0000252else
253
254# Check for kernel versions that we don't support.
255
256BELOW24 := $(shell if [ $(VERSION) -lt 2 -o $(PATCHLEVEL) -lt 4 ]; then \
257 echo y; fi)
258
259ifeq ($(BELOW24),y)
260$(error Only 2.4.x and later kernels are supported \
261 ($(VERSION).$(PATCHLEVEL).$(SUBLEVEL)))
Jeff Hartmannba1b1ae2000-04-04 22:08:14 +0000262endif
Daryll Straussb6a28bf1999-12-05 23:10:37 +0000263
Alan Hourihanec5168012003-09-12 20:00:59 +0000264ifdef ARCHX86
265ifndef CONFIG_X86_CMPXCHG
266$(error CONFIG_X86_CMPXCHG needs to be enabled in the kernel)
267endif
268endif
269
David Dawesdbb7beb2003-04-17 18:44:38 +0000270# This needs to go before all other include paths.
271CC += -I$(DRMSRCDIR)
272
273# Check for Red Hat's 4-argument do_munmap().
274DOMUNMAP := $(shell grep do_munmap $(LINUXDIR)/include/linux/mm.h | \
275 grep -c acct)
David Dawesdbb7beb2003-04-17 18:44:38 +0000276
277ifneq ($(DOMUNMAP),0)
278EXTRA_CFLAGS += -DDO_MUNMAP_4_ARGS
279endif
280
Michel Daenzere5d3c7f2003-05-16 23:41:27 +0000281# Check for 5-argument remap_page_range() in RH9 kernel, and 2.5.x kernels
282RPR := $(shell grep remap_page_range $(LINUXDIR)/include/linux/mm.h | \
283 grep -c vma)
284
David Dawesdbb7beb2003-04-17 18:44:38 +0000285ifneq ($(RPR),0)
286EXTRA_CFLAGS += -DREMAP_PAGE_RANGE_5_ARGS
287endif
288
Michel Daenzere5d3c7f2003-05-16 23:41:27 +0000289# Check for 4-argument vmap() in some 2.5.x and 2.4.x kernels
290VMAP := $(shell grep -A1 'vmap.*count,$$' $(LINUXDIR)/include/linux/vmalloc.h | \
291 grep -c prot)
292
293ifneq ($(VMAP),0)
294EXTRA_CFLAGS += -DVMAP_4_ARGS
295endif
296
297# Check for PAGE_AGP definition
298PAGE_AGP := $(shell cat $(LINUXDIR)/include/asm/agp.h 2>/dev/null | \
299 grep -c PAGE_AGP)
300
301ifneq ($(PAGE_AGP),0)
302EXTRA_CFLAGS += -DHAVE_PAGE_AGP
303endif
304
305
David Dawesdbb7beb2003-04-17 18:44:38 +0000306# Start with all modules turned off.
307CONFIG_DRM_GAMMA := n
308CONFIG_DRM_TDFX := n
309CONFIG_DRM_MGA := n
310CONFIG_DRM_I810 := n
311CONFIG_DRM_R128 := n
312CONFIG_DRM_RADEON := n
313CONFIG_DRM_I830 := n
314CONFIG_DRM_SIS := n
315CONFIG_DRM_FFB := n
Felix Kuehling3dea36d2004-02-22 16:20:16 +0000316CONFIG_DRM_SAVAGE := n
Thomas Hellstrom89d67d92004-03-23 21:14:17 +0000317CONFIG_DRM_VIA := n
Dave Airlie873e1c42004-04-12 05:27:40 +0000318CONFIG_DRM_MACH64 := n
David Dawesdbb7beb2003-04-17 18:44:38 +0000319
320# Enable module builds for the modules requested/supported.
321
322ifneq (,$(findstring gamma,$(DRM_MODULES)))
323CONFIG_DRM_GAMMA := m
324endif
325ifneq (,$(findstring tdfx,$(DRM_MODULES)))
326CONFIG_DRM_TDFX := m
327endif
Leif Delgass22608a42003-04-22 19:42:27 +0000328ifneq (,$(findstring r128,$(DRM_MODULES)))
329CONFIG_DRM_R128 := m
330endif
331ifneq (,$(findstring radeon,$(DRM_MODULES)))
332CONFIG_DRM_RADEON := m
333endif
334ifneq (,$(findstring sis,$(DRM_MODULES)))
335CONFIG_DRM_SIS := m
336endif
Thomas Hellstrom89d67d92004-03-23 21:14:17 +0000337ifneq (,$(findstring via,$(DRM_MODULES)))
338CONFIG_DRM_VIA := m
339endif
Dave Airlie873e1c42004-04-12 05:27:40 +0000340ifneq (,$(findstring mach64,$(DRM_MODULES)))
341CONFIG_DRM_MACH64 := m
342endif
343
Thomas Hellstrom89d67d92004-03-23 21:14:17 +0000344
David Dawesdbb7beb2003-04-17 18:44:38 +0000345
346# These require AGP support
347
348ifdef CONFIG_AGP
349ifneq (,$(findstring mga,$(DRM_MODULES)))
350CONFIG_DRM_MGA := m
351endif
352ifneq (,$(findstring i810,$(DRM_MODULES)))
353CONFIG_DRM_I810 := m
354endif
David Dawesdbb7beb2003-04-17 18:44:38 +0000355ifneq (,$(findstring i830,$(DRM_MODULES)))
356CONFIG_DRM_I830 := m
357endif
Felix Kuehling3dea36d2004-02-22 16:20:16 +0000358ifneq (,$(findstring savage,$(DRM_MODULES)))
359CONFIG_DRM_SAVAGE := m
360endif
David Dawesdbb7beb2003-04-17 18:44:38 +0000361endif
362
363include $(DRMSRCDIR)/Makefile.kernel
364
365# Depencencies
366$(gamma-objs): $(GAMMAHEADERS)
367$(tdfx-objs): $(TDFXHEADERS)
368$(r128-objs): $(R128HEADERS)
369$(mga-objs): $(MGAHEADERS)
370$(i810-objs): $(I810HEADERS)
371$(i830-objs): $(I830HEADERS)
372$(radeon-objs): $(RADEONHEADERS)
373$(sis-objs): $(SISHEADERS)
374$(ffb-objs): $(FFBHEADERS)
Felix Kuehling3dea36d2004-02-22 16:20:16 +0000375$(savage-objs): $(SAVAGEHEADERS)
Thomas Hellstrom89d67d92004-03-23 21:14:17 +0000376$(via-objs): $(VIAHEADERS)
Dave Airlie873e1c42004-04-12 05:27:40 +0000377$(mach64-objs): $(MACH64HEADERS)
David Dawesdbb7beb2003-04-17 18:44:38 +0000378
379endif
Alan Hourihaneb3eb34e2003-03-25 11:36:43 +0000380