### ==========================================================================
### Makefile for the ULeague Command Server
###  $Id$
### --------------------------------------------------------------------------

BRICKOS_ROOT=/usr/local/robocup/Lego-Mindstorms/brickos.jacky
BUILDING_HOST_UTILS = true

include $(BRICKOS_ROOT)/Makefile.common

INSTALL_DIR = .
EXE1 = command_server$(EXT)
MAN1 = command_server.1
TARGET1 = $(INSTALL_DIR)/$(EXE1)
SRCS1 = command_server.c rcxtty.c lex.yy.c $(BRICKOS_ROOT)/kernel/lnp.c 
OBJS1 = $(notdir $(SRCS1:.c=.o))

ALL_TARGETS        = $(TARGET1)
LIBS=-lpthread -lm -L$(BRICKOS_ROOT)/../LegoUSB/drivers/linux/ -llegousbapi

CFLAGS=-Wall -I. -I$(BRICKOS_ROOT)/include/lnp -I$(BRICKOS_ROOT)/../LegoUSB/drivers/linux/include

CFLAGS+= -g -DDEBUG

all::  $(ALL_TARGETS)
	@# nothing to do here but do it silently

clean:
	rm -f *.o *~ *.bak 

realclean: clean
	rm -f $(ALL_TARGETS) 
	@rm -f .depend install-stamp

.depend:
	$(CC) -M $(CFLAGS) -c $(SRCS1) $(SRCS2) >.depend

depend:: .depend
	@# nothing to do here but do it silently

install: install-stamp
	@# nothing to do here but do it silently

install-stamp: $(ALL_TARGETS)
	cp -f $(TARGET1) $(bindir)/$(EXE1)
	@if [ ! -d ${pkglibdir} ]; then \
		mkdir -p ${pkglibdir}; \
	fi
	cp -f $(TARGET2) $(pkglibdir)/$(EXE2)
	cp -f $(TARGET3) $(pkglibdir)/$(EXE3)
	cp -f $(TARGET4) $(pkglibdir)/$(EXE4)
	@if [ ! -d ${mandir}/man1 ]; then \
		mkdir -p ${mandir}/man1; \
	fi
	cp -f $(MAN1) $(mandir)/man1/$(MAN1)
	@touch $@

uninstall:
	rm -f install-stamp $(mandir)/man1/$(MAN1) $(bindir)/$(EXE1)

$(TARGET1):  $(OBJS1)
	$(CC) -o $@ $(OBJS1) $(LIBS) $(CFLAGS)

$(TARGET2):  $(OBJS2)
	$(CC) -o $@ $(OBJS2) $(LIBS) $(CFLAGS)

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

%.o: $(BRICKOS_ROOT)/kernel/%.c
	$(CC) -o $@ -c $< $(CFLAGS)

../%$(EXT): %.c
	$(CC) -o $@ $< $(CFLAGS)

.PHONY: depend all clean realclean install

lex.yy.c: scanner.l
	flex scanner.l

scanner_test: lex.yy.c
	gcc -DTEST_SCANNER -O -Wall -g -DDEBUG lex.yy.c -o $@

### --------------------------------------------------------------------------
###                   End of FILE: Makefile
### ==========================================================================
