XDIRS			= /usr/X11/lib
XLIBS			= X11
OBJ			= ./obj
COMMUNICATION_LIB	= ../communication/communication.a
COMMUNICATION_INCLUDE	= ../communication/include
MATRIX_LIB		= ../matrix/matrix.a
MATRIX_INCLUDE		= ../matrix/include
MAIN_INCLUDE		= ../include
LIBS			= $(COMMUNICATION_LIB) $(MATRIX_LIB) -lm
TARGET			= bemmel
IDIRS			= -I. -I../include\
			  -I$(MATRIX_INCLUDE) -I$(COMMUNICATION_INCLUDE)
COMPILER		= gcc
REAL_TYPE		= double
CFLAGS			= -O $(IDIRS) -DREAL=$(REAL_TYPE)
CC			= $(COMPILER) $(CFLAGS)

CFILES=\
	communication.c\
	compute.c\
	datastruct.c\
	input.c\
	main.c\
	xgraphics.c

OBJECTS=\
	$(OBJ)/communication.o\
	$(OBJ)/compute.o\
	$(OBJ)/datastruct.o\
	$(OBJ)/input.o\
	$(OBJ)/main.o\
	$(OBJ)/xgraphics.o

$(TARGET)1: $(OBJECTS) $(COMMUNICATION_LIB) $(MATRIX_LIB)
	$(CC) $(CFLAGS) -o $(TARGET)1 $(OBJECTS) $(LIBS)\
			 -L$(XDIRS) -l$(XLIBS)
	rm -f $(TARGET)2
	ln $(TARGET)1 $(TARGET)2

communication.h: $(MATRIX_INCLUDE)/matrix.h
	@touch communication.h

datastruct.h: $(MATRIX_INCLUDE)/matrix.h
	@touch datastruct.h

compute.h: $(MATRIX_INCLUDE)/matrix.h
	@touch compute.h

$(OBJ)/communication.o: communication.c communication.h \
	$(MAIN_INCLUDE)/global_communication.h datastruct.h \
	$(MAIN_INCLUDE)/setup.h xgraphics.h Makefile
	$(CC) -c -g $(CFLAGS) -o $(OBJ)/communication.o communication.c

$(OBJ)/compute.o: compute.c compute.h datastruct.h main.h xgraphics.h \
	$(MATRIX_INCLUDE)/matrix.h $(MAIN_INCLUDE)/setup.h Makefile
	$(CC) -c -g $(CFLAGS) -o $(OBJ)/compute.o compute.c

$(OBJ)/datastruct.o: datastruct.c datastruct.h main.h \
	$(MATRIX_INCLUDE)/matrix.h $(MAIN_INCLUDE)/setup.h Makefile
	$(CC) -c -g $(CFLAGS) -o $(OBJ)/datastruct.o datastruct.c

$(OBJ)/input.o: input.c input.h datastruct.h  \
	$(MATRIX_INCLUDE)/matrix.h $(MAIN_INCLUDE)/setup.h Makefile
	$(CC) -c -g $(CFLAGS) -o $(OBJ)/input.o input.c

$(OBJ)/main.o: main.c main.h input.h compute.h communication.h \
	$(MAIN_INCLUDE)/setup.h Makefile
	$(CC) -c -g $(CFLAGS) -o $(OBJ)/main.o main.c

$(OBJ)/xgraphics.o: xgraphics.c xgraphics.h main.h datastruct.h \
	$(MATRIX_INCLUDE)/matrix.h $(MAIN_INCLUDE)/setup.h Makefile
	$(CC) -c -g $(CFLAGS) -o $(OBJ)/xgraphics.o xgraphics.c

all: $(TARGET)1

clean:
	rm -f $(OBJECTS)

clear:
	rm -f $(OBJECTS) $(TARGET)?
