all: engine engine_wrapper.a

GENERATED_OBJECTS=system/accept_estimates.o \
		    system/init_t1.o \
		    system/build_jacobian.o \
		    system/init_variables.o \
		    system/update_estimate_derivatives.o \
		    system/compute_line_flows.o \
		    system/insert_remove_line.o \
		    system/update_estimates.o \
		    system/compute_mismatches.o \
		    system/variables.o

GENERATED_FUNCTIONS=$(GENERATED_OBJECTS:.c=.o)


INCLUDE=-I.
LINKOBJECTS=
include MakeDirectives

USE_UMF=0

ifeq ($(USE_UMF),1)
  INCLUDE += -I UMFPACKv4.4/UMFPACK/Include/
  LINK += -L UMFPACKv4.4/AMD/Lib/ -L UMFPACKv4.4/UMFPACK/Lib/ \
        -L UMFPACKv4.4/BLAS/ -lumfpack -lamd -lgoto -lpthread -lxerbla
else
  GENERATED_OBJECTS += system/solve_lu.o 
  LINK += -static
endif

#CC = icc
#CCFLAGS = -xN -O3 -align -g -debug
#CCFLAGS = -xN -O3 -g -noalign -debug
#LINK+=-svml  # Short Vector Math Library

#Warning: Compiling with gcc will result in a simulation that fails to run
#in real-time.  You have been warned.
CC = gcc
CCFLAGS = -g -O3 -Wall
LINK+=-lm

.c.o:
	if [ -e system ] && [ ! -L system ]; then echo "system is not a link"; exit 1; fi
	$(CC) -c $(CCFLAGS) $(INCLUDE) $< -o $@

engine_functions.o: engine_functions.c engine.h

engine_wrapper.o: engine_wrapper.c engine_wrapper.h engine.h engine_debug.h

engine: $(GENERATED_OBJECTS) $(LINKOBJECTS) engine.o engine_functions.o engine_debug.o engine_wrapper.o
	$(CC) $^ -o $@  $(LINK)

engine_wrapper.a: $(GENERATED_OBJECTS) $(LINKOBJECTS) engine_wrapper.o engine_functions.o engine_debug.o
	$(AR) cruv $@ $^

clean:
	rm -f *.o *.a *~ engine engine_test *.o system/*.o

superclean:
	rm -f *.o *.a *~ engine engine_test *.o system/*.o system/*.c system/matlab/*.m system/matlab/*.txt

