#~~syntax:makefile
#==============================================================================
# ttyrpld - TTY replay daemon
#   Copyright (C) Jan Engelhardt <jengelh [at] linux01 gwdg de>, 2004
#   -- License restrictions apply (GPL2)
#
#   This file is part of ttyrpld.
#   ttyrpld 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; however only version 2 of the License.
#
#   ttyrpld 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 kit; if not, write to:
#   Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
#   02111-1307, USA.
#
#   -- For details see doc/GPL2.txt.
#==============================================================================
KERN_DIR := $(shell readlink /lib/modules/`uname -r`/build)
include $(KERN_DIR)/.config

### Programs ------------------------------------------------------------------
#
KCC      := gcc
## Gosh, this is ugly, but I fixed it (see the two lines commented-out below)
## so it should work with non-x86 too.
KFLAGS   := -D__KERNEL__ -DMODULE -I${KERN_DIR}/include -I../include -O2 \
            -Wall -Wno-sign-compare -Wno-trigraphs -Wstrict-prototypes \
            -finline-functions -finline-limit=2000 -fno-common \
            -fno-strict-aliasing -fomit-frame-pointer -pipe -nostdinc \
            -iwithprefix include

# -march=athlon -mpreferred-stack-boundary=2
# -Waggregate-return -Wmissing-declarations -Wmissing-prototypes -Wshadow

KLD      := ld
KLDFLAGS :=

ifdef CONFIG_SMP
  KFLAGS += -D__SMP__ -DSMP
endif

ifneq (${MARCH},)
  CFLAGS += -march=${MARCH}
  KFLAGS += -march=${MARCH}
endif
ifneq (${MCPU},)
  CFLAGS += -mcpu=${MCPU}
  KFLAGS += -mcpu=${MCPU}
endif

ifeq (${VERBOSE},)
  KCC   := @${KCC}
  KLD   := @${KLD}
  LN    := @${LN}
  RM    := @${RM}
  STRIP := @${STRIP}

  VECHO_CC  = @echo "[CC] " $@
  VECHO_LD  = @echo "[LD] " $@
  VECHO_KCC = @echo "[KCC]" $@
  VECHO_KLD = @echo "[KLD]" $@
  VECHO_DEP = @echo "[DEP]" $@
endif

#------------------------------------------------------------------------------
.PHONY: all clean cleanx

all: rpldev.o;

%.o: %.c;
	${VECHO_KCC}
	${KCC} ${KFLAGS} -DKBUILD_BASENAME=$* -c -o $@ $<;

clean: ;
	${RM} -f *.o;

cleanx: clean;
	${RM} -f *.d;

#--( C/H Dependencies )--------------------------------------------------------
Makefile: $(patsubst %.c,%.d,$(wildcard *.c))

%.d: %.c;
	${VECHO_DEP}
	${KCC} ${KFLAGS} -MM -MF $@ -MT $(@:.d=.o) $<;

_DEP_FILES := $(wildcard *.d)
ifneq (${_DEP_FILES},)
-include ${_DEP_FILES}
endif

#==[ End of file ]=============================================================
