GCC_VER_MAJ      = $(shell $(CC) --version | head -n 1 | sed -e 's/[^0-9. ]//g;s/^ *//;s/^\(.\)\..*$$/\1/')

obj-m           += fglrx.o
fglrx-libs      += libfglrx_ip.a.GCC$(GCC_VER_MAJ)
fglrx-c-objs    += agp3.o nvidia-agp.o agpgart_be.o i7505-agp.o firegl_public.o
fglrx-objs      += $(fglrx-c-objs) $(fglrx-libs)
fglrx-hdrs      += agp_backend.h agp.h firegl_public.h
drm-hdrs        += drm.h drmP.h drm_os_linux.h drm_proc.h drm_compat.h

ifeq ($(PAGE_ATTR_FIX),)
PAGE_ATTR_FIX   =1
endif

EXTRA_CFLAGS    += \
                -I$(PWD) \
                -D__AGP__ \
                -DFGL \
                -DFGL_LINUX \
                -DFGL_GART_RESERVED_SLOT \
                -DFGL_LINUX253P1_VMA_API \
                -DPAGE_ATTR_FIX=$(PAGE_ATTR_FIX) \

ifeq ($(KERNELRELEASE),)
# on first call from remote location we get into this path
# whilst on second call all is managed by the embedding kernel makefile

KVER            = $(shell uname -r)
# KVER            = 2.6.0-0.test1.1.26custom

ifeq (1,1)
KDIR            = /lib/modules/$(KVER)/build
else
KDIR            = /usr/src/linux-$(KVER)
endif
PWD             = $(shell pwd)

fglrx-cfiles    = ${fglrx-c-objs:.o=.c}

# default:: kmod_build

kmod_build:: $(fglrx-libs) $(fglrx-cfiles) $(fglrx-hdrs) $(drm-hdrs)
	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

%.c:
	@ln -s ../$@

%.h:
	@ln -s ../$@

%.GCC$(GCC_VER_MAJ):
	@ln -s ../$@

# distclean:: clean

clean::
	rm -f *.c *.h *.o *.ko *.GCC* .??*

endif

# ### EOF ###
