LIBS=-lncurses libcli/libcli.a
CFLAGS=-I.. -Ilibcli -DHAVE_CONFIG_H -Wall -pedantic -g

CFILES=$(wildcard *.c)
OBJS=$(patsubst %.c,%.o,$(CFILES))

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

hnb: libcli/libcli.a Makefile $(OBJS) init_subsystems.c *.h *.inc
	$(CC) -o hnb $(OBJS) $(LIBS) $(CFLAGS)
#	strip hnb
libcli/libcli.a: libcli/*.c
	(cd libcli;make libcli.a)
libcli/libcli_p.a: libcli/*.c
	(cd libcli;make libcli_p.a)
init_subsystems.c: *.c
	echo "/* this file is autogenerated, do not edit */">init_subsystems.c
	cat *.c | grep "^\!init_" | sort | sed -e "s/^\!/void /g">>init_subsystems.c
	echo "">>init_subsystems.c
	echo "void init_subsystems(){">>init_subsystems.c
	cat *.c | grep "^\!init_" | sort | sed -e "s/^\!/ /g">>init_subsystems.c
	echo "}">>init_subsystems.c
clean:
	rm -f xml_debug hnb $(OBJS) *~ cli_*.inc
	(cd libcli;make clean)
hnb_p: *.c libcli/libcli_p.a init_subsystems.c
	$(CC) -o hnb_p *.c -pg -lncurses_p libcli/libcli_p.a -I.. -Ilibcli -DHAVE_CONFIG_H

ps:  xml_states.ps
xml_states.ps: xml.dot
	dot -Tps xml.dot > xml_states.ps
hnb1:
	cc -o hnb -lcurses -I.. -DHAVE_CONFIG_H -Ilibcli libcli/cli.c libcli/cli_history.c *.c -Wall
hnb2:
	cc -o hnb -lncurses -I.. -DHAVE_CONFIG_H -Ilibcli libcli/cli.c libcli/cli_history.c *.c -Wall
hnb3:
	/path/to/cross-compiler/cc -o hnb /usr/local/cross-tools/i386-mingw32msvc/lib/pdcurses.a libcli/libcli.a -I.. -DHAVE_CONFIG_H -Ilibcli libcli/cli.c libcli/cli_history.c *.c -Wall
