OSDN Git Service

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