# USI++ Makefile
#

LIBS=@LIBS@
CFLAGS=@CFLAGS@ -I/usr/include/pcap -I. -Wall
CXX=@CXX@
INSTALL=@INSTALL@
RANLIB=@RANLIB@

all: clear usi++

clear:
	clear

usi++:icmp.o datalink.o ip.o misc.o udp.o tcp.o TX_IP.o Layer2.o arp.o
	ar cr libusi++.a *.o
	ld *.o -Bshareable -o libusi++.so
	$(RANLIB) libusi++.a
	rm -f *.o

arp.o: arp.cc
	$(CXX) $(CFLAGS) -c -O2 arp.cc

datalink.o: datalink.cc
	$(CXX) $(CFLAGS) -c -O2 datalink.cc

icmp.o: icmp.cc
	$(CXX) $(CFLAGS) -c -O2 icmp.cc

ip.o: ip.cc
	$(CXX) $(CFLAGS) -c -O2 ip.cc

misc.o: misc.cc
	$(CXX) $(CFLAGS) -c -O2 misc.cc

udp.o: udp.cc
	$(CXX) $(CFLAGS) -c -O2 udp.cc

tcp.o: tcp.cc
	$(CXX) $(CFLAGS) -c -O2 tcp.cc

Layer2.o: Layer2.cc
	$(CXX) $(CFLAGS) -c -O2 Layer2.cc

TX_IP.o: TX_IP.cc
	$(CXX) $(CFLAGS) -c -O2 TX_IP.cc

install:
	$(INSTALL) -g bin -o root -m 0755 libusi++.* /usr/lib
	mkdir -m 0755 /usr/include/usi++||true
	cp -R usi++/* /usr/include/usi++
	chown -R root /usr/include/usi++
	@echo To build programs using libusi++, you have to do \'c++ foo.cc -lusi++ $(LIBS)\'

uninstall:
	rm -f /usr/lib/libusi++.a
	rm -rf /usr/include/usi++

clean:
	rm -f *.o *.a
