-# Acess2 - ld-acess
+# ld-acess
include $(BASE)header.mk
# Variables
SRCS := main.c lib.c loadlib.c export.c elf.c pe.c
SRCS += arch/$(ARCHDIR).$(ASSUFFIX)
BIN := $(OUTPUTDIR)Libs/ld-acess.so
-XOBJ := $(call fcn_mkobj,_stublib.o)
-XBIN := $(OUTPUTDIR)Libs/libld-acess.so
CFLAGS-$(DIR) := -Wall -fno-builtin -fno-leading-underscore -fno-stack-protector -fPIC -g
CPPFLAGS-$(DIR) := $(CPPFLAGS-$(PDIR))
LDFLAGS-$(DIR) := -g -T $(DIR)/arch/$(ARCHDIR).ld -Map $(call fcn_mkobj,map.txt) --export-dynamic
-OBJ := $(call fcn_src2obj,$(SRCS))
-ALL_OBJ := $(ALL_OBJ) $(OBJ)
-OBJ-$(DIR) := $(OBJ) $(XOBJ)
-BIN-$(DIR) := $(BIN) $(XBIN)
-$(foreach f,$(OBJ) $(XOBJ) $(BIN) $(XBIN),$(eval _DIR-$f := $(DIR)))
+include $(BASE)body.mk
-# Rules
-.PHONY: all-$(DIR) clean-$(DIR)
-
-all-$(DIR): $(BIN-$(DIR))
-clean-$(DIR): clean-%:
- $(eval BIN=$(BIN-$*/))
- $(eval OBJ=$(OBJ-$*/))
- $(RM) $(BIN) $(OBJ)
-
-$(BIN): $(OBJ)
-
-# Stub library
-$(XBIN): $(call fcn_mkobj,_stublib.c.o) $(BIN)
- @echo [LD] -shared -o libld-acess.so
- @$(LD) -shared -o $@ $<
+$(call fcn_addbin, $(OUTPUTDIR)Libs/libld-acess.so, $(call fcn_mkobj,_stublib.c.o))
# Handle preprocessed files
$(DIR)/%: $(DIR)/%.h
# Config Options
SOURCE_DIR =
-OBJECT_DIR = obj-$(ARCH)
+OBJECT_DIR = obj-$(ARCH)/
OBJECT_SUFFIX =
# Functions used later
$(patsubst %,%$(OBJECT_SUFFIX).o,$(filter %.cc,$1)) \
$(patsubst %,%$(OBJECT_SUFFIX).o,$(filter %.S,$1)) \
$(patsubst %,%$(OBJECT_SUFFIX).o,$(filter %.asm,$1))
-fcn_mkobj = $(addprefix $(DIR)$(OBJECT_DIR)/,$(patsubst $(SOURCE_DIR)%,%,$1))
+fcn_mkobj = $(addprefix $(DIR)$(OBJECT_DIR),$(patsubst $(SOURCE_DIR)%,%,$1))
fcn_src2obj = $(call fcn_mkobj, $(call fcn_src2obj_int,$1))
+fcn_obj2src = $(subst $(OBJECT_DIR),$(SOURCE_DIR),$(patsubst %$(OBJECT_SUFFIX).o,%,$1))
+
+fcn_addbin = $(eval ALL_OBJ:=$(ALL_OBJ) $2) $(eval ALL_BIN:=$(ALL_BIN) $1) $(foreach f,$2 $1,$(eval _DIR-$f := $(DIR))) $(eval $1: $2) $(eval OBJ-$(DIR):=$(OBJ-$(DIR)) $2) $(eval BIN-$(DIR):=$(BIN-$(DIR)) $1)
# Start of Voodoo code
SUB_DIRS = $(wildcard */rules.mk)
.PHONY: all clean
-all: $(BASE)obj_rules.mk $(addprefix all-,$(DEFAULT_RULES))
+all: $(addprefix all-,$(DEFAULT_RULES))
clean: $(addprefix clean-,$(DEFAULT_RULES))
# Sub-directory rules
# === Rules ===
-fcn_obj2src = $(subst $(OBJECT_DIR)/,$(SOURCE_DIR)/,$(patsubst %$(OBJECT_SUFFIX).o,%,$1))
# ACESS SPECIFIC
-fcn_getlibs = $(patsubst -l%,$(OUTPUTDIR)/Libs/lib%.so,$(filter -l%,$(LDFLAGS-$(_DIR-$1))))
-
-fcn_mkrule = $(eval $f: $(call fcn_getlibs,$f) $(call fcn_obj2src,$f))
-ifeq (,)
-$(foreach file,$(filter %.cpp$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(call fcn_mkrule,$f))
-$(foreach file,$(filter %.cc$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(call fcn_mkrule,$f))
-$(foreach file,$(filter %.c$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(call fcn_mkrule,$f))
-$(foreach file,$(filter %.S$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(call fcn_mkrule,$f))
-$(foreach file,$(filter %.asm$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(call fcn_mkrule,$f))
-else
-.PHONY: $(BASE)obj_rules.mk
-$(BASE)obj_rules.mk:
- @echo "$(foreach f,$(filter %.cpp$(OBJECT_SUFFIX).o,$(ALL_OBJ)),$f: $(call fcn_obj2src,$f)\n)" > $@
- @echo "$(foreach f,$(filter %.cc$(OBJECT_SUFFIX).o,$(ALL_OBJ)),$f: $(call fcn_obj2src,$f)\n)" >> $@
- @echo "$(foreach f,$(filter %.c$(OBJECT_SUFFIX).o,$(ALL_OBJ)),$f: $(call fcn_obj2src,$f)\n)" >> $@
- @echo "$(foreach f,$(filter %.S$(OBJECT_SUFFIX).o,$(ALL_OBJ)),$f: $(call fcn_obj2src,$f)\n)" >> $@
- @echo "$(foreach f,$(filter %.asm$(OBJECT_SUFFIX).o,$(ALL_OBJ)),$f: $(call fcn_obj2src,$f)\n)" >> $@
-include $(BASE)obj_rules.mk
-endif
+fcn_getlibs = $(patsubst -l%,$(OUTPUTDIR)Libs/lib%.so,$(filter -l%,$(LDFLAGS-$(_DIR-$1))))
+
+fcn_mkrule = $(eval $1: $(call fcn_obj2src,$1))
+$(foreach f,$(filter %.cpp$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(call fcn_mkrule,$f))
+$(foreach f,$(filter %.cc$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(call fcn_mkrule,$f))
+$(foreach f,$(filter %.c$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(call fcn_mkrule,$f))
+$(foreach f,$(filter %.S$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(call fcn_mkrule,$f))
+$(foreach f,$(filter %.asm$(OBJECT_SUFFIX).o,$(ALL_OBJ)), $(call fcn_mkrule,$f))
+$(foreach f,$(ALL_BIN), $(eval $f: $(EXTRA_DEP-$(_DIR-$f)) $(call fcn_getlibs,$f)))
# --- Object Files ---
# C++ (.cpp)
@echo [AS] -o $@
@mkdir -p $(dir $@)
@$(AS) $(ASFLAGS) $(ASFLAGS-$(_dir)) -o $@ $(_src)
# --- Binaries ---
# Static Library (.a)
$(eval _dir=$(_DIR-$@))
@echo [LD] -o $@
@$(LD) $(LDFLAGS) -o $@ $(OBJ-$(_dir)) $(LDFLAGS-$(_dir))
-
+
+-include $(ALL_OBJ:%=%.dep)
+
+%.asm: %.asm.o
+