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