common.mk 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. AR = $(PREFIX)ar
  2. AS = $(PREFIX)as
  3. CC = $(PREFIX)gcc
  4. CXX = $(PREFIX)g++
  5. LD = $(PREFIX)ld
  6. OBJCOPY = $(PREFIX)objcopy
  7. RANLIB = $(PREFIX)ranlib
  8. STRIP = $(PREFIX)strip
  9. BIN2S = $(DEVKITPPC)/bin/bin2s
  10. ifeq ($(NOMAPFILE),)
  11. LDFLAGS += -Wl,-Map,$(TARGET).map
  12. endif
  13. ifneq ($(LDSCRIPT),)
  14. LDFLAGS += -Wl,-T$(LDSCRIPT)
  15. endif
  16. DEPDIR = .deps
  17. all: $(TARGET)
  18. $(TARGET): $(OBJS)
  19. @echo " LINK $@"
  20. @$(CC) $(LDFLAGS) $(OBJS) $(LIBS) -o $@
  21. ifneq ($(LDSCRIPT),)
  22. $(TARGET): $(LDSCRIPT)
  23. endif
  24. %.o: %.c
  25. @echo " COMPILE $<"
  26. @mkdir -p $(DEPDIR)
  27. @$(CC) $(CFLAGS) $(DEFINES) -Wp,-MMD,$(DEPDIR)/$(*F).d,-MQ,"$@",-MP -c $< -o $@
  28. %.o: %.s
  29. @echo " ASSEMBLE $<"
  30. @$(CC) $(CFLAGS) $(DEFINES) $(ASFLAGS) -c $< -o $@
  31. %.o: %.S
  32. @echo " ASSEMBLE $<"
  33. @$(CC) $(CFLAGS) $(DEFINES) $(ASFLAGS) -c $< -o $@
  34. clean:
  35. rm -rf $(DEPDIR)
  36. rm -f $(TARGET) $(TARGET).map $(OBJS)
  37. define bin2o
  38. @echo " BIN2S $(notdir $<)"
  39. @$(BIN2S) -a 32 $< | $(AS) -o $(@)
  40. @echo "extern const u8" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(<F) | tr . _)`.h
  41. @echo "extern const u8" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(<F) | tr . _)`.h
  42. @echo "extern const u32" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(<F) | tr . _)`.h
  43. endef
  44. -include $(DEPDIR)/*
  45. .PHONY: clean