-include ../../../../Rules.make
export PATH=/bin:/sbin:/usr/bin:$(SDK_PATH_TARGET)/usr/bin:$PATH

#define library variable
Internal485ProtocolLib = -L ../../../Modularization/Internal485Protocol -lInternal485Protocol
#PsuCommProtocolLib = -L ../../../Modularization/PsuCommProtocol -lPsuCommProtocol

all: CopyFile apps
#apps: Module_CSU Module_EvComm Module_EventLogging Module_InternalComm Module_LcmControl Module_PrimaryComm Module_PsuComm 
# ReadCmdline kill.sh
apps: MainTask EvCommTask EventLoggingTask InternalCommTask LcmControlTask PrimaryCommTask PsuCommTask ReadCmdlineTask WebService 4GTask ModbusTask FactoryConfigApp OtherTools

MainTask:
	rm -f *.o
	rm -f main;
	$(CC) -D $(Project) -include../../../Modularization/Module_RFID.h -O0 -g3 -Wall -c -fmessage-length=0 -o main.o main.c
	$(CC) -D $(Project) -include../../../Modularization/Module_RFID.h -O0 -g3 -Wall -c -fmessage-length=0 -o timeout.o timeout.c
	$(CC) -o main main.o timeout.o ../../../Modularization/libModule_RFID.a ../../../Modularization/libModule_Upgrade.a	
	cp -f main ../Images/root

EvCommTask:
	rm -f Module_EvComm;
	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Ev_Comm.o Ev_Comm.c
	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_EvComm.o Module_EvComm.c
	$(CC) -o Module_EvComm Ev_Comm.o Module_EvComm.o
	cp -f Module_EvComm ../Images/root	
	
EventLoggingTask:
	rm -f Module_EventLogging;
	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_EventLogging.o Module_EventLogging.c
	$(CC) -o Module_EventLogging Module_EventLogging.o 	
	cp -f Module_EventLogging ../Images/root	
	
InternalCommTask:
	rm -f Module_InternalComm; 
	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o internalComm.o internalComm.c
	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_InternalComm.o Module_InternalComm.c
	$(CC) -o Module_InternalComm Module_InternalComm.o internalComm.o 	
	cp -f Module_InternalComm ../Images/root
	
LcmControlTask:
	rm -f Module_LcmControl; 
	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_LcmControl.o Module_LcmControl.c
	$(CC) -o Module_LcmControl Module_LcmControl.o
	cp -f Module_LcmControl ../Images/root			

PrimaryCommTask:
	rm -f Module_PrimaryComm; 
	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_PrimaryComm.o Module_PrimaryComm.c
	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o PrimaryComm.o PrimaryComm.c
	$(CC) -o Module_PrimaryComm Module_PrimaryComm.o PrimaryComm.o
	cp -f Module_PrimaryComm ../Images/root	

PsuCommTask:
	rm -f Module_PsuComm; 
	$(CC) -D $(Project) -include../../../Modularization/Infypwr_PsuCommObj.h -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_PsuComm.o Module_PsuComm.c
	$(CC) -o Module_PsuComm Module_PsuComm.o ../../../Modularization/libInfypwr_PsuCommObj.a
	cp -f Module_PsuComm ../Images/root	

ModbusTask:
	rm -f Module_Modbus; 
	$(CC) -D $(Project) -I../../../rootfs/include/modbus -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o Module_Modbus.o Module_Modbus.c
	$(CC) -L../../../rootfs/lib -o Module_Modbus Module_Modbus.o -lmodbus
	cp -f Module_Modbus ../Images/root

ReadCmdlineTask:
	rm -f ReadCmdline; 
	$(CC) -D $(Project) -includeConfig.h -O0 -g3 -Wall -c -fmessage-length=0 -o ReadCmdline.o ReadCmdline.c
	$(CC) -o ReadCmdline ReadCmdline.o
	cp -f ReadCmdline ../Images/root

FactoryConfigApp:
	@echo "===== Module_FactoryConfig_Task =================================="
	rm -f FactoryConfig
	gcc -D $(Project) "-I../../" -o FactoryConfig "./FactoryConfig.c"
	mkdir -p /Storage/SystemLog	
	./FactoryConfig -f;true
	cp /mnt/FactoryDefaultConfig.bin ../Images
	rm -f FactoryConfig; 
	$(CC) -D $(Project) -O0 -g3 -Wall -c -fmessage-length=0 -o FactoryConfig.o FactoryConfig.c 
	$(CC) -o FactoryConfig FactoryConfig.o 
	cp -f FactoryConfig ../Images/root

WebService:
	cp -f ../../../Modularization/WebService ../Images/root

4GTask:
	cp -f ../../../Modularization/Module_4g ../Images/root

OtherTools:
	cp -f init.sh ../Images/root
	cp -f kill.sh ../Images/root

CopyFile: 
	rm -rfv ../Images/root
	mkdir -p ../Images/root