Advertisement
Guest User

Makefile

a guest
Jul 7th, 2023
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 7.27 KB | None | 0 0
  1. #---------------------------------------------------------------------------------
  2. .SUFFIXES:
  3. #---------------------------------------------------------------------------------
  4.  
  5. ifeq ($(strip $(DEVKITPRO)),)
  6. $(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
  7. endif
  8.  
  9. TOPDIR ?= $(CURDIR)
  10. include $(DEVKITPRO)/libnx/switch_rules
  11.  
  12. #---------------------------------------------------------------------------------
  13. # TARGET is the name of the output
  14. # BUILD is the directory where object files & intermediate files will be placed
  15. # SOURCES is a list of directories containing source code
  16. # DATA is a list of directories containing data files
  17. # INCLUDES is a list of directories containing header files
  18. # EXEFS_SRC is the optional input directory containing data copied into exefs, if anything this normally should only contain "main.npdm".
  19. # ROMFS is the directory containing data to be added to RomFS, relative to the Makefile (Optional)
  20. #
  21. # NO_ICON: if set to anything, do not use icon.
  22. # NO_NACP: if set to anything, no .nacp file is generated.
  23. # APP_TITLE is the name of the app stored in the .nacp file (Optional)
  24. # APP_AUTHOR is the author of the app stored in the .nacp file (Optional)
  25. # APP_VERSION is the version of the app stored in the .nacp file (Optional)
  26. # APP_TITLEID is the titleID of the app stored in the .nacp file (Optional)
  27. # ICON is the filename of the icon (.jpg), relative to the project folder.
  28. #   If not set, it attempts to use one of the following (in this order):
  29. #     - <Project name>.jpg
  30. #     - icon.jpg
  31. #     - <libnx folder>/default_icon.jpg
  32. #---------------------------------------------------------------------------------
  33. TARGET      :=  $(notdir $(CURDIR))
  34. BUILD       :=  build
  35. SOURCES     :=  source
  36. DATA        :=  data
  37. INCLUDES    :=  include
  38. EXEFS_SRC   :=  exefs_src
  39. ROMFS       :=  romfs
  40.  
  41. APP_TITLE   :=  BOTW UI Redux
  42. APP_AUTHOR  :=  Jpe230 | Redux:ThatBenderGuy
  43. APP_VERSION :=  0.1
  44. ICON        :=  meta/icon.jpg
  45.  
  46. #---------------------------------------------------------------------------------
  47. # options for code generation
  48. #---------------------------------------------------------------------------------
  49. ARCH    :=  -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE
  50.  
  51. CFLAGS  :=  -g -Wall -O2 -ffunction-sections \
  52.             $(ARCH) $(DEFINES)
  53.  
  54. CFLAGS  +=  -D__SWITCH__ $(INCLUDE) `sdl2-config --cflags`
  55.  
  56. CXXFLAGS    := $(CFLAGS) -fno-rtti -fno-exceptions #-std=gnu++11
  57.  
  58. ASFLAGS :=  -g $(ARCH)
  59.  
  60. LDFLAGS =   -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
  61.  
  62. LIBS    := -lSDL2_ttf -lSDL2_gfx -lSDL2_image \
  63.            -lpng -ljpeg `sdl2-config --libs` `freetype-config --libs` -lnx
  64.  
  65. #---------------------------------------------------------------------------------
  66. # list of directories containing libraries, this must be the top level containing
  67. # include and lib
  68. #---------------------------------------------------------------------------------
  69. LIBDIRS := $(PORTLIBS) $(LIBNX)
  70.  
  71.  
  72. #---------------------------------------------------------------------------------
  73. # no real need to edit anything past this point unless you need to add additional
  74. # rules for different file extensions
  75. #---------------------------------------------------------------------------------
  76. ifneq ($(BUILD),$(notdir $(CURDIR)))
  77. #---------------------------------------------------------------------------------
  78.  
  79. export OUTPUT   :=  $(CURDIR)/$(TARGET)
  80. export TOPDIR   :=  $(CURDIR)
  81.  
  82. export VPATH    :=  $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
  83.             $(foreach dir,$(DATA),$(CURDIR)/$(dir))
  84.  
  85. export DEPSDIR  :=  $(CURDIR)/$(BUILD)
  86.  
  87. CFILES      :=  $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
  88. CPPFILES    :=  $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
  89. SFILES      :=  $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
  90. BINFILES    :=  $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
  91.  
  92. #---------------------------------------------------------------------------------
  93. # use CXX for linking C++ projects, CC for standard C
  94. #---------------------------------------------------------------------------------
  95. ifeq ($(strip $(CPPFILES)),)
  96. #---------------------------------------------------------------------------------
  97.     export LD   :=  $(CC)
  98. #---------------------------------------------------------------------------------
  99. else
  100. #---------------------------------------------------------------------------------
  101.     export LD   :=  $(CXX)
  102. #---------------------------------------------------------------------------------
  103. endif
  104. #---------------------------------------------------------------------------------
  105.  
  106. export OFILES_BIN   :=  $(addsuffix .o,$(BINFILES))
  107. export OFILES_SRC   :=  $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
  108. export OFILES   :=  $(OFILES_BIN) $(OFILES_SRC)
  109. export HFILES_BIN   :=  $(addsuffix .h,$(subst .,_,$(BINFILES)))
  110.  
  111. export INCLUDE  :=  $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
  112.             $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
  113.             -I$(CURDIR)/$(BUILD)
  114.  
  115. export LIBPATHS :=  $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
  116.  
  117. export BUILD_EXEFS_SRC := $(TOPDIR)/$(EXEFS_SRC)
  118.  
  119. ifeq ($(strip $(ICON)),)
  120.     icons := $(wildcard *.jpg)
  121.     ifneq (,$(findstring $(TARGET).jpg,$(icons)))
  122.         export APP_ICON := $(TOPDIR)/$(TARGET).jpg
  123.     else
  124.         ifneq (,$(findstring icon.jpg,$(icons)))
  125.             export APP_ICON := $(TOPDIR)/icon.jpg
  126.         endif
  127.     endif
  128. else
  129.     export APP_ICON := $(TOPDIR)/$(ICON)
  130. endif
  131.  
  132. ifeq ($(strip $(NO_ICON)),)
  133.     export NROFLAGS += --icon=$(APP_ICON)
  134. endif
  135.  
  136. ifeq ($(strip $(NO_NACP)),)
  137.     export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp
  138. endif
  139.  
  140. ifneq ($(APP_TITLEID),)
  141.     export NACPFLAGS += --titleid=$(APP_TITLEID)
  142. endif
  143.  
  144. ifneq ($(ROMFS),)
  145.     export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS)
  146. endif
  147.  
  148. .PHONY: $(BUILD) clean all
  149.  
  150. #---------------------------------------------------------------------------------
  151. all: $(BUILD)
  152.  
  153. $(BUILD):
  154.     @[ -d $@ ] || mkdir -p $@
  155.     @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
  156.  
  157. #---------------------------------------------------------------------------------
  158. clean:
  159.     @echo clean ...
  160.     @rm -fr $(BUILD) $(TARGET).pfs0 $(TARGET).nso $(TARGET).nro $(TARGET).nacp $(TARGET).elf
  161.  
  162.  
  163. #---------------------------------------------------------------------------------
  164. else
  165. .PHONY: all
  166.  
  167. DEPENDS :=  $(OFILES:.o=.d)
  168.  
  169. #---------------------------------------------------------------------------------
  170. # main targets
  171. #---------------------------------------------------------------------------------
  172. all :   $(OUTPUT).pfs0 $(OUTPUT).nro
  173.  
  174. $(OUTPUT).pfs0  :   $(OUTPUT).nso
  175.  
  176. $(OUTPUT).nso   :   $(OUTPUT).elf
  177.  
  178. ifeq ($(strip $(NO_NACP)),)
  179. $(OUTPUT).nro   :   $(OUTPUT).elf $(OUTPUT).nacp
  180. else
  181. $(OUTPUT).nro   :   $(OUTPUT).elf
  182. endif
  183.  
  184. $(OUTPUT).elf   :   $(OFILES)
  185.  
  186. $(OFILES_SRC)   : $(HFILES_BIN)
  187.  
  188. #---------------------------------------------------------------------------------
  189. # you need a rule like this for each extension you use as binary data
  190. #---------------------------------------------------------------------------------
  191. %.bin.o %_bin.h :   %.bin
  192. #---------------------------------------------------------------------------------
  193.     @echo $(notdir $<)
  194.     @$(bin2o)
  195.  
  196. -include $(DEPENDS)
  197.  
  198. #---------------------------------------------------------------------------------------
  199. endif
  200. #---------------------------------------------------------------------------------------
  201.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement