## Code generation directories for both projects
SENDER_CCG_DIR=../SenderProject/ccg_unix
RECEIVER_CCG_DIR=../ReceiverProject/ccg_unix

## Directory from where the common files will be copied; can be the code generation
## directory from any of the two projects: the files will be identical in both
COMMON_CCG_DIR=$(SENDER_CCG_DIR)

## Directory for common files
LIB_DIR=../common

## Directories where to find RTDS required include files
RTDS_TEMPLATES_DIR=$(LIB_DIR)/profile
RTDS_COMMON_DIR=${RTDS_HOME}/share/ccg/common
RTDS_SCHEDULER_DIR=${RTDS_HOME}/share/ccg/cscheduler

CC_OPTIONS=-g -I. -I$(RTDS_COMMON_DIR) -I$(RTDS_TEMPLATES_DIR) -I$(RTDS_SCHEDULER_DIR) -I$(LIB_DIR) -DRTDS_NO_SCHEDULER


## Required object files: the ones for the 2 processes + common files
OBJECT_FILES = \
	pSender.o \
	pReceiver.o \
	RTDS_String.o \
	RTDS_Proc.o \
	trace_procedure.o \
	common.o

	
COMMON_INCLUDES = \
	$(LIB_DIR)/common.h \
	Signals.h \
	RTDS_all_processes.h \
	RTDS_gen.h \
	RTDS_String.h \
	RTDS_Set.h \
	sSender.h \
	sReceiver.h \
	pSender.h \
	pReceiver.h \
	pSender_locals.h \
	pReceiver_locals.h \
	RTDS_SenderProject_messages.h \
	RTDS_ReceiverProject_messages.h

SENDER_INCLUDES=pSender_decl.h pSender_tmpvars.h
RECEIVER_INCLUDES=pReceiver_decl.h pReceiver_tmpvars.h

all: whole_system

whole_system: $(OBJECT_FILES)
	gcc -o "$@" $(OBJECT_FILES)

pSender.o: pSender.c $(COMMON_INCLUDES) $(SENDER_INCLUDES)
	gcc $(CC_OPTIONS) -c -o "$@" "$<"

pReceiver.o: pReceiver.c $(COMMON_INCLUDES) $(RECEIVER_INCLUDES)
	gcc $(CC_OPTIONS) -c -o "$@" "$<"

RTDS_String.o: RTDS_String.c
	gcc $(CC_OPTIONS) -c -o "$@" "$<"

RTDS_Proc.o: $(RTDS_SCHEDULER_DIR)/RTDS_Proc.c
	gcc $(CC_OPTIONS) -c -o "$@" "$<"

trace_procedure.o: $(LIB_DIR)/trace_procedure.c sSender.h
	gcc $(CC_OPTIONS) -c -o "$@" "$<"

common.o: $(LIB_DIR)/common.c $(COMMON_INCLUDES)
	gcc $(CC_OPTIONS) -c -o "$@" "$<"


## All files from SenderProject have to be copied from its code generation directory
pSender.c: $(SENDER_CCG_DIR)/pSender.c
	cp $< $@
pSender.h: $(SENDER_CCG_DIR)/pSender.h
	cp $< $@
pSender_decl.h: $(SENDER_CCG_DIR)/pSender_decl.h
	cp $< $@
pSender_locals.h: $(SENDER_CCG_DIR)/pSender_locals.h
	cp $< $@
pSender_tmpvars.h: $(SENDER_CCG_DIR)/pSender_tmpvars.h
	cp $< $@
sSender.h: $(SENDER_CCG_DIR)/sSender.h
	cp $< $@
RTDS_SenderProject_messages.h: $(SENDER_CCG_DIR)/RTDS_SenderProject_messages.h
	cp $< $@

## All files from ReceiverProject have to be copied from its code generation directory
pReceiver.c: $(RECEIVER_CCG_DIR)/pReceiver.c
	cp $< $@
pReceiver.h: $(RECEIVER_CCG_DIR)/pReceiver.h
	cp $< $@
pReceiver_decl.h: $(RECEIVER_CCG_DIR)/pReceiver_decl.h
	cp $< $@
pReceiver_locals.h: $(RECEIVER_CCG_DIR)/pReceiver_locals.h
	cp $< $@
pReceiver_tmpvars.h: $(RECEIVER_CCG_DIR)/pReceiver_tmpvars.h
	cp $< $@
sReceiver.h: $(RECEIVER_CCG_DIR)/sReceiver.h
	cp $< $@
RTDS_ReceiverProject_messages.h: $(RECEIVER_CCG_DIR)/RTDS_ReceiverProject_messages.h
	cp $< $@

## All common files can be copied from either sender or receiver project code generation directory
Signals.h: $(COMMON_CCG_DIR)/Signals.h
	cp $< $@
RTDS_all_processes.h: $(COMMON_CCG_DIR)/RTDS_all_processes.h
	cp $< $@
RTDS_gen.h: $(COMMON_CCG_DIR)/RTDS_gen.h
	cp $< $@
RTDS_String.h: $(COMMON_CCG_DIR)/RTDS_String.h
	cp $< $@
RTDS_String.c: $(COMMON_CCG_DIR)/RTDS_String.c
	cp $< $@
RTDS_Set.h: $(COMMON_CCG_DIR)/RTDS_Set.h
	cp $< $@
