OBJS_BARE= parse wxmain  radialplot  plotsession

PROGNAME = msplot
CXX=g++
CXXFLAGS = -O3  -Wall -g -Werror -DDEBUGMODE  `wx-config --cxxflags`
LDFLAGS = -g
LIBS=	`wx-config --libs`
LD=g++ $(LDFLAGS)
SCRIPTS=scripts
RM=rm -f
RMDIR=rm -rf
.PHONY: clean depend veryclean fixbuild

OBJS = $(addprefix obj/, $(addsuffix .o, $(OBJS_BARE)))
DEPS = $(addprefix dep/, $(addsuffix .dep, $(OBJS_BARE)))


$(PROGNAME) : $(OBJS)
	$(LD) $(LDFLAGS) $(OBJS) $(LIBS) -o $(PROGNAME)


        
veryclean:
	$(RMDIR) dep obj scripts
	$(RM) $(PROGNAME) core core.* *~ *bkp
        



clean:
	$(RM) $(OBJS) $(DEPS)  $(PROGNAME) core core.* *~ *bkp



fixbuild:
	mkdir -p dep
	mkdir -p obj
	mkdir -p scripts
	#here follows a tcc fixdep script, with main all on one line because I'm too lazy to paste it in the makefile properly
	echo	"#!/usr/bin/tcc -run" > scripts/fixdep.c
	echo	"#include <stdio.h>" >> scripts/fixdep.c
	echo	"int main(int argc, char **argv) { char *prefix = \"obj/\"; if (argc > 1) prefix = argv[1]; fputs(prefix, stdout); int firstChar = -1; int c;        while(1) {              c = getc(stdin);              if (firstChar && c == '#') { while(c !=10 && c != 13  && !feof(stdin))                {                     c = getc(stdin);                }                while((c ==10 || c == 13)  && !feof(stdin))                     c = getc(stdin);              }              if (feof(stdin))                break;              fputc(c, stdout);              if (c == 13 || c == 10)                firstChar = -1;              else                firstChar = 0;        }        return 0; }" >> scripts/fixdep.c
	chmod +x scripts/fixdep.c


depend: $(DEPS)

obj/%.o: %.cpp
	$(CXX) $(CXXFLAGS) -c $< -o $@ 
                                      
dep/%.dep: %.cpp
	$(CXX)  $(CXXFLAGS)  -MM $< | $(SCRIPTS)/fixdep.c > $@


obj/%.o: %.c
	$(CC) $(CFLAGS) -c $< -o $@
                                      
dep/%.dep: %.c
	$(CC)  $(CFLAGS)  -MM $< | $(SCRIPTS)/fixdep.c > $@




-include dep/*.dep
