Subversion Repositories f9daq

Rev

Blame | Last modification | View Log | RSS feed


#****************************************************************************
# Copyright (C) 2001-2004  ARW Elektronik Germany
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Maintainer(s): Klaus Hitschler (klaus.hitschler@gmx.de)
#****************************************************************************

#****************************************************************************
#
# Makefile - makefile for ARW Elektronik CAMAC interfaces driver
#
#****************************************************************************
# please modify only here if your kernel path is elsewhere located
#
#
KERNEL_LOCATION =/usr/src/linux-headers-$(shell uname -r)
#****************************************************************************
# removed old kernel source path retrival for support of kernels < 2.2.18!
# old KERNSRC = /lib/modules/$(VERSION)/build
#
KERNSRC := $(KERNEL_LOCATION)

#****************************************************************************
# whole makefile is based on availability of version.h file
# do a forced stop if it is not available
#
HASVERSION_H := $(shell if test -f /usr/include/linux/version.h ; then echo yes ; else echo no; fi )

ifeq ($(HASVERSION_H),no)
$(error "Can't find $(KERNEL_LOCATION)/include/linux/version.h !")
else

#****************************************************************************
# removed old version retrival for better cross compile support

VERSION := $(shell cpp -dM -I$(KERNEL_LOCATION)/include $(KERNEL_LOCATION)/include/generated/utsrelease.h \
            | grep UTS_RELEASE | sed -e 's;[^"]*"\(.*\)";\1;g')


#****************************************************************************
# where the driver should be installed - change here for cross install - currently not functional
#

INSTALL_LOCATION = /lib/modules/$(shell uname -r)/kernel/drivers/misc/

#****************************************************************************
# get extracted kernel VERSION and PATCHLEVEL for comparison
# decide to use KBUILD for kernels greater 2.6.0
#
KVERSION    := $(shell echo $(VERSION) | sed -e 's;\([1-9]\)\..*;\1;g' )
KPATCHLEVEL := $(shell echo $(VERSION) | sed -e 's;[1-9]\.\([0-9]\{0,3\}\)\..*;\1;g' )
USEKBUILD   := $(shell if [ $(KVERSION) -gt 2 ] || [ $(KVERSION) -eq 2 ] && [ $(KPATCHLEVEL) -ge 6 ]  ; \
                 then echo "yes" ; else echo "no"  ; fi)

#****************************************************************************
# some common switches and defines
#
#DBG     = __NO_DEBUG__  # or __DEBUG__ to debug the driver
DBG     = __DEBUG__ 
SRC     = .

#****************************************************************************
# preparation what to build or what to KBUILD
#
pcicc32-objs :=  $(SRC)/main.o $(SRC)/list.o $(SRC)/askpci.o $(SRC)/plxbug.o $(SRC)/fops.o


ifeq ($(USEKBUILD),yes) # <<<<< USEKBUILD >>>>>>

#****************************************************************************
# for local installation only: sometimes /etc/modprobe.conf.local is used
#
MODCONF = /etc/modprobe.conf
MODINST = "install pcicc32 /sbin/modprobe --ignore-install pcicc32; /usr/local/bin/pcicc32_make_devices 2"

#****************************************************************************
# what's the target
#
TARGET = pcicc32.ko
obj-m := pcicc32.o

#****************************************************************************
# add flags to standard flags
#
CPPFLAGS += -I$(PWD) -D$(DBG)

#****************************************************************************
# do it
#
all : message
        $(MAKE) -C $(KERNSRC) M=$(PWD) V=$(VERBOSE) $(filter-out all, $(MAKECMDGOLAS)) modules

else # <<<<< USEKBUILD >>>>>>

#****************************************************************************
# for local installation only: sometimes /etc/modules.conf.local is used
#
MODCONF = /etc/modules.conf
MODINST = "post-install pcicc32 /usr/local/bin/pcicc32_make_devices 2"

#****************************************************************************
# additional common switches and defines
#
CC      = gcc
LD      = ld
INC     = -I$(SRC) -I$(KERNSRC)/include
DEP     = .depend

#****************************************************************************
# what's the target
#
TARGET = pcicc32.o

#****************************************************************************
# compile flags
#
CFLAGS = -O2 -D__KERNEL__ -DMODULE -Wall $(INCLUDE) -D$(DBG) $(INC) -I$(PWD)

#****************************************************************************
# do it
#
all: message $(TARGET)

$(TARGET)  : $(pcicc32-objs)
        $(LD) -r $^ -o $@

#********** catch include file depencies ************************************
ifeq ($(DEP),$(wildcard $(DEP)))

depend:
        makedepend -f$(DEP) -- $(CFLAGS) -- $(addsuffix .c, $(basename $(pcicc32-objs))) -I$(INC)

include $(DEP)

else

depend:
        touch $(DEP)
        makedepend -f$(DEP) -- $(CFLAGS) -- $(addsuffix .c, $(basename $(pcicc32-objs))) -I$(INC)
endif

endif # <<<<< USEKBUILD >>>>>>

#********** clean all for a rebuild *****************************************
clean:
        rm -f *~ $(TARGET) $(pcicc32-objs)

#********** clean all for a rebuild *****************************************
fresh:
        touch *.c
        make all
        
#********** informations during build of driver *****************************
.PHONY : message
message:
        @ echo "***"
        @ echo "*** Host machine kernel version=$(shell uname -r), Driver kernel version=$(VERSION), Path to kernel sources=$(KERNSRC), use KBUILD=$(USEKBUILD)"
        @ echo "***"


#********** this entry is reserved for root access only *********************
install:
        @if test -d $(INSTALL_LOCATION) ; then echo "info: $(INSTALL_LOCATION) exists."; else mkdir $(INSTALL_LOCATION); fi
        cp $(TARGET) $(INSTALL_LOCATION)/$(TARGET)
        cp pcicc32_make_devices /usr/local/bin/pcicc32_make_devices
        if test -z $(shell grep -l pcicc32 $(MODCONF)); then\
                cp $(MODCONF) $(MODCONF)~;\
                echo ""                                                  >> $(MODCONF);\
                echo "# pcicc32 - automatic made entry, begin --------"  >> $(MODCONF);\
                echo $(MODINST)                                          >> $(MODCONF);\
                echo "# pcicc32 - automatic made entry, end ----------"  >> $(MODCONF);\
                echo ""                                                  >> $(MODCONF);\
        fi
        /sbin/depmod
        cp pcicc32.h /usr/include/pcicc32.h
        chmod 644 /usr/include/pcicc32.h

endif  # <<<<< HASVERSION_H >>>>>>

# DO NOT DELETE