Makefile 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. #---------------------------------------------------------------------------------
  2. .SUFFIXES:
  3. #---------------------------------------------------------------------------------
  4. ifeq ($(strip $(DEVKITPRO)),)
  5. $(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
  6. endif
  7. TOPDIR ?= $(CURDIR)
  8. include $(DEVKITPRO)/libnx/switch_rules
  9. #---------------------------------------------------------------------------------
  10. # TARGET is the name of the output
  11. # BUILD is the directory where object files & intermediate files will be placed
  12. # SOURCES is a list of directories containing source code
  13. # DATA is a list of directories containing data files
  14. # INCLUDES is a list of directories containing header files
  15. # ROMFS is the directory containing data to be added to RomFS, relative to the Makefile (Optional)
  16. #
  17. # NO_ICON: if set to anything, do not use icon.
  18. # NO_NACP: if set to anything, no .nacp file is generated.
  19. # APP_TITLE is the name of the app stored in the .nacp file (Optional)
  20. # APP_AUTHOR is the author of the app stored in the .nacp file (Optional)
  21. # APP_VERSION is the version of the app stored in the .nacp file (Optional)
  22. # APP_TITLEID is the titleID of the app stored in the .nacp file (Optional)
  23. # ICON is the filename of the icon (.jpg), relative to the project folder.
  24. # If not set, it attempts to use one of the following (in this order):
  25. # - <Project name>.jpg
  26. # - icon.jpg
  27. # - <libnx folder>/default_icon.jpg
  28. #
  29. # CONFIG_JSON is the filename of the NPDM config file (.json), relative to the project folder.
  30. # If not set, it attempts to use one of the following (in this order):
  31. # - <Project name>.json
  32. # - config.json
  33. # If a JSON file is provided or autodetected, an ExeFS PFS0 (.nsp) is built instead
  34. # of a homebrew executable (.nro). This is intended to be used for sysmodules.
  35. # NACP building is skipped as well.
  36. #---------------------------------------------------------------------------------
  37. APP_TITLE := MEGAHAKUS
  38. APP_VERSION := 2.4.0
  39. TARGET := $(notdir $(CURDIR))
  40. BUILD := build
  41. SOURCES := source Atmosphere-libs/libstratosphere/source/dmnt
  42. DATA := data
  43. INCLUDES := include libs/libtesla/include Atmosphere-libs/libstratosphere/source/dmnt
  44. NO_ICON := 1
  45. #---------------------------------------------------------------------------------
  46. # options for code generation
  47. #---------------------------------------------------------------------------------
  48. ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE
  49. CFLAGS := -g -Wall -ffunction-sections \
  50. $(ARCH) $(DEFINES)
  51. CFLAGS += $(INCLUDE) -D__SWITCH__
  52. CXXFLAGS := $(CFLAGS) -fno-exceptions -std=c++17 -fpermissive -O3
  53. ASFLAGS := -g $(ARCH)
  54. LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
  55. LIBS := -lnx
  56. #---------------------------------------------------------------------------------
  57. # list of directories containing libraries, this must be the top level containing
  58. # include and lib
  59. #---------------------------------------------------------------------------------
  60. LIBDIRS := $(PORTLIBS) $(LIBNX)
  61. #---------------------------------------------------------------------------------
  62. # no real need to edit anything past this point unless you need to add additional
  63. # rules for different file extensions
  64. #---------------------------------------------------------------------------------
  65. ifneq ($(BUILD),$(notdir $(CURDIR)))
  66. #---------------------------------------------------------------------------------
  67. export OUTPUT := $(CURDIR)/$(TARGET)
  68. export TOPDIR := $(CURDIR)
  69. export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
  70. $(foreach dir,$(DATA),$(CURDIR)/$(dir))
  71. export DEPSDIR := $(CURDIR)/$(BUILD)
  72. CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
  73. CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
  74. SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
  75. BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
  76. #---------------------------------------------------------------------------------
  77. # use CXX for linking C++ projects, CC for standard C
  78. #---------------------------------------------------------------------------------
  79. ifeq ($(strip $(CPPFILES)),)
  80. #---------------------------------------------------------------------------------
  81. export LD := $(CC)
  82. #---------------------------------------------------------------------------------
  83. else
  84. #---------------------------------------------------------------------------------
  85. export LD := $(CXX)
  86. #---------------------------------------------------------------------------------
  87. endif
  88. #---------------------------------------------------------------------------------
  89. export OFILES_BIN := $(addsuffix .o,$(BINFILES))
  90. export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
  91. export OFILES := $(OFILES_BIN) $(OFILES_SRC)
  92. export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
  93. export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
  94. $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
  95. -I$(CURDIR)/$(BUILD)
  96. export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
  97. ifeq ($(strip $(CONFIG_JSON)),)
  98. jsons := $(wildcard *.json)
  99. ifneq (,$(findstring $(TARGET).json,$(jsons)))
  100. export APP_JSON := $(TOPDIR)/$(TARGET).json
  101. else
  102. ifneq (,$(findstring config.json,$(jsons)))
  103. export APP_JSON := $(TOPDIR)/config.json
  104. endif
  105. endif
  106. else
  107. export APP_JSON := $(TOPDIR)/$(CONFIG_JSON)
  108. endif
  109. ifeq ($(strip $(ICON)),)
  110. icons := $(wildcard *.jpg)
  111. ifneq (,$(findstring $(TARGET).jpg,$(icons)))
  112. export APP_ICON := $(TOPDIR)/$(TARGET).jpg
  113. else
  114. ifneq (,$(findstring icon.jpg,$(icons)))
  115. export APP_ICON := $(TOPDIR)/icon.jpg
  116. endif
  117. endif
  118. else
  119. export APP_ICON := $(TOPDIR)/$(ICON)
  120. endif
  121. ifeq ($(strip $(NO_ICON)),)
  122. export NROFLAGS += --icon=$(APP_ICON)
  123. endif
  124. ifeq ($(strip $(NO_NACP)),)
  125. export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp
  126. endif
  127. ifneq ($(APP_TITLEID),)
  128. export NACPFLAGS += --titleid=$(APP_TITLEID)
  129. endif
  130. ifneq ($(ROMFS),)
  131. export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS)
  132. endif
  133. .PHONY: $(BUILD) clean all
  134. #---------------------------------------------------------------------------------
  135. all: $(BUILD)
  136. $(BUILD):
  137. @[ -d $@ ] || mkdir -p $@
  138. @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
  139. #---------------------------------------------------------------------------------
  140. clean:
  141. @rm -fr $(BUILD) $(TARGET).ovl $(TARGET).nro $(TARGET).nacp $(TARGET).elf
  142. #---------------------------------------------------------------------------------
  143. else
  144. .PHONY: all
  145. DEPENDS := $(OFILES:.o=.d)
  146. DEPENDS += Atmosphere-libs//libstratosphere/release:.o=.d
  147. #---------------------------------------------------------------------------------
  148. # main targets
  149. #---------------------------------------------------------------------------------
  150. all : $(OUTPUT).ovl
  151. $(OUTPUT).ovl : $(OUTPUT).elf $(OUTPUT).nacp
  152. @elf2nro $< $@ $(NROFLAGS)
  153. @echo "built ... $(notdir $(OUTPUT).ovl)"
  154. $(OUTPUT).elf : $(OFILES)
  155. $(OFILES_SRC) : $(HFILES_BIN)
  156. #---------------------------------------------------------------------------------
  157. # you need a rule like this for each extension you use as binary data
  158. #---------------------------------------------------------------------------------
  159. %.bin.o %_bin.h : %.bin
  160. #---------------------------------------------------------------------------------
  161. @echo $(notdir $<)
  162. @$(bin2o)
  163. -include $(DEPENDS)
  164. #---------------------------------------------------------------------------------------
  165. endif
  166. #---------------------------------------------------------------------------------------