64 lines
1.2 KiB
Makefile
64 lines
1.2 KiB
Makefile
# Stand-alone directories used to fetch source files and create object
|
|
# files.
|
|
|
|
SRC_DIR := src/
|
|
ASM_DIR := asm/
|
|
OBJ_DIR := obj
|
|
LOBJ_DIR := lobj
|
|
|
|
# Directory where library interfaces are kept.
|
|
|
|
INC_DIR := ../include/
|
|
|
|
# Final object file created by this library. It will have the same name
|
|
# as the library directory.
|
|
|
|
LIB_NAME = $(notdir $(shell pwd))
|
|
LIB_OBJ := $(LOBJ_DIR)/$(LIB_NAME).o
|
|
|
|
# C and assembly source code files.
|
|
|
|
SRC := $(wildcard $(SRC_DIR)/*.c)
|
|
ASM := $(wildcard $(ASM_DIR)/*.s)
|
|
|
|
# Objects created from source files.
|
|
|
|
OBJ := $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
|
|
OBJ += $(ASM:$(ASM_DIR)/%.s=$(OBJ_DIR)/%.o)
|
|
|
|
# Compiler settings.
|
|
|
|
CFLAGS+=-c
|
|
HFLAGS = -MMD
|
|
|
|
# Linker settings.
|
|
|
|
LDFLAGS = -r -nostdlib -ffreestanding -lgcc
|
|
|
|
# Include flags.
|
|
|
|
INCFLAGS := $(foreach TMP, $(INC_DIR), -I$(TMP))
|
|
|
|
.PHONY: all clean
|
|
|
|
# Start of rules.
|
|
|
|
all: $(LIB_OBJ)
|
|
|
|
$(LIB_OBJ): $(OBJ) | $(LOBJ_DIR)
|
|
$(CC) $(OBJ) -o $@ $(LDFLAGS)
|
|
|
|
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
|
|
$(CC) $< -o $@ $(CFLAGS) $(HFLAGS) $(INCFLAGS)
|
|
|
|
$(OBJ_DIR)/%.o: $(ASM_DIR)/%.s | $(OBJ_DIR)
|
|
$(CC) $< -o $@ $(CFLAGS) $(HFLAGS) $(INCFLAGS)
|
|
|
|
$(LOBJ_DIR) $(OBJ_DIR):
|
|
mkdir -p $@
|
|
|
|
clean:
|
|
@$(RM) -rv $(LOBJ_DIR) $(OBJ_DIR)
|
|
|
|
-include $(OBJ:.o=.d)
|