# - Application Template Makefile
#
-CFLAGS += -Wall -Werror -fno-builtin -fno-stack-protector -g
-LDFLAGS +=
+CFLAGS += -g
+LDFLAGS += -g
+
+LDFLAGS += -Map $(_OBJPREFIX)Map.txt
+
+ifneq ($(lastword $(subst -, ,$(basename $(LD)))),ld)
+ comma=,
+ LDFLAGS := $(subst -rpath-link ,-Wl$(comma)-rpath-link$(comma),$(LDFLAGS))
+ LDFLAGS := $(subst -Map ,-Wl$(comma)-Map$(comma),$(LDFLAGS))
+endif
_BIN := $(OUTPUTDIR)$(DIR)/$(BIN)
_OBJPREFIX := obj-$(ARCH)/
_LIBS := $(filter -l%,$(LDFLAGS))
_LIBS := $(patsubst -l%,$(OUTPUTDIR)Libs/lib%.so,$(_LIBS))
+ifeq ($(VERBOSE),)
+V := @
+else
+V :=
+endif
+
OBJ := $(addprefix $(_OBJPREFIX),$(OBJ))
DEPFILES := $(OBJ:%.o=%.dep)
$(_BIN): $(OUTPUTDIR)Libs/acess.ld $(OUTPUTDIR)Libs/crt0.o $(_LIBS) $(OBJ)
@mkdir -p $(dir $(_BIN))
@echo [LD] -o $@
-ifneq ($(_DBGMAKEFILE),)
- $(LD) -g $(LDFLAGS) -o $@ $(OBJ) -Map $(_OBJPREFIX)Map.txt
-else
- @$(LD) -g $(LDFLAGS) -o $@ $(OBJ) -Map $(_OBJPREFIX)Map.txt
-endif
- @$(DISASM) $(_BIN) > $(BIN).dsm
+ $V$(LD) -g $(LDFLAGS) -o $@ $(CRTBEGIN) $(OBJ) $(LIBGCC_PATH) $(CRTEND)
+ $V$(DISASM) $(_BIN) > $(_OBJPREFIX)$(BIN).dsm
-$(OBJ): $(_OBJPREFIX)%.o: %.c
+$(_OBJPREFIX)%.o: %.c
@echo [CC] -o $@
ifneq ($(_OBJPREFIX),)
- @mkdir -p $(_OBJPREFIX)
+ @mkdir -p $(dir $@)
+endif
+ $V$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ -MQ $@ -MP -MD -MF $(_OBJPREFIX)$*.dep
+
+$(_OBJPREFIX)%.o: %.cpp
+ @echo [CXX] -o $@
+ifneq ($(_OBJPREFIX),)
+ @mkdir -p $(dir $@)
endif
- @$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
- @$(CC) -M -MT $@ $(CPPFLAGS) $< -o $(_OBJPREFIX)$*.dep
+ $V$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@ -MQ $@ -MP -MD -MF $(_OBJPREFIX)$*.dep
$(OUTPUTDIR)Libs/libld-acess.so:
@make -C $(ACESSDIR)/Usermode/Libraries/ld-acess.so_src/
@make -C $(ACESSDIR)/Usermode/Libraries/$*_src/
-include $(DEPFILES)
+
+# vim: ft=make