###############################################################################
#
# (c) Copyright IBM Corp. 2005 All Rights Reserved
#
# Physical Memory Information Module
#
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Author International Business Machines
# Author Paul Movall <movall@us.ibm.com>
#
# Version Current Version: 1.0
#
# Date Current Date: 01/2005
#
# Version 0.1, 11/2003: File created by Paul Movall <movall@us.ibm.com>
# Version 1.0, 01/2005: Miscellaneous cleanup for publish
#
###############################################################################

.PHONY: clean tests doc

DATE=$(shell date +%m-%d-%Y)

# Comment/uncomment the following line to disable/enable debugging

# Subdirectories

INTEL_INCLUDE_DIR = /lib/modules/2.4.18-14/build/include
INTEL_HEADER_DIR = /lib/modules/2.4.18-14/build/include
INTEL_CFLAGS = $(DEBFLAGS) -I$(INCLUDE_DIR)
INTEL_KFLAGS = -D__KERNEL__ -DMODULE 
INTEL_SUFFIX = x86
INTEL_CROSS = 

PPC_INCLUDE_DIR = /opt/fsp/powerpc-linux/include
PPC_HEADER_DIR = /opt/fsp/powerpc-linux/include/
PPC_CFLAGS = -Wall -mcpu=403 $(DEBFLAGS) -I. -I$(INCLUDE_DIR) -I/opt/fsp/src/linux/arch/ppc
PPC_KFLAGS = -D__KERNEL__ -DMODULE -Wstrict-prototypes -fomit-frame-pointer -fno-strict-aliasing -D__powerpc__ -fsigned-char -msoft-float -pipe -ffixed-r2 -Wno-uninitialized -mmultiple -mstring -DEXPORT_SYMTAB
PPC_SUFFIX = ppc
PPC_CROSS = powerpc-linux-

ifeq ($(ARCH),intel)
  INCLUDE_DIR = $(INTEL_INCLUDE_DIR)
  HEADER_DIR = $(INTEL_HEADER_DIR)
  CFLAGS = $(INTEL_CFLAGS)
  KFLAGS = $(INTEL_KFLAGS)
  SUFFIX = $(INTEL_SUFFIX)
  CROSS = $(INTEL_CROSS)
else
  INCLUDE_DIR = $(PPC_INCLUDE_DIR)
  HEADER_DIR = $(PPC_HEADER_DIR)
  CFLAGS = $(PPC_CFLAGS)
  KFLAGS = $(PPC_KFLAGS)
  SUFFIX = $(PPC_SUFFIX)
  CROSS = $(PPC_CROSS)
endif

ifeq ($(DEBUG),y)
  DEBFLAGS = -O2 -DDEBUG
else
  DEBFLAGS = -O2
endif


CC = $(CROSS)gcc
LD = $(CROSS)ld
DOXYGEN = doxygen   

# version of this driver
VERSION = 0.1


# extract kernel version number from kernel headers.
VER = $(shell awk -F\" '/REL/ {print $$2}' $(INCLUDE_DIR)/linux/version.h)

SRCS    = mem-task.c

TARGETS = physmem_info_$(SUFFIX).o
OBJS   = $(SRCS:.c=_$(SUFFIX).o)

all: $(TARGETS) .depend

$(TARGETS): $(OBJS)
	$(LD) -r -o $@ $^

%_$(SUFFIX).o: %.c
	$(CC) -c $(CFLAGS) $(KFLAGS) $< -o $@

install: $(TARGETS)
	mkdir -p /local/export/meminfo
	install -c $(TARGETS) $(INSTALL_DIR)

clean distclean:
	$(RM) $(TARGETS) *.o *~ core .depend *.LOG dep depend
	$(RM) -r man
	$(RM) -r html
	$(RM) -r latex

tgz:
	tar cvfz /tmp/meminfo-$(DATE).tgz $(SRCS) *load bugs.txt Makefile

ident: all
	ident $(TARGET).o | awk '{ printf("%-14s %10s %s %s %s %s\n",$$2,$$3,$$4,$$5,$$6,$$7)}'

dep depend .depend:
	$(CC) $(CFLAGS) -M *.c > .depend

ifeq (.depend,$(wildcard .depend))
include .depend
endif
