#-------------------------------------------------------------------------------
# Makefile
#
# Copyright (c) 2012 
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the GNU Public License v2.0
# which accompanies this distribution, and is available at
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# 
# Contributors:
#   Cesar Prados  
#	Benoit Rat
#-------------------------------------------------------------------------------


# Parameters
ifeq ($(strip $(WRS_BASE_DIR)),)
$(error You first need to define WRS_BASE_DIR variable)
#WRS_BASE_DIR=/home/neub/Work/7S/WR/wr-switch-sw/build
endif

EXEC = shw_tool 
INCLUDES =-I. -I${WRS_BASE_DIR}/../userspace/include -I${WRS_BASE_DIR}/../userspace/libswitchhw
LDFLAGS = -L${WRS_BASE_DIR}/../userspace/libswitchhw -lswitchhw -lm -ldl -llua
CFLAGS =  -O2  -DDEBUG -g ${INCLUDES} ${LDFLAGS}
DEPS = 

# Autoconfigurated
SRC=$(wildcard *.c)
OBJECTS = $(SRC:.c=.o)
CC = ${CROSS_COMPILE}gcc


#############
all: libswitchhw.a ${WRS_BASE_DIR}/../userspace/libswitchhw/libswitchhw.a $(EXEC) 
	
libswitchhw.a:
	$(MAKE) -C ${WRS_BASE_DIR}/../userspace/libswitchhw all	

%.o: %.c %.h $(DEPS)
	${CC} ${CFLAGS}  -c $< -o $@ 

$(EXEC): $(OBJECTS)
	${CC}  $^ -o $@ ${LDFLAGS}

clean:
	rm -f ${OBJECTS} $(EXEC)

##############

INSTALLDIR=alpha-pts/bin/

install: all
	$(MAKE) -C ${WRS_BASE_DIR}/../userspace/libswitchhw install
	cp $(EXEC) ../$(INSTALLDIR)
	cp $(EXEC) $(WR_INSTALL_ROOT)/bin/

	#cp $(EXEC) $(WR_INSTALL_ROOT)/../$(INSTALLDIR)

install2: libswitchhw.a clean install	
