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