- libam-riscv32-nemu is working. - libam on platforms other than riscv32-nemu has not been worked on yet. - klib has not been worked on yet.
47 lines
1.6 KiB
Makefile
47 lines
1.6 KiB
Makefile
|
|
# Usage:
|
|
# $(1): Target prefix
|
|
#
|
|
# Generate build rules for files in variable <PREFIX>_SRCS. Use <PREFIX>_CFLAGS,
|
|
# <PREFIX>_CXXFLAGS, <PREFIX>_ASFLAGS to control build flags.
|
|
# E.g:
|
|
# $(eval $(call COMPILE_RULES,AM_))
|
|
define COMPILE_RULES
|
|
AM_OBJS := $(addprefix $(DST_DIR)/, $(addsuffix .o, $(AM_SRCS)))
|
|
### Rule (compile): a single `.c` -> `.c.o` (gcc)
|
|
$$(filter %.c.o, $$($(1)OBJS)): $$(DST_DIR)/%.c.o: %.c
|
|
@mkdir -p $$(dir $$@) && echo + CC $$<
|
|
@$$(CC) $$($(1)CFLAGS) -c -o $$@ $$(realpath $$<)
|
|
|
|
### Rule (compile): a single `.cc` -> `.cc.o` (g++)
|
|
$$(filter %.cc.o, $$($(1)OBJS)): $$(DST_DIR)/%.cc.o: %.cc
|
|
@mkdir -p $$(dir $$@) && echo + CXX $$<
|
|
@$$(CXX) $$($(1)CXXFLAGS) -c -o $$@ $$(realpath $$<)
|
|
|
|
### Rule (compile): a single `.cpp` -> `.cpp.o` (g++)
|
|
$$(filter %.cpp.o, $$($(1)OBJS)): $$(DST_DIR)/%.cpp.o: %.cpp
|
|
@mkdir -p $$(dir $$@) && echo + CXX $$<
|
|
@$$(CXX) $$($(1)CXXFLAGS) -c -o $$@ $$(realpath $$<)
|
|
|
|
### Rule (compile): a single `.S` -> `.S.o` (gcc, which preprocesses and calls as)
|
|
$$(filter %.S.o, $$($(1)OBJS)): $$(DST_DIR)/%.S.o: %.S
|
|
@mkdir -p $$(dir $$@) && echo + AS $$<
|
|
@$$(AS) $$($(1)ASFLAGS) -c -o $$@ $$(realpath $$<)
|
|
|
|
### Rule (`#include` dependencies): paste in `.d` files generated by gcc on `-MMD`
|
|
-include $$(addprefix $$(DST_DIR)/, $$(addsuffix .d, $$(filter %.c %.cc, $$(AM_SRCS))))
|
|
endef
|
|
|
|
# Usage:
|
|
# $(1): Library name
|
|
# $(2): Library variable prefix
|
|
# E.g:
|
|
# $(eval $(call ADD_LIBRARY,am-riscv,AM_))
|
|
define ADD_LIBRARY
|
|
$(eval $(call COMPILE_RULES,$(2)))
|
|
$(1): $$($(2)OBJS)
|
|
@mkdir -p $$(dir $$@)
|
|
@echo + AR "->" $$(patsubst $$(CURDIR)/%,%,$(1))
|
|
@$$(AR) rcs $$@ $$($(2)OBJS)
|
|
endef
|
|
|