fxBoot/tests/Makefile

102 lines
1.7 KiB
Makefile

#!/usr/bin/make -f
## ---
## Project: PIE executable
## Author: yann.magnin@epitech.eu
## ---
##---
## Static variables
##--
HEADER := -I./include
NAME := test
EXEC := $(NAME).elf
LDFLAG := -T $(NAME).ld
MEMORY_MAP := $(NAME).map
BUILD := build
# Tools
COMPILER := sh-elf-
CC := $(COMPILER)gcc
LD := $(COMPILER)ld
OBJCOPY := $(COMPILER)objcopy
OBJDUMP := $(COMPILER)objdump
WRAPPER := g1a-wrapper
# Flags
CFLAGS := -Werror -Wall -W -Wextra -std=c18 -m3 -mb -mrenesas \
-ffreestanding -nostdlib -fstrict-volatile-bitfields \
-Wno-unused-const-variable -Wno-unused-function \
-Wno-unused-variable -Wno-unused-but-set-variable \
-Wno-unused-parameter -Wno-pointer-to-int-cast
# Colors
red := \033[1;31m
green := \033[1;32m
blue := \033[1;34m
white := \033[1;37m
nocolor := \033[1;0m
##---
## Automated variables
##---
SRC := $(wildcard src/*.[csS])
OBJ := $(patsubst %,$(BUILD)/%.o,\
$(subst /,_,$(subst src/,,$(basename $(SRC)))))
##---
## General rules
##---
all: $(EXEC)
$(EXEC): $(OBJ) | $(DEBUG)
$(CC) -pie -Wl,-M $(LDFLAG) $(CFLAGS) -o $@ $(OBJ) $(HEADER) > $(MEMORY_MAP)
check:
@ echo 'src: $(SRC)'
@ echo 'obj: $(OBJ)'
$(BUILD):
mkdir -p $@
##---
## Automated rules
##---
define rule-src
$(patsubst %,$(BUILD)/%.o,$(subst /,_,$(subst src/,,$(basename $1)))): $1 | $(BUILD)
@ printf "compiling $(white)$$<$(nocolor)..."
@ $(CC) -pie -DFXCG50 $(CFLAGS) -o $$@ -c $$< $(HEADER) -lgcc
@ printf "$(green)[ok]$(nocolor)\n"
endef
$(foreach source,$(SRC),$(eval \
$(call rule-src,$(source))) \
)
##---
## Cleaning rules
##---
clean:
rm -rf $(BUILD)
fclean: clean
rm -f $(EXEC)
re: fclean all
.PHONY: re fclean clean all install