LD		= gcc
CC      	= gcc
AS		= gcc
RM		= rm -f
ARFLAGS 	= -rcs
INCLUDE		= $(patsubst %,-I%,$(subst :, ,$(PCBAC_INCLUDE)))
LIBS_PATH	= $(patsubst %,-L%,$(subst :, ,$(PCBAC_RESOURCES)))
CFLAGS		= -O0 -g -std=c99 -W 
LIBS		= -lelf
OBJECTS 	= main.o		\
			string_table.o	\
			symbol.o	\
			relocation.o	\
			list.o		\
			section.o	\
			spm.o		\
			protected_got.o	\
			ld.o		\
			elf_file.o	\
			assertion.o	
OUTPUT		= pcbac-x86_64-fides-ld

.SILENT:
all: $(OUTPUT)

$(OUTPUT): $(OBJECTS)
	echo "			[LD] " $(OBJECTS) 
	$(LD) $(OBJECTS) $(LIBS_PATH) $(LIBS) -o $(OUTPUT)

%.o : %.c
	echo "			[CC] " $(CC) $(CFLAGS) -c $< 
	$(CC) $(CFLAGS) $(INCLUDE) -c $<

.PHONY: test
test:	$(OUTPUT)
	echo "			[RUN] ./$(OUTPUT) caesar.spmo -o output.spm"
	./$(OUTPUT) caesar.spmo --output output.spm --name caesar --stack-size 512 --heap-size 256

.PHONY: scrub
scrub:  $(SCRUBDIRS)
	echo "			[RM] output.spm"
	$(RM) output.spm
	#echo "[   scrubbing   ]"

.PHONY: configure
configure: $(CONFIGDIRS)
	#echo "[   configuring   ]"
	
.PHONY: install
install:  $(INSTALLDIRS)
	#echo "[   installing   ]"

.PHONY: uninstall
uninstall: $(UNINSTALLDIRS)
	#echo "[   uninstalling   ]"

.PHONY: clean
clean:
	echo "			[RM]" $(OUTPUT) $(OBJECTS)
	$(RM) $(OUTPUT) $(OBJECTS)

