ifndef KERNEL_DIR
KERNEL_DIR=/usr/src/linux
endif

ifndef RC_INIT_DIR
RC_INIT_DIR=/etc/rc.d/init.d
endif


KERNEL_VER = $(shell grep "\#define UTS_RELEASE" $(KERNEL_DIR)/include/linux/version.h | cut -d\" -f2)
MODULE_DIR = /lib/modules/$(KERNEL_VER)/net

MODVERSIONS = $(shell grep -q '^\#define CONFIG_MODVERSIONS' $(KERNEL_DIR)/include/linux/autoconf.h && echo -DMODVERSIONS -include $(KERNEL_DIR)/include/linux/modversions.h)

CC = gcc

COPT_FLAGS = -O2

CFLAGS += $(COPT_FLAGS) -Wall -D__KERNEL__ -DMODULE $(MODVERSIONS) -I./ -I$(KERNEL_DIR)/include

CFLAGS += $(shell grep '^CONFIG_SMP=y' $(KERNEL_DIR)/.config >/dev/null && echo -D__SMP__)

# use '-fno-strict-aliasing', but only if the compiler can take it
CFLAGS += $(shell if $(CC) -fno-strict-aliasing -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-fno-strict-aliasing"; fi)

# ARM-specific flags
CFLAGS += $(shell [ `uname -m` = armv4l ] && echo -fomit-frame-pointer -fno-strength-reduce -mshort-load-bytes -march=armv4 -mtune=strongarm110)

all: pppox.o

clean:
	rm -f pppox.o

install: all
	install -m 755 pppox.o "$(MODULE_DIR)/pppox.o"
	[ -d $(RC_INIT_DIR) ] && install -m 755 rc.pppox $(RC_INIT_DIR)/pppox  && chkconfig --add pppox
	#[ -d $(RC_INIT_DIR) ] && install -m 755 rc.pppox $(RC_INIT_DIR)/pppox 

ins: install
	/sbin/depmod -a
	$(RC_INIT_DIR)/pppox stop
	$(RC_INIT_DIR)/pppox start
