include CONFIG

OBJ = main.o Exec.o Lang.o Grouping.o Queue.o XmlProg.o SubLang.o Headers.o Cache.o
# Hypertext Scripting Markup Language
BIN = hsml
DEBUG=-g
DEFS+=  -DINCORE_LUA=${INCORE_LUA}
DEFS+=	-DPATH_JAVA=\"${JAVA}\"
DEFS+=	-DPATH_CC=\"${PATH_CC}\"
CFLAGS+= ${DEBUG} ${DEFS}
PICFLAGS?=-fPIC

%.o: %.c
	@echo "[hsml] $<"
	@${CC} $< -c ${CFLAGS} ${PICFLAGS} -o $@

all: opts ${OBJ} langs
	@echo "[hsml] LINKING..."
	@${CC} ${CFLAGS} ${LDFLAGS} ${OBJ} -o ${BIN} `cat .opts`
	@echo "-----------------"

clean:
	rm -f ${OBJ} ${BIN} core
	@echo " *** hsml - CLEAN OK"

opts:
	echo > .opts
	if [ "${INCORE_LUA}" = "1" ]; then echo "-L /usr/pkg/lib ${COMPILER_RPATH_FLAG}/usr/pkg/lib -llua -lm " > .opts ; \
	else echo "" > .opts ; fi
	if [ "`uname`" = "Linux" ]; then echo " -ldl " >> .opts ; fi

todo:
	grep -e TODO -e XXX *.c

check:
	@for A in test/* ; do \
	echo " - Parsing $$A..."; \
	./${BIN} $$A > /dev/null ;\
	if [ ! "$$?" = "0" ]; then \
	echo "PARSE ERROR\n"; \
	exit 1; fi \
	done

langs:
	@echo "[hsml] C lang module"
	@${CC} ${CFLAGS} ${PICFLAGS} lang_c.c -shared -o lang_c.so
	@echo "[hsml] Perl lang module"
	@${CC} ${CFLAGS} ${PICFLAGS} lang_perl.c -shared -o lang_perl.so
	@echo "[hsml] Python lang module"
	@${CC} ${CFLAGS} ${PICFLAGS} lang_python.c -shared -o lang_python.so
	@echo "[hsml] Brainfuck lang module"
	@${CC} ${CFLAGS} ${PICFLAGS} lang_brainfuck.c -shared -o lang_brainfuck.so

modules_install:
	install -c -m 0755 \
		lang_c.so \
		lang_perl.so \
		lang_python.so \
		lang_brainfuck.so \
	${MODULE_PATH}

