#
# Makefile for TSLinux's building of portslave
#

CROSS_COMPILE=/opt/hardhat/devkit/ppc/8xx/bin/ppc_8xx
CC=$(CROSS_COMPILE)-gcc
CXX=$(CROSS_COMPILE)-g++

INCLUDES=-I$(PROJ)/include -I$(PROJ)/linux/include -I$(PAM_DIR)/libpam/include -I$(PAM_DIR)/libpam_misc/include -I$(PAM_DIR)/libpamc/include

# use '-Os' optimization if available, else use -O2
OPTIMIZATION=$(shell if $(CC) -Os -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-Os"; else echo "-O2" ; fi )

CFLAGS=-Wall $(OPTIMIZATION) -fomit-frame-pointer $(INCLUDES) -DUSE_PAM -DCYCLADES -D_GNU_SOURCE -DCY_DLA_ALERT
LDFLAGS=-s

AS=$(CROSS_COMPILE)-as
LD=$(CROSS_COMPILE)-ld
CPP="$(CC) -E"
AR=$(CROSS_COMPILE)-ar
NM=$(CROSS_COMPILE)-nm
STRIP=$(CROSS_COMPILE)-strip --remove-section=.note --remove-section=.comment
OBJCOPY=$(CROSS_COMPILE)-objcopy
OBJDUMP=$(CROSS_COMPILE)-objdump
RANLIB=$(CROSS_COMPILE)-ranlib
MAKE=make

export

.PHONY: all target

all: configure pslave_cfg.h Makefile target

target: force
ifeq ($(TARG),ts1h)
	$(MAKE) all install TARGETS="cy_shm cy_buffering cy_ras portslave cy_wdt_led bootconf socket ts_menu wiz cy_alarm modbusd pu puconnect billing showsensor modem-replace 2way-raw sh_write_evt"
else
ifeq ($(TARG),ts1hbb)
	$(MAKE) all install TARGETS="cy_shm cy_buffering cy_ras portslave cy_wdt_led bootconf socket ts_menu wiz cy_alarm modbusd pu billing"
else
ifeq ($(TARG),sm100)
	$(MAKE) all install TARGETS="cy_shm cy_buffering cy_ras portslave cy_wdt_led bootconf socket ts_menu wiz cy_alarm sm"
else
	$(MAKE) all install TARGETS="cy_shm cy_buffering cy_ras portslave cy_wdt_led bootconf socket ts_menu wiz cy_alarm billing modem-replace 2way-raw sh_write_evt"
endif
endif
endif

pslave_cfg.h Makefile: Makefile.in ex_config configure pslave_cfg.h.in pslave.conf.in
	CC=$(CC) RANLIB="$(RANLIB)" AR="$(AR)" LD="$(CC)" NM="$(NM)" \
	STRIP="$(STRIP)" OBJCOPY="$(OBJCOPY)" OBJDUMP="$(OBJDUMP)" MAKE="$(MAKE)" \
	CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
	./configure	--prefix=$(TARGET_DIR) \
				--enable-sbindir=/bin \
				--enable-bindir=/bin \
				--enable-libdir=/lib \
				--with-nports=64 \
				--with-nvlines=1024 \
				--with-network=/etc/network \
				--enable-syslog \
				--host=powerpc-hardhat-linux \
				--enable-cyclades

configure: configure.in ex_config
	autoconf

cdk_sm100: Makefile pslave_cfg.h force
	make cdk_sm100

clean:
	if [ -f Makefile ] ; then \
		$(MAKE) clean ; \
	fi
	rm Makefile

force: ;
