Completeley rewritten Savage DRM which can be considered secure (modulo
[platform/upstream/libdrm.git] / linux-core / Makefile
1 # Makefile -- For the Direct Rendering Manager module (drm)
2 #
3 # Based on David Woodhouse's mtd build.
4 #
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.
8 #
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.
13 #
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 $
15 #
16
17 #
18 # By default, the build is done against the running linux kernel source.
19 # To build against a different kernel source tree, set LINUXDIR:
20 #
21 #    make LINUXDIR=/path/to/kernel/source
22
23 #
24 # To build only some modules, either set DRM_MODULES to the list of modules,
25 # or specify the modules as targets:
26 #
27 #    make r128.o radeon.o
28 #
29 # or:
30 #
31 #    make DRM_MODULES="r128 radeon"
32 #
33
34 SHELL=/bin/sh
35
36 .SUFFIXES:
37
38 ifndef LINUXDIR
39 RUNNING_REL := $(shell uname -r)
40
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)
44 endif
45
46 ifndef O
47 O := $(LINUXDIR)
48 endif
49
50 MACHINE := $(shell uname -m)
51
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
54
55 # Modules only for ix86 architectures
56 ifneq (,$(findstring 86,$(MACHINE)))
57 ARCHX86 := 1
58 MODULE_LIST += i830.o i810.o i915.o
59 endif
60
61 ifneq (,$(findstring sparc64,$(MACHINE)))
62 ARCHSPARC64 := 1
63 MODULE_LIST += ffb.o
64 endif
65
66 DRM_MODULES ?= $(MODULE_LIST)
67
68 # These definitions are for handling dependencies in the out of kernel build.
69
70 DRMSHARED =     drm.h drm_sarea.h
71 DRMHEADERS =    drmP.h drm_compat.h drm_os_linux.h $(DRMSHARED)
72 COREHEADERS =   drm_core.h 
73
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 SAVAGESHARED=   savage_drv.h savage_drm.h savage_bci.c savage_state.c
92 VIAHEADERS =    via_drm.h via_drv.h via_mm.h via_ds.h \
93                 via_3d_reg.h $(DRMHEADERS)
94 VIASHARED       = via_drm.h via_drv.h via_mm.h via_ds.h \
95                 via_3d_reg.h via_drv.c via_ds.c via_irq.c via_map.c \
96                 via_mm.c via_dma.c via_verifier.c
97 MACH64HEADERS = mach64_drv.h mach64_drm.h $(DRMHEADERS)
98 MACH64SHARED =  mach64_drv.h mach64_drm.h mach64_dma.c \
99                 mach64_irq.c mach64_state.c
100 FFBHEADERS =    ffb_drv.h $(DRMHEADERS)
101
102 SHAREDSRC = $(DRMSHARED) $(MGASHARED) $(R128SHARED) $(RADEONSHARED) \
103         $(SISSHARED) $(TDFXSHARED) $(VIASHARED) $(MACH64SHARED) \
104         $(I915SHARED) $(SAVAGESHARED)
105
106 PROGS = dristat drmstat
107
108 CLEANFILES = *.o *.ko $(PROGS) .depend .*.flags .*.d .*.cmd *.mod.c linux drm_pciids.h .tmp_versions
109
110 # VERSION is not defined from the initial invocation.  It is defined when
111 # this Makefile is invoked from the kernel's root Makefile.
112
113 ifndef VERSION
114
115 ifdef RUNNING_REL
116
117 # SuSE has the version.h and autoconf.h headers for the current kernel
118 # in /boot as /boot/vmlinuz.version.h and /boot/vmlinuz.autoconf.h.
119 # Check these first to see if they match the running kernel.
120
121 BOOTVERSION_PREFIX = /boot/vmlinuz.
122
123 V := $(shell if [ -f $(BOOTVERSION_PREFIX)version.h ]; then \
124         grep UTS_RELEASE $(BOOTVERSION_PREFIX)version.h | \
125         cut -d' ' -f3; fi)
126
127 ifeq ($(V),"$(RUNNING_REL)")
128 HEADERFROMBOOT := 1
129 GETCONFIG := MAKEFILES=$(shell pwd)/.config
130 HAVECONFIG := y
131 endif
132
133 # On Red Hat we need to check if there is a .config file in the kernel
134 # source directory.  If there isn't, we need to check if there's a
135 # matching file in the configs subdirectory.
136
137 ifneq ($(HAVECONFIG),y)
138 HAVECONFIG := $(shell if [ -e $(LINUXDIR)/.config ]; then echo y; fi)
139 endif
140
141 ifneq ($(HAVECONFIG),y)
142 REL_BASE := $(shell echo $(RUNNING_REL) | sed 's/-.*//')
143 REL_TYPE := $(shell echo $(RUNNING_REL) | sed 's/[0-9.-]//g')
144 ifeq ($(REL_TYPE),)
145 RHCONFIG := configs/kernel-$(REL_BASE)-$(MACHINE).config
146 else
147 RHCONFIG := configs/kernel-$(REL_BASE)-$(MACHINE)-$(REL_TYPE).config
148 endif
149 HAVECONFIG := $(shell if [ -e $(LINUXDIR)/$(RHCONFIG) ]; then echo y; fi)
150 ifneq ($(HAVECONFIG),y)
151 RHCONFIG :=
152 endif
153 endif
154
155 ifneq ($(HAVECONFIG),y)
156 ifneq ($(0),$(LINUXDIR))
157 GETCONFIG += O=$(O)
158 endif
159 HAVECONFIG := $(shell if [ -e $(O)/.config ]; then echo y; fi)
160 endif
161
162 ifneq ($(HAVECONFIG),y)
163 $(error Cannot find a kernel config file)
164 endif
165
166 endif
167
168 CLEANCONFIG := $(shell if cmp -s $(LINUXDIR)/.config .config; then echo y; fi)
169 ifeq ($(CLEANCONFIG),y)
170 CLEANFILES += $(LINUXDIR)/.config .config $(LINUXDIR)/tmp_include_depends
171 endif
172
173 all: modules
174
175 modules: includes
176         make -C $(LINUXDIR) $(GETCONFIG) SUBDIRS=`pwd` DRMSRCDIR=`pwd` modules
177
178 ifeq ($(HEADERFROMBOOT),1)
179
180 BOOTHEADERS = version.h autoconf.h
181 BOOTCONFIG = .config
182
183 CLEANFILES += $(BOOTHEADERS) $(BOOTCONFIG)
184
185 includes:: $(BOOTHEADERS) $(BOOTCONFIG)
186
187 version.h: $(BOOTVERSION_PREFIX)version.h
188         rm -f $@
189         ln -s $< $@
190
191 autoconf.h: $(BOOTVERSION_PREFIX)autoconf.h
192         rm -f $@
193         ln -s $< $@
194
195 .config: $(BOOTVERSION_PREFIX)config
196         rm -f $@
197         ln -s $< $@
198 endif
199
200 # This prepares an unused Red Hat kernel tree for the build.
201 ifneq ($(RHCONFIG),)
202 includes:: $(LINUXDIR)/.config $(LINUXDIR)/tmp_include_depends .config
203
204 $(LINUXDIR)/.config: $(LINUXDIR)/$(RHCONFIG)
205         rm -f $@
206         ln -s $< $@
207
208 .config: $(LINUXDIR)/$(RHCONFIG)
209         rm -f $@
210         ln -s $< $@
211
212 $(LINUXDIR)/tmp_include_depends:
213         echo all: > $@
214 endif
215
216 # Make sure that the shared source files are linked into this directory.
217
218
219 SHAREDDIR := ../shared-core
220
221 HASSHARED := $(shell if [ -d $(SHAREDDIR) ]; then echo y; fi)
222
223 ifeq ($(HASSHARED),y)
224 includes:: $(SHAREDSRC) drm_pciids.h
225
226 drm_pciids.h: $(SHAREDDIR)/drm_pciids.txt
227         sh ../scripts/create_linux_pci_lists.sh < $(SHAREDDIR)/drm_pciids.txt
228
229 $(SHAREDSRC):
230         @if [ -r $(SHAREDDIR)/$@ ]; then \
231                 (rm -f $@; set -x; ln -s $(SHAREDDIR)/$@ $@); fi
232
233 CLEANFILES += $(SHAREDSRC)
234 endif
235
236 includes:: linux
237
238 linux:
239         rm -f linux
240         ln -s . linux
241
242 clean cleandir:
243         rm -rf $(CLEANFILES)
244
245 $(MODULE_LIST)::
246         make DRM_MODULES=$@ modules
247
248 # Build test utilities
249
250 PRGCFLAGS = $(CFLAGS) -g -ansi -pedantic -DPOSIX_C_SOURCE=199309L \
251             -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE \
252             -I. -I../../..
253
254 DRMSTATLIBS = -L../../.. -L.. -ldrm -lxf86_os \
255               -L../../../../dummylib -ldummy -lm
256
257 programs: $(PROGS)
258
259 dristat: dristat.c
260         $(CC) $(PRGCFLAGS) $< -o $@
261
262 drmstat: drmstat.c
263         $(CC) $(PRGCFLAGS) $< -o $@ $(DRMSTATLIBS)
264
265 else
266
267 # Check for kernel versions that we don't support.
268
269 BELOW24 := $(shell if [ $(VERSION) -lt 2 -o $(PATCHLEVEL) -lt 4 ]; then \
270                 echo y; fi)
271
272 ifeq ($(BELOW24),y)
273 $(error Only 2.4.x and later kernels are supported \
274         ($(VERSION).$(PATCHLEVEL).$(SUBLEVEL)))
275 endif
276
277 ifdef ARCHX86
278 ifndef CONFIG_X86_CMPXCHG
279 $(error CONFIG_X86_CMPXCHG needs to be enabled in the kernel)
280 endif
281 endif
282
283 # This needs to go before all other include paths.
284 CC += -I$(DRMSRCDIR)
285
286 # Check for Red Hat's 4-argument do_munmap().
287 DOMUNMAP := $(shell grep do_munmap $(LINUXDIR)/include/linux/mm.h | \
288                 grep -c acct)
289
290 ifneq ($(DOMUNMAP),0)
291 EXTRA_CFLAGS += -DDO_MUNMAP_4_ARGS
292 endif
293
294 # Check for 5-argument remap_page_range() in RH9 kernel, and 2.5.x kernels
295 RPR := $(shell grep remap_page_range $(LINUXDIR)/include/linux/mm.h | \
296                 grep -c vma)
297
298 ifneq ($(RPR),0)
299 EXTRA_CFLAGS += -DREMAP_PAGE_RANGE_5_ARGS
300 endif
301
302 # Check for 4-argument vmap() in some 2.5.x and 2.4.x kernels
303 VMAP := $(shell grep -A1 'vmap.*count,$$' $(LINUXDIR)/include/linux/vmalloc.h | \
304                 grep -c prot)
305
306 ifneq ($(VMAP),0)
307 EXTRA_CFLAGS += -DVMAP_4_ARGS
308 endif
309
310 # Check for PAGE_AGP definition
311 PAGE_AGP := $(shell cat $(LINUXDIR)/include/asm/agp.h 2>/dev/null | \
312                 grep -c PAGE_AGP)
313
314 ifneq ($(PAGE_AGP),0)
315 EXTRA_CFLAGS += -DHAVE_PAGE_AGP
316 endif
317
318
319 # Start with all modules turned off.
320 CONFIG_DRM_GAMMA := n
321 CONFIG_DRM_TDFX := n
322 CONFIG_DRM_MGA := n
323 CONFIG_DRM_I810 := n
324 CONFIG_DRM_R128 := n
325 CONFIG_DRM_RADEON := n
326 CONFIG_DRM_I830 := n
327 CONFIG_DRM_I915 := n
328 CONFIG_DRM_SIS := n
329 CONFIG_DRM_FFB := n
330 CONFIG_DRM_SAVAGE := n
331 CONFIG_DRM_VIA := n
332 CONFIG_DRM_MACH64 := n
333
334 # Enable module builds for the modules requested/supported.
335
336 ifneq (,$(findstring tdfx,$(DRM_MODULES)))
337 CONFIG_DRM_TDFX := m
338 endif
339 ifneq (,$(findstring r128,$(DRM_MODULES)))
340 CONFIG_DRM_R128 := m
341 endif
342 ifneq (,$(findstring radeon,$(DRM_MODULES)))
343 CONFIG_DRM_RADEON := m
344 endif
345 ifneq (,$(findstring sis,$(DRM_MODULES)))
346 CONFIG_DRM_SIS := m
347 endif
348 ifneq (,$(findstring via,$(DRM_MODULES)))
349 CONFIG_DRM_VIA := m
350 endif
351 ifneq (,$(findstring mach64,$(DRM_MODULES)))
352 CONFIG_DRM_MACH64 := m
353 endif
354 ifneq (,$(findstring ffb,$(DRM_MODULES)))
355 CONFIG_DRM_FFB := m
356 endif
357
358 # These require AGP support
359
360 ifdef CONFIG_AGP
361 ifneq (,$(findstring mga,$(DRM_MODULES)))
362 CONFIG_DRM_MGA := m
363 endif
364 ifneq (,$(findstring i810,$(DRM_MODULES)))
365 CONFIG_DRM_I810 := m
366 endif
367 ifneq (,$(findstring i830,$(DRM_MODULES)))
368 CONFIG_DRM_I830 := m
369 endif
370 ifneq (,$(findstring i915,$(DRM_MODULES)))
371 CONFIG_DRM_I915 := m
372 endif
373 ifneq (,$(findstring savage,$(DRM_MODULES)))
374 CONFIG_DRM_SAVAGE := m
375 endif
376 endif
377
378 include $(DRMSRCDIR)/Makefile.kernel
379
380 # Depencencies
381 $(drm-objs):    $(DRMHEADERS) $(COREHEADERS)
382 $(tdfx-objs):   $(TDFXHEADERS)
383 $(r128-objs):   $(R128HEADERS)
384 $(mga-objs):    $(MGAHEADERS)
385 $(i810-objs):   $(I810HEADERS)
386 $(i830-objs):   $(I830HEADERS)
387 $(i915-objs):   $(I830HEADERS)
388 $(radeon-objs): $(RADEONHEADERS)
389 $(sis-objs):    $(SISHEADERS)
390 $(ffb-objs):    $(FFBHEADERS)
391 $(savage-objs): $(SAVAGEHEADERS)
392 $(via-objs):    $(VIAHEADERS)
393 $(mach64-objs): $(MACH64HEADERS)
394
395 endif
396