################################################################################
# dpuser-parser/lex Makefile
################################################################################

MV         = mv
RM         = rm -f
CP         = cp

ifeq ($(PLATFORM), WIN)
   # didn't manage to do this as onliner like in the unix-case, pipe doesn't work...
   ARCH := $(shell wmic os get osarchitecture)
   $(shell @echo $(ARCH) > _bbb.txt)
   ARCH := $(shell sed  -e "s/OSArchitecture//g" -e "s/ //g" -e "s/-bit//g" -e "s/-Bit//g" _bbb.txt)
   $(shell del _bbb.txt)

   YACC    = ..\..\bin\WIN$(ARCH)\yacc.exe
   LEX     = ..\..\bin\WIN$(ARCH)\flex.exe
   SED     = ..\..\bin\WIN$(ARCH)\sed.exe -i''
   MV      = ren
   RM      = del
	 CP      = copy /Y
else
   ifeq ($(shell uname -m), x86_64)
      ARCH = 64
   else
      ARCH = 32
   endif

   ifeq ($(PLATFORM), LINUX)
      YACC = ../../bin/LINUX$(ARCH)/yacc -d
      LEX  = flex -l
      SED  = sed -i''
   endif
   ifeq ($(PLATFORM), MACOSX)
      YACC = yacc
      LEX  = flex -l
      SED  = sed -i ''
   endif
endif

dpuser-parser: y.tab.cpp lex.yy.cpp

#y.tab.cpp: dpuser.y
y.tab.cpp: ast.y
	$(YACC) -d $<
	$(MV) y.tab.c y.tab.cpp

#lex.yy.cpp: dpuser.l
lex.yy.cpp: ast.l
	$(LEX) $<
	$(MV) lex.yy.c lex.yy.cpp
# resolve the isatty problem (only LINUX and MAC)
	$(if $(PLATFORM:WIN=), \
		$(SED) 's/extern int isatty/\/\/extern int isatty/g' lex.yy.cpp \
	)

	$(MV) y.tab.h astParser.h
#	$(CP) astParser.h ..

clean:
	$(RM) y.tab.cpp lex.yy.cpp astParser.h y.tab.c lex.yy.c svn_revision.cpp
