TEXT2MIB=perl -I../tools ../tools/text2mib.pl

MIBSRC = vpndevice.mibsrc

# Note: The setting of dummy creates the module sources
DUMMY = $(shell $(TEXT2MIB) -c $(MIBSRC))
MODULE_SRCS = $(shell echo vpndevice.cpp getter_*.cpp setter_*.cpp init_*.cpp)
MODULE_OBJS = $(MODULE_SRCS:.cpp=.o)

OBJS = $(MODULE_OBJS) vpndevice_common.o pptputil.o
LIBRARY = libvpndevice.a

OBJS1 = testget.o
OBJS2 = testgetnext.o
OBJS3 = testset.o
EXECS = testset testget testgetnext
MIBS = vpndevice.mib vpndevice.javamib

CXXFLAGS += -I../asn -I../snmputil -I../agent
CXXFLAGS += -DCONFIG_VERSION=\"$(VERSIONPKG)\"
# To fix the gcc/glibc bug with bits/in.h and struct ip_opts
CXXFLAGS += -fpermissive
ifeq ($(release),debug)
CXXFLAGS += -g #-DDEBUG
else
CXXFLAGS += -DSNMP_MINIMAL
endif

USELIBS = ../snmputil/libsnmputil.a $(LIBRARY)

.PHONY: test romfs all clean
all: $(LIBRARY) $(MIBS)

$(LIBRARY): $(OBJS)
	$(AR) rcv $@ $(OBJS)

romfs:

test: $(EXECS)
	./testget
	./testgetnext

# Make sure we pick up a new VERSIONPKG from config.arch
getter_firmware.o: getter_firmware.cpp ../../../config.arch

vpndevice.mib: $(MIBSRC)
	$(TEXT2MIB) -m $(MIBSRC) >$@ || (rm $@; exit 1)

vpndevice.javamib: $(MIBSRC)
	$(TEXT2MIB) -j $(MIBSRC) >$@ || (rm $@; exit 1)

vpndevice.cpp vpndevice.h: $(MIBSRC)
	$(TEXT2MIB) -c $(MIBSRC) || (rm $@; exit 1)

testget: $(OBJS1) $(LIBRARY)
	$(CXX) $(LDFLAGS) -o $@ $(OBJS1) $(USELIBS)

testgetnext: $(OBJS2) $(LIBRARY)
	$(CXX) $(LDFLAGS) -o $@ $(OBJS2) $(USELIBS)

testset: $(OBJS3) $(LIBRARY)
	$(CXX) $(LDFLAGS) -o $@ $(OBJS3) $(USELIBS)

clean:
	rm -f $(MIBS) *.o vpndevice.cpp vpndevice.h $(LIBRARY) $(EXECS) core
