From 555b9eeeeb55290988323e9dd99b8228c6bfb696 Mon Sep 17 00:00:00 2001 From: PoloNX <57038157+PoloNX@users.noreply.github.com> Date: Fri, 9 Aug 2024 17:17:50 +0200 Subject: [PATCH] Ci : Fixed CI with xmake (#75) * test ci * try fix * fix conf * fix... * fix container * switch to ubuntu * fix * fix * rm devkitpro * add devkita64 * add devkit * sudo pacman * accept all packages * fix * fix * fix * fix pacman * remove release * add debug * try fix * fix typo * rm step * add path * add debug * removed libs * use docker * add deps * rm root * fix path * fix path * fix repo * remove tinyxml2 * removed submodule * add curl * add deps * add gcc * temp fix * test * fix warning --- lib/ini/.gitignore | 13 ++ lib/ini/Makefile | 147 +++++++++++++++ lib/ini/example/Creating/Makefile | 226 ++++++++++++++++++++++ lib/ini/example/Creating/source/main.cpp | 76 ++++++++ lib/ini/example/Editing/Makefile | 227 +++++++++++++++++++++++ lib/ini/example/Editing/romfs/config.ini | 26 +++ lib/ini/example/Editing/source/main.cpp | 71 +++++++ lib/ini/example/Magic/Makefile | 226 ++++++++++++++++++++++ lib/ini/example/Magic/source/main.cpp | 115 ++++++++++++ lib/ini/example/Reading/Makefile | 227 +++++++++++++++++++++++ lib/ini/example/Reading/romfs/config.ini | 26 +++ lib/ini/example/Reading/source/main.cpp | 123 ++++++++++++ toolchain/devkitA64.lua | 59 +++++- 13 files changed, 1555 insertions(+), 7 deletions(-) create mode 100644 lib/ini/.gitignore create mode 100644 lib/ini/Makefile create mode 100644 lib/ini/example/Creating/Makefile create mode 100644 lib/ini/example/Creating/source/main.cpp create mode 100644 lib/ini/example/Editing/Makefile create mode 100644 lib/ini/example/Editing/romfs/config.ini create mode 100644 lib/ini/example/Editing/source/main.cpp create mode 100644 lib/ini/example/Magic/Makefile create mode 100644 lib/ini/example/Magic/source/main.cpp create mode 100644 lib/ini/example/Reading/Makefile create mode 100644 lib/ini/example/Reading/romfs/config.ini create mode 100644 lib/ini/example/Reading/source/main.cpp diff --git a/lib/ini/.gitignore b/lib/ini/.gitignore new file mode 100644 index 0000000..34ed471 --- /dev/null +++ b/lib/ini/.gitignore @@ -0,0 +1,13 @@ +pkg +src +debug +example/**/build +example/**/*.elf +example/**/*.nacp +example/**/*.nro +release +lib +.vscode +*.tar.bz2 +*.tar.xz +*.tar.gz diff --git a/lib/ini/Makefile b/lib/ini/Makefile new file mode 100644 index 0000000..32c58c6 --- /dev/null +++ b/lib/ini/Makefile @@ -0,0 +1,147 @@ +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- + +ifeq ($(strip $(DEVKITPRO)),) +$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=/devkitpro") +endif + +include $(DEVKITPRO)/libnx/switch_rules + +#--------------------------------------------------------------------------------- +# TARGET is the name of the output +# SOURCES is a list of directories containing source code +# DATA is a list of directories containing data files +# INCLUDES is a list of directories containing header files +#--------------------------------------------------------------------------------- +TARGET := SimpleIniParser +VERSION := 2.1.1 +SOURCES := source source/SimpleIniParser +INCLUDES := include include/SimpleIniParser + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIC -ftls-model=local-exec + +CFLAGS := -g -Wall -Werror \ + -ffunction-sections \ + -fdata-sections \ + $(ARCH) \ + $(BUILD_CFLAGS) + +CFLAGS += $(INCLUDE) + +CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions + +ASFLAGS := -g $(ARCH) + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := $(PORTLIBS) $(LIBNX) + +#--------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#--------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#--------------------------------------------------------------------------------- + +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) + +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) +#--------------------------------------------------------------------------------- + export LD := $(CC) +#--------------------------------------------------------------------------------- +else +#--------------------------------------------------------------------------------- + export LD := $(CXX) +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- + +export OFILES_BIN := $(addsuffix .o,$(BINFILES)) +export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) +export OFILES := $(OFILES_BIN) $(OFILES_SRC) +export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) + +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) + +.PHONY: clean all + +#--------------------------------------------------------------------------------- +all: lib/lib$(TARGET).a lib/lib$(TARGET)d.a + +lib: + @[ -d $@ ] || mkdir -p $@ + +release: + @[ -d $@ ] || mkdir -p $@ + +debug: + @[ -d $@ ] || mkdir -p $@ + +lib/lib$(TARGET).a : lib release $(SOURCES) $(INCLUDES) + @$(MAKE) BUILD=release OUTPUT=$(CURDIR)/$@ \ + BUILD_CFLAGS="-DNDEBUG=1 -O2" \ + DEPSDIR=$(CURDIR)/release \ + --no-print-directory -C release \ + -f $(CURDIR)/Makefile + +lib/lib$(TARGET)d.a : lib debug $(SOURCES) $(INCLUDES) + @$(MAKE) BUILD=debug OUTPUT=$(CURDIR)/$@ \ + BUILD_CFLAGS="-DDEBUG=1 -Og" \ + DEPSDIR=$(CURDIR)/debug \ + --no-print-directory -C debug \ + -f $(CURDIR)/Makefile + +dist-bin: all + @tar --exclude=*~ -cjf lib$(TARGET).tar.bz2 include lib + +dist-src: + @tar --exclude=*~ -cjf lib$(TARGET)-src.tar.bz2 include source Makefile + +dist: dist-src dist-bin + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr release debug lib *.bz2 + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(OUTPUT) : $(OFILES) + +$(OFILES_SRC) : $(HFILES) + +#--------------------------------------------------------------------------------- +%_bin.h %.bin.o : %.bin +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + @$(bin2o) + + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------------- diff --git a/lib/ini/example/Creating/Makefile b/lib/ini/example/Creating/Makefile new file mode 100644 index 0000000..ade357d --- /dev/null +++ b/lib/ini/example/Creating/Makefile @@ -0,0 +1,226 @@ +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- + +ifeq ($(strip $(DEVKITPRO)),) +$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=/devkitpro") +endif + +TOPDIR ?= $(CURDIR) +include $(DEVKITPRO)/libnx/switch_rules + +#--------------------------------------------------------------------------------- +# TARGET is the name of the output +# BUILD is the directory where object files & intermediate files will be placed +# SOURCES is a list of directories containing source code +# DATA is a list of directories containing data files +# INCLUDES is a list of directories containing header files +# ROMFS is the directory containing data to be added to RomFS, relative to the Makefile (Optional) +# +# NO_ICON: if set to anything, do not use icon. +# NO_NACP: if set to anything, no .nacp file is generated. +# APP_TITLE is the name of the app stored in the .nacp file (Optional) +# APP_AUTHOR is the author of the app stored in the .nacp file (Optional) +# APP_VERSION is the version of the app stored in the .nacp file (Optional) +# APP_TITLEID is the titleID of the app stored in the .nacp file (Optional) +# ICON is the filename of the icon (.jpg), relative to the project folder. +# If not set, it attempts to use one of the following (in this order): +# - .jpg +# - icon.jpg +# - /default_icon.jpg +# +# CONFIG_JSON is the filename of the NPDM config file (.json), relative to the project folder. +# If not set, it attempts to use one of the following (in this order): +# - .json +# - config.json +# If a JSON file is provided or autodetected, an ExeFS PFS0 (.nsp) is built instead +# of a homebrew executable (.nro). This is intended to be used for sysmodules. +# NACP building is skipped as well. +#--------------------------------------------------------------------------------- +TARGET := $(notdir $(CURDIR)) +BUILD := build +SOURCES := source +DATA := data +INCLUDES := include + +APP_TITLE := Simple INI Parser Creating Example +APP_AUTHOR := Nichole Mattera +APP_VERSION := 2.1.1 + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE + +CFLAGS := -g -Wall -O2 -ffunction-sections \ + $(ARCH) $(DEFINES) + +CFLAGS += $(INCLUDE) -D__SWITCH__ + +CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions + +ASFLAGS := -g $(ARCH) +LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) + +LIBS := -lSimpleIniParser -lnx + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := $(PORTLIBS) $(LIBNX) $(CURDIR)/../../ + + +#--------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#--------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#--------------------------------------------------------------------------------- + +export OUTPUT := $(CURDIR)/$(TARGET) +export TOPDIR := $(CURDIR) + +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + +export DEPSDIR := $(CURDIR)/$(BUILD) + +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) + +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) +#--------------------------------------------------------------------------------- + export LD := $(CC) +#--------------------------------------------------------------------------------- +else +#--------------------------------------------------------------------------------- + export LD := $(CXX) +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- + +export OFILES_BIN := $(addsuffix .o,$(BINFILES)) +export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) +export OFILES := $(OFILES_BIN) $(OFILES_SRC) +export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES))) + +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) + +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +ifeq ($(strip $(CONFIG_JSON)),) + jsons := $(wildcard *.json) + ifneq (,$(findstring $(TARGET).json,$(jsons))) + export APP_JSON := $(TOPDIR)/$(TARGET).json + else + ifneq (,$(findstring config.json,$(jsons))) + export APP_JSON := $(TOPDIR)/config.json + endif + endif +else + export APP_JSON := $(TOPDIR)/$(CONFIG_JSON) +endif + +ifeq ($(strip $(ICON)),) + icons := $(wildcard *.jpg) + ifneq (,$(findstring $(TARGET).jpg,$(icons))) + export APP_ICON := $(TOPDIR)/$(TARGET).jpg + else + ifneq (,$(findstring icon.jpg,$(icons))) + export APP_ICON := $(TOPDIR)/icon.jpg + endif + endif +else + export APP_ICON := $(TOPDIR)/$(ICON) +endif + +ifeq ($(strip $(NO_ICON)),) + export NROFLAGS += --icon=$(APP_ICON) +endif + +ifeq ($(strip $(NO_NACP)),) + export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp +endif + +ifneq ($(APP_TITLEID),) + export NACPFLAGS += --titleid=$(APP_TITLEID) +endif + +ifneq ($(ROMFS),) + export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS) +endif + +.PHONY: $(BUILD) clean all + +#--------------------------------------------------------------------------------- +all: $(BUILD) + +$(BUILD): + @[ -d $@ ] || mkdir -p $@ + @$(MAKE) -C $(CURDIR)/../.. -f $(CURDIR)/../../Makefile + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... +ifeq ($(strip $(APP_JSON)),) + @rm -fr $(BUILD) $(TARGET).nro $(TARGET).nacp $(TARGET).elf +else + @rm -fr $(BUILD) $(TARGET).nsp $(TARGET).nso $(TARGET).npdm $(TARGET).elf +endif + + +#--------------------------------------------------------------------------------- +else +.PHONY: all + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +ifeq ($(strip $(APP_JSON)),) + +all : $(OUTPUT).nro + +ifeq ($(strip $(NO_NACP)),) +$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp +else +$(OUTPUT).nro : $(OUTPUT).elf +endif + +else + +all : $(OUTPUT).nsp + +$(OUTPUT).nsp : $(OUTPUT).nso $(OUTPUT).npdm + +$(OUTPUT).nso : $(OUTPUT).elf + +endif + +$(OUTPUT).elf : $(OFILES) + +$(OFILES_SRC) : $(HFILES_BIN) + +#--------------------------------------------------------------------------------- +# you need a rule like this for each extension you use as binary data +#--------------------------------------------------------------------------------- +%.bin.o %_bin.h : %.bin +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + @$(bin2o) + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------------- diff --git a/lib/ini/example/Creating/source/main.cpp b/lib/ini/example/Creating/source/main.cpp new file mode 100644 index 0000000..c2b0c76 --- /dev/null +++ b/lib/ini/example/Creating/source/main.cpp @@ -0,0 +1,76 @@ +/* + * Simple INI Parser + * Copyright (c) 2021 Nichole Mattera + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include +#include + +using namespace simpleIniParser; + +int main(int argc, char **argv) { + consoleInit(NULL); + + Ini * hekateIni = new Ini(); + + IniSection * configSection = new IniSection(IniSectionType::Section, "config"); + configSection->options.push_back(new IniOption(IniOptionType::Option, "autoboot", "1")); + configSection->options.push_back(new IniOption(IniOptionType::Option, "autoboot_list", "0")); + configSection->options.push_back(new IniOption(IniOptionType::Option, "bootwait", "5")); + configSection->options.push_back(new IniOption(IniOptionType::Option, "customlogo", "1")); + configSection->options.push_back(new IniOption(IniOptionType::Option, "verification", "1")); + configSection->options.push_back(new IniOption(IniOptionType::Option, "backlight", "100")); + configSection->options.push_back(new IniOption(IniOptionType::Option, "autohosoff", "0")); + configSection->options.push_back(new IniOption(IniOptionType::Option, "autonogc", "1")); + hekateIni->sections.push_back(configSection); + + hekateIni->sections.push_back(new IniSection(IniSectionType::HekateCaption, "CFW")); + + IniSection * cfwSection = new IniSection(IniSectionType::Section, "CFW"); + cfwSection->options.push_back(new IniOption(IniOptionType::Option, "fss0", "atmosphere/fusee-secondary.bin")); + cfwSection->options.push_back(new IniOption(IniOptionType::Option, "kip1patch", "nosigchk")); + cfwSection->options.push_back(new IniOption(IniOptionType::Option, "atmosphere", "1")); + cfwSection->options.push_back(new IniOption(IniOptionType::Option, "logopath", "bootloader/bootlogo.bmp")); + hekateIni->sections.push_back(cfwSection); + + hekateIni->sections.push_back(new IniSection(IniSectionType::HekateCaption, "Stock")); + + IniSection * stockSection = new IniSection(IniSectionType::Section, "Stock"); + stockSection->options.push_back(new IniOption(IniOptionType::Option, "fss0", "atmosphere/fusee-secondary.bin")); + stockSection->options.push_back(new IniOption(IniOptionType::Option, "stock", "1")); + hekateIni->sections.push_back(stockSection); + + if (hekateIni->writeToFile("sdmc:/example.ini")) { + std::cout << "Ini file writen to: sdmc:/example.ini\n"; + } + + delete hekateIni; + + std::cout << "Press any key to close.\n"; + + while(appletMainLoop()) + { + hidScanInput(); + if (hidKeysDown(CONTROLLER_P1_AUTO)) + break; + + consoleUpdate(NULL); + } + + consoleExit(NULL); + return 0; +} diff --git a/lib/ini/example/Editing/Makefile b/lib/ini/example/Editing/Makefile new file mode 100644 index 0000000..cb241d1 --- /dev/null +++ b/lib/ini/example/Editing/Makefile @@ -0,0 +1,227 @@ +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- + +ifeq ($(strip $(DEVKITPRO)),) +$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=/devkitpro") +endif + +TOPDIR ?= $(CURDIR) +include $(DEVKITPRO)/libnx/switch_rules + +#--------------------------------------------------------------------------------- +# TARGET is the name of the output +# BUILD is the directory where object files & intermediate files will be placed +# SOURCES is a list of directories containing source code +# DATA is a list of directories containing data files +# INCLUDES is a list of directories containing header files +# ROMFS is the directory containing data to be added to RomFS, relative to the Makefile (Optional) +# +# NO_ICON: if set to anything, do not use icon. +# NO_NACP: if set to anything, no .nacp file is generated. +# APP_TITLE is the name of the app stored in the .nacp file (Optional) +# APP_AUTHOR is the author of the app stored in the .nacp file (Optional) +# APP_VERSION is the version of the app stored in the .nacp file (Optional) +# APP_TITLEID is the titleID of the app stored in the .nacp file (Optional) +# ICON is the filename of the icon (.jpg), relative to the project folder. +# If not set, it attempts to use one of the following (in this order): +# - .jpg +# - icon.jpg +# - /default_icon.jpg +# +# CONFIG_JSON is the filename of the NPDM config file (.json), relative to the project folder. +# If not set, it attempts to use one of the following (in this order): +# - .json +# - config.json +# If a JSON file is provided or autodetected, an ExeFS PFS0 (.nsp) is built instead +# of a homebrew executable (.nro). This is intended to be used for sysmodules. +# NACP building is skipped as well. +#--------------------------------------------------------------------------------- +TARGET := $(notdir $(CURDIR)) +BUILD := build +SOURCES := source +DATA := data +INCLUDES := include +ROMFS := romfs + +APP_TITLE := Simple INI Parser Editing Example +APP_AUTHOR := Nichole Mattera +APP_VERSION := 2.1.1 + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE + +CFLAGS := -g -Wall -O2 -ffunction-sections \ + $(ARCH) $(DEFINES) + +CFLAGS += $(INCLUDE) -D__SWITCH__ + +CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions + +ASFLAGS := -g $(ARCH) +LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) + +LIBS := -lSimpleIniParser -lnx + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := $(PORTLIBS) $(LIBNX) $(CURDIR)/../../ + + +#--------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#--------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#--------------------------------------------------------------------------------- + +export OUTPUT := $(CURDIR)/$(TARGET) +export TOPDIR := $(CURDIR) + +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + +export DEPSDIR := $(CURDIR)/$(BUILD) + +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) + +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) +#--------------------------------------------------------------------------------- + export LD := $(CC) +#--------------------------------------------------------------------------------- +else +#--------------------------------------------------------------------------------- + export LD := $(CXX) +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- + +export OFILES_BIN := $(addsuffix .o,$(BINFILES)) +export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) +export OFILES := $(OFILES_BIN) $(OFILES_SRC) +export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES))) + +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) + +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +ifeq ($(strip $(CONFIG_JSON)),) + jsons := $(wildcard *.json) + ifneq (,$(findstring $(TARGET).json,$(jsons))) + export APP_JSON := $(TOPDIR)/$(TARGET).json + else + ifneq (,$(findstring config.json,$(jsons))) + export APP_JSON := $(TOPDIR)/config.json + endif + endif +else + export APP_JSON := $(TOPDIR)/$(CONFIG_JSON) +endif + +ifeq ($(strip $(ICON)),) + icons := $(wildcard *.jpg) + ifneq (,$(findstring $(TARGET).jpg,$(icons))) + export APP_ICON := $(TOPDIR)/$(TARGET).jpg + else + ifneq (,$(findstring icon.jpg,$(icons))) + export APP_ICON := $(TOPDIR)/icon.jpg + endif + endif +else + export APP_ICON := $(TOPDIR)/$(ICON) +endif + +ifeq ($(strip $(NO_ICON)),) + export NROFLAGS += --icon=$(APP_ICON) +endif + +ifeq ($(strip $(NO_NACP)),) + export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp +endif + +ifneq ($(APP_TITLEID),) + export NACPFLAGS += --titleid=$(APP_TITLEID) +endif + +ifneq ($(ROMFS),) + export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS) +endif + +.PHONY: $(BUILD) clean all + +#--------------------------------------------------------------------------------- +all: $(BUILD) + +$(BUILD): + @[ -d $@ ] || mkdir -p $@ + @$(MAKE) -C $(CURDIR)/../.. -f $(CURDIR)/../../Makefile + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... +ifeq ($(strip $(APP_JSON)),) + @rm -fr $(BUILD) $(TARGET).nro $(TARGET).nacp $(TARGET).elf +else + @rm -fr $(BUILD) $(TARGET).nsp $(TARGET).nso $(TARGET).npdm $(TARGET).elf +endif + + +#--------------------------------------------------------------------------------- +else +.PHONY: all + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +ifeq ($(strip $(APP_JSON)),) + +all : $(OUTPUT).nro + +ifeq ($(strip $(NO_NACP)),) +$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp +else +$(OUTPUT).nro : $(OUTPUT).elf +endif + +else + +all : $(OUTPUT).nsp + +$(OUTPUT).nsp : $(OUTPUT).nso $(OUTPUT).npdm + +$(OUTPUT).nso : $(OUTPUT).elf + +endif + +$(OUTPUT).elf : $(OFILES) + +$(OFILES_SRC) : $(HFILES_BIN) + +#--------------------------------------------------------------------------------- +# you need a rule like this for each extension you use as binary data +#--------------------------------------------------------------------------------- +%.bin.o %_bin.h : %.bin +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + @$(bin2o) + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------------- diff --git a/lib/ini/example/Editing/romfs/config.ini b/lib/ini/example/Editing/romfs/config.ini new file mode 100644 index 0000000..a4d19d3 --- /dev/null +++ b/lib/ini/example/Editing/romfs/config.ini @@ -0,0 +1,26 @@ +# Sample Config +global_setting=1 +; Comments +global_setting_two=2 + +[config] +autoboot=1 +autoboot_list=0 +bootwait=5 +customlogo=1 +verification=1 + +{AtlasNX/Kosmos} + +; Custom Firmwares +[CFW] +kip1patch=nosigchk +# Option Comment Test +atmosphere=1 +logopath=bootloader/bootlogo1.bmp +logopath=bootloader/bootlogo2.bmp + +# Miscellaneous +[Stock] +fss0=atmosphere/fusee-secondary.bin +stock=1 \ No newline at end of file diff --git a/lib/ini/example/Editing/source/main.cpp b/lib/ini/example/Editing/source/main.cpp new file mode 100644 index 0000000..f4a9a42 --- /dev/null +++ b/lib/ini/example/Editing/source/main.cpp @@ -0,0 +1,71 @@ +/* + * Simple INI Parser + * Copyright (c) 2021 Nichole Mattera + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include +#include + +using namespace simpleIniParser; + +void copy_file(std::string srcPath, std::string destPath) { + std::ifstream src(srcPath, std::ios::binary); + std::ofstream dest(destPath, std::ios::binary); + + dest << src.rdbuf(); + + src.close(); + dest.flush(); + dest.close(); +} + +int main(int argc, char **argv) { + consoleInit(NULL); + + Result rc = romfsInit(); + if (R_FAILED(rc)) { + std::cout << "Unable to initialize romfs.\n"; + } + else { + copy_file("romfs:/config.ini", "sdmc:/example1.ini"); + + Ini * exampleIni = Ini::parseFile("sdmc:/example1.ini"); + exampleIni->sections.pop_back(); + exampleIni->sections.pop_back(); + + exampleIni->findSection("config")->findFirstOption("autoboot")->value = "0"; + + exampleIni->writeToFile("sdmc:/example2.ini"); + + delete exampleIni; + } + std::cout << "Original file written to: sdmc:/example1.ini\n"; + std::cout << "Modified file written to: sdmc:/example2.ini\n\n"; + std::cout << "Press any key to close.\n"; + + while(appletMainLoop()) + { + hidScanInput(); + if (hidKeysDown(CONTROLLER_P1_AUTO)) + break; + + consoleUpdate(NULL); + } + + consoleExit(NULL); + return 0; +} diff --git a/lib/ini/example/Magic/Makefile b/lib/ini/example/Magic/Makefile new file mode 100644 index 0000000..3385f3c --- /dev/null +++ b/lib/ini/example/Magic/Makefile @@ -0,0 +1,226 @@ +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- + +ifeq ($(strip $(DEVKITPRO)),) +$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=/devkitpro") +endif + +TOPDIR ?= $(CURDIR) +include $(DEVKITPRO)/libnx/switch_rules + +#--------------------------------------------------------------------------------- +# TARGET is the name of the output +# BUILD is the directory where object files & intermediate files will be placed +# SOURCES is a list of directories containing source code +# DATA is a list of directories containing data files +# INCLUDES is a list of directories containing header files +# ROMFS is the directory containing data to be added to RomFS, relative to the Makefile (Optional) +# +# NO_ICON: if set to anything, do not use icon. +# NO_NACP: if set to anything, no .nacp file is generated. +# APP_TITLE is the name of the app stored in the .nacp file (Optional) +# APP_AUTHOR is the author of the app stored in the .nacp file (Optional) +# APP_VERSION is the version of the app stored in the .nacp file (Optional) +# APP_TITLEID is the titleID of the app stored in the .nacp file (Optional) +# ICON is the filename of the icon (.jpg), relative to the project folder. +# If not set, it attempts to use one of the following (in this order): +# - .jpg +# - icon.jpg +# - /default_icon.jpg +# +# CONFIG_JSON is the filename of the NPDM config file (.json), relative to the project folder. +# If not set, it attempts to use one of the following (in this order): +# - .json +# - config.json +# If a JSON file is provided or autodetected, an ExeFS PFS0 (.nsp) is built instead +# of a homebrew executable (.nro). This is intended to be used for sysmodules. +# NACP building is skipped as well. +#--------------------------------------------------------------------------------- +TARGET := $(notdir $(CURDIR)) +BUILD := build +SOURCES := source +DATA := data +INCLUDES := include + +APP_TITLE := Simple INI Parser Magic Example +APP_AUTHOR := Nichole Mattera +APP_VERSION := 2.1.1 + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE + +CFLAGS := -g -Wall -O2 -ffunction-sections \ + $(ARCH) $(DEFINES) + +CFLAGS += $(INCLUDE) -D__SWITCH__ + +CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions + +ASFLAGS := -g $(ARCH) +LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) + +LIBS := -lSimpleIniParser -lnx + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := $(PORTLIBS) $(LIBNX) $(CURDIR)/../../ + + +#--------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#--------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#--------------------------------------------------------------------------------- + +export OUTPUT := $(CURDIR)/$(TARGET) +export TOPDIR := $(CURDIR) + +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + +export DEPSDIR := $(CURDIR)/$(BUILD) + +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) + +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) +#--------------------------------------------------------------------------------- + export LD := $(CC) +#--------------------------------------------------------------------------------- +else +#--------------------------------------------------------------------------------- + export LD := $(CXX) +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- + +export OFILES_BIN := $(addsuffix .o,$(BINFILES)) +export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) +export OFILES := $(OFILES_BIN) $(OFILES_SRC) +export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES))) + +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) + +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +ifeq ($(strip $(CONFIG_JSON)),) + jsons := $(wildcard *.json) + ifneq (,$(findstring $(TARGET).json,$(jsons))) + export APP_JSON := $(TOPDIR)/$(TARGET).json + else + ifneq (,$(findstring config.json,$(jsons))) + export APP_JSON := $(TOPDIR)/config.json + endif + endif +else + export APP_JSON := $(TOPDIR)/$(CONFIG_JSON) +endif + +ifeq ($(strip $(ICON)),) + icons := $(wildcard *.jpg) + ifneq (,$(findstring $(TARGET).jpg,$(icons))) + export APP_ICON := $(TOPDIR)/$(TARGET).jpg + else + ifneq (,$(findstring icon.jpg,$(icons))) + export APP_ICON := $(TOPDIR)/icon.jpg + endif + endif +else + export APP_ICON := $(TOPDIR)/$(ICON) +endif + +ifeq ($(strip $(NO_ICON)),) + export NROFLAGS += --icon=$(APP_ICON) +endif + +ifeq ($(strip $(NO_NACP)),) + export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp +endif + +ifneq ($(APP_TITLEID),) + export NACPFLAGS += --titleid=$(APP_TITLEID) +endif + +ifneq ($(ROMFS),) + export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS) +endif + +.PHONY: $(BUILD) clean all + +#--------------------------------------------------------------------------------- +all: $(BUILD) + +$(BUILD): + @[ -d $@ ] || mkdir -p $@ + @$(MAKE) -C $(CURDIR)/../.. -f $(CURDIR)/../../Makefile + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... +ifeq ($(strip $(APP_JSON)),) + @rm -fr $(BUILD) $(TARGET).nro $(TARGET).nacp $(TARGET).elf +else + @rm -fr $(BUILD) $(TARGET).nsp $(TARGET).nso $(TARGET).npdm $(TARGET).elf +endif + + +#--------------------------------------------------------------------------------- +else +.PHONY: all + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +ifeq ($(strip $(APP_JSON)),) + +all : $(OUTPUT).nro + +ifeq ($(strip $(NO_NACP)),) +$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp +else +$(OUTPUT).nro : $(OUTPUT).elf +endif + +else + +all : $(OUTPUT).nsp + +$(OUTPUT).nsp : $(OUTPUT).nso $(OUTPUT).npdm + +$(OUTPUT).nso : $(OUTPUT).elf + +endif + +$(OUTPUT).elf : $(OFILES) + +$(OFILES_SRC) : $(HFILES_BIN) + +#--------------------------------------------------------------------------------- +# you need a rule like this for each extension you use as binary data +#--------------------------------------------------------------------------------- +%.bin.o %_bin.h : %.bin +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + @$(bin2o) + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------------- diff --git a/lib/ini/example/Magic/source/main.cpp b/lib/ini/example/Magic/source/main.cpp new file mode 100644 index 0000000..9f4cc96 --- /dev/null +++ b/lib/ini/example/Magic/source/main.cpp @@ -0,0 +1,115 @@ +/* + * Simple INI Parser + * Copyright (c) 2021 Nichole Mattera + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include +#include + +using namespace simpleIniParser; +using namespace std; + +void writeOption(IniOption * option, bool withTab) { + switch (option->type) { + case IniOptionType::SemicolonComment: + std::cout << ((withTab) ? "\t" : "") << "Type: Semicolon Comment, Value: \"" << option->value << "\"\n"; + break; + + case IniOptionType::HashtagComment: + std::cout << ((withTab) ? "\t" : "") << "Type: Hashtag Comment, Value: \"" << option->value << "\"\n"; + break; + + default: + std::cout << ((withTab) ? "\t" : "") << "Type: Option, Key: \"" << option->key << "\", Value: \"" << option->value << "\"\n"; + break; + } +} + +void writeSection(IniSection * section) { + switch (section->type) { + case IniSectionType::SemicolonComment: + std::cout << "Type: Semicolon Comment, Value: \"" << section->value << "\"\n"; + break; + + case IniSectionType::HashtagComment: + std::cout << "Type: Hashtag Comment, Value: \"" << section->value << "\"\n"; + break; + + case IniSectionType::HekateCaption: + std::cout << "Type: Hekate Caption, Value: \"" << section->value << "\"\n"; + break; + + default: + std::cout << "Type: Section, Value: \"" << section->value << "\"\n"; + break; + } + + for (auto const& option : section->options) { + writeOption(option, true); + } + + std::cout << "\n"; +} + +int main(int argc, char **argv) { + consoleInit(NULL); + + Ini * config = Ini::parseFileWithMagic("sdmc:/atmosphere/BCT.ini", "BCT0"); + + std::cout << "Reading through an INI file.\n"; + std::cout << "=====================================================\n\n"; + + + for (auto const& option : config->options) { + writeOption(option, false); + } + + if (config->options.size() > 0) + std::cout << "\n"; + + for (auto const& section : config->sections) { + writeSection(section); + } + + auto exosphereSection = config->findSection("exosphere"); //->findFirstOption("autoboot")->value = "0"; + if (exosphereSection != nullptr) { + auto debugModeOption = exosphereSection->findFirstOption("debugmode"); + if (debugModeOption != nullptr) { + debugModeOption->value = "0"; + + config->writeToFile("sdmc:/BCT.ini"); + + std::cout << "Modified version of BCT.ini has been writen to the root of your SD Card.\n"; + } + } + + delete config; + + std::cout << "\nPress any key to close.\n"; + + while(appletMainLoop()) + { + hidScanInput(); + if (hidKeysDown(CONTROLLER_P1_AUTO)) + break; + + consoleUpdate(NULL); + } + + consoleExit(NULL); + return 0; +} diff --git a/lib/ini/example/Reading/Makefile b/lib/ini/example/Reading/Makefile new file mode 100644 index 0000000..0f349a6 --- /dev/null +++ b/lib/ini/example/Reading/Makefile @@ -0,0 +1,227 @@ +#--------------------------------------------------------------------------------- +.SUFFIXES: +#--------------------------------------------------------------------------------- + +ifeq ($(strip $(DEVKITPRO)),) +$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=/devkitpro") +endif + +TOPDIR ?= $(CURDIR) +include $(DEVKITPRO)/libnx/switch_rules + +#--------------------------------------------------------------------------------- +# TARGET is the name of the output +# BUILD is the directory where object files & intermediate files will be placed +# SOURCES is a list of directories containing source code +# DATA is a list of directories containing data files +# INCLUDES is a list of directories containing header files +# ROMFS is the directory containing data to be added to RomFS, relative to the Makefile (Optional) +# +# NO_ICON: if set to anything, do not use icon. +# NO_NACP: if set to anything, no .nacp file is generated. +# APP_TITLE is the name of the app stored in the .nacp file (Optional) +# APP_AUTHOR is the author of the app stored in the .nacp file (Optional) +# APP_VERSION is the version of the app stored in the .nacp file (Optional) +# APP_TITLEID is the titleID of the app stored in the .nacp file (Optional) +# ICON is the filename of the icon (.jpg), relative to the project folder. +# If not set, it attempts to use one of the following (in this order): +# - .jpg +# - icon.jpg +# - /default_icon.jpg +# +# CONFIG_JSON is the filename of the NPDM config file (.json), relative to the project folder. +# If not set, it attempts to use one of the following (in this order): +# - .json +# - config.json +# If a JSON file is provided or autodetected, an ExeFS PFS0 (.nsp) is built instead +# of a homebrew executable (.nro). This is intended to be used for sysmodules. +# NACP building is skipped as well. +#--------------------------------------------------------------------------------- +TARGET := $(notdir $(CURDIR)) +BUILD := build +SOURCES := source +DATA := data +INCLUDES := include +ROMFS := romfs + +APP_TITLE := Simple INI Parser Reading Example +APP_AUTHOR := Nichole Mattera +APP_VERSION := 2.1.1 + +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- +ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE + +CFLAGS := -g -Wall -O2 -ffunction-sections \ + $(ARCH) $(DEFINES) + +CFLAGS += $(INCLUDE) -D__SWITCH__ + +CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions + +ASFLAGS := -g $(ARCH) +LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) + +LIBS := -lSimpleIniParser -lnx + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := $(PORTLIBS) $(LIBNX) $(CURDIR)/../../ + + +#--------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#--------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#--------------------------------------------------------------------------------- + +export OUTPUT := $(CURDIR)/$(TARGET) +export TOPDIR := $(CURDIR) + +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + +export DEPSDIR := $(CURDIR)/$(BUILD) + +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) + +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) +#--------------------------------------------------------------------------------- + export LD := $(CC) +#--------------------------------------------------------------------------------- +else +#--------------------------------------------------------------------------------- + export LD := $(CXX) +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- + +export OFILES_BIN := $(addsuffix .o,$(BINFILES)) +export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) +export OFILES := $(OFILES_BIN) $(OFILES_SRC) +export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES))) + +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) + +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +ifeq ($(strip $(CONFIG_JSON)),) + jsons := $(wildcard *.json) + ifneq (,$(findstring $(TARGET).json,$(jsons))) + export APP_JSON := $(TOPDIR)/$(TARGET).json + else + ifneq (,$(findstring config.json,$(jsons))) + export APP_JSON := $(TOPDIR)/config.json + endif + endif +else + export APP_JSON := $(TOPDIR)/$(CONFIG_JSON) +endif + +ifeq ($(strip $(ICON)),) + icons := $(wildcard *.jpg) + ifneq (,$(findstring $(TARGET).jpg,$(icons))) + export APP_ICON := $(TOPDIR)/$(TARGET).jpg + else + ifneq (,$(findstring icon.jpg,$(icons))) + export APP_ICON := $(TOPDIR)/icon.jpg + endif + endif +else + export APP_ICON := $(TOPDIR)/$(ICON) +endif + +ifeq ($(strip $(NO_ICON)),) + export NROFLAGS += --icon=$(APP_ICON) +endif + +ifeq ($(strip $(NO_NACP)),) + export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp +endif + +ifneq ($(APP_TITLEID),) + export NACPFLAGS += --titleid=$(APP_TITLEID) +endif + +ifneq ($(ROMFS),) + export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS) +endif + +.PHONY: $(BUILD) clean all + +#--------------------------------------------------------------------------------- +all: $(BUILD) + +$(BUILD): + @[ -d $@ ] || mkdir -p $@ + @$(MAKE) -C $(CURDIR)/../.. -f $(CURDIR)/../../Makefile + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- +clean: + @echo clean ... +ifeq ($(strip $(APP_JSON)),) + @rm -fr $(BUILD) $(TARGET).nro $(TARGET).nacp $(TARGET).elf +else + @rm -fr $(BUILD) $(TARGET).nsp $(TARGET).nso $(TARGET).npdm $(TARGET).elf +endif + + +#--------------------------------------------------------------------------------- +else +.PHONY: all + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +ifeq ($(strip $(APP_JSON)),) + +all : $(OUTPUT).nro + +ifeq ($(strip $(NO_NACP)),) +$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp +else +$(OUTPUT).nro : $(OUTPUT).elf +endif + +else + +all : $(OUTPUT).nsp + +$(OUTPUT).nsp : $(OUTPUT).nso $(OUTPUT).npdm + +$(OUTPUT).nso : $(OUTPUT).elf + +endif + +$(OUTPUT).elf : $(OFILES) + +$(OFILES_SRC) : $(HFILES_BIN) + +#--------------------------------------------------------------------------------- +# you need a rule like this for each extension you use as binary data +#--------------------------------------------------------------------------------- +%.bin.o %_bin.h : %.bin +#--------------------------------------------------------------------------------- + @echo $(notdir $<) + @$(bin2o) + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------------- diff --git a/lib/ini/example/Reading/romfs/config.ini b/lib/ini/example/Reading/romfs/config.ini new file mode 100644 index 0000000..a4d19d3 --- /dev/null +++ b/lib/ini/example/Reading/romfs/config.ini @@ -0,0 +1,26 @@ +# Sample Config +global_setting=1 +; Comments +global_setting_two=2 + +[config] +autoboot=1 +autoboot_list=0 +bootwait=5 +customlogo=1 +verification=1 + +{AtlasNX/Kosmos} + +; Custom Firmwares +[CFW] +kip1patch=nosigchk +# Option Comment Test +atmosphere=1 +logopath=bootloader/bootlogo1.bmp +logopath=bootloader/bootlogo2.bmp + +# Miscellaneous +[Stock] +fss0=atmosphere/fusee-secondary.bin +stock=1 \ No newline at end of file diff --git a/lib/ini/example/Reading/source/main.cpp b/lib/ini/example/Reading/source/main.cpp new file mode 100644 index 0000000..ad47d34 --- /dev/null +++ b/lib/ini/example/Reading/source/main.cpp @@ -0,0 +1,123 @@ +/* + * Simple INI Parser + * Copyright (c) 2021 Nichole Mattera + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include +#include +#include + +using namespace simpleIniParser; + +void writeOption(IniOption * option, bool withTab) { + switch (option->type) { + case IniOptionType::SemicolonComment: + std::cout << ((withTab) ? "\t" : "") << "Type: Semicolon Comment, Value: \"" << option->value << "\"\n"; + break; + + case IniOptionType::HashtagComment: + std::cout << ((withTab) ? "\t" : "") << "Type: Hashtag Comment, Value: \"" << option->value << "\"\n"; + break; + + default: + std::cout << ((withTab) ? "\t" : "") << "Type: Option, Key: \"" << option->key << "\", Value: \"" << option->value << "\"\n"; + break; + } +} + +void writeSection(IniSection * section) { + switch (section->type) { + case IniSectionType::SemicolonComment: + std::cout << "Type: Semicolon Comment, Value: \"" << section->value << "\"\n"; + break; + + case IniSectionType::HashtagComment: + std::cout << "Type: Hashtag Comment, Value: \"" << section->value << "\"\n"; + break; + + case IniSectionType::HekateCaption: + std::cout << "Type: Hekate Caption, Value: \"" << section->value << "\"\n"; + break; + + default: + std::cout << "Type: Section, Value: \"" << section->value << "\"\n"; + break; + } + + for (auto const& option : section->options) { + writeOption(option, true); + } + + std::cout << "\n"; +} + +int main(int argc, char **argv) { + consoleInit(NULL); + + Result rc = romfsInit(); + if (R_FAILED(rc)) { + std::cout << "Unable to initialize romfs.\n"; + } + else { + Ini * config = Ini::parseFile("romfs:/config.ini"); + + std::cout << "Reading through an INI file.\n"; + std::cout << "=====================================================\n\n"; + + + for (auto const& option : config->options) { + writeOption(option, false); + } + + if (config->options.size() > 0) + std::cout << "\n"; + + for (auto const& section : config->sections) { + writeSection(section); + } + + std::cout << "\nGet a specific option from a specific section.\n"; + std::cout << "=====================================================\n\n"; + + std::vector options = config->findSection("CFW", true, IniSectionType::Section)->findAllOptions("logopath"); + for (auto const& option : options) { + writeOption(option, false); + } + + IniOption * option = config->findSection("config")->findFirstOption("cUsToMlOgO", false); + std::cout << "Key: \"" << option->key << "\" | Value: \"" << option->value << "\"\n"; + + IniOption * option2 = config->findSection("CFW", true, IniSectionType::Section)->findFirstOption("option comment test", false, IniOptionType::HashtagComment, IniOptionSearchField::Value); + std::cout << "Key: \"" << option2->key << "\" | Value: \"" << option2->value << "\"\n\n"; + + delete config; + } + + std::cout << "\nPress any key to close.\n"; + + while(appletMainLoop()) + { + hidScanInput(); + if (hidKeysDown(CONTROLLER_P1_AUTO)) + break; + + consoleUpdate(NULL); + } + + consoleExit(NULL); + return 0; +} diff --git a/toolchain/devkitA64.lua b/toolchain/devkitA64.lua index b156e8c..6a1aa3e 100644 --- a/toolchain/devkitA64.lua +++ b/toolchain/devkitA64.lua @@ -1,5 +1,46 @@ local triple = "aarch64-unknown-none-elf" +local buildflags = { + "-mcpu=cortex-a57", -- Utiliser uniquement -mcpu + "-mtune=cortex-a57", + "-ftls-model=local-exec", + "-ffunction-sections", + "-fdata-sections", + "-fstack-protector-strong", + "-fPIC", + "-D__SWITCH__=1", + "-D__SWITCH=1", + "-DLIBNX_NO_DEPRECATION", + "-D_GNU_SOURCE=1", + "-D_LIBC", + "-D_NEWLIB_VERSION=4.3.0", + "-D__NEWLIB__=4" +} + +local sharedlinkflags = { + "-Wl,-Bdynamic", + "-fPIC", + "-Wl,--gc-sections", + "-Wl,-z,text", + "-Wl,--build-id=sha1", + "-Wl,--no-dynamic-linker", + "-Wl,--as-needed", + "-Wl,--eh-frame-hdr", + "-fvisibility=hidden" +} + +local executablelinkflags = { + "-Wl,-Bsymbolic", + "-fPIE", + "-Wl,-pie", + "-Wl,--gc-sections", + "-Wl,-z,text", + "-Wl,--build-id=sha1", + "-Wl,--no-dynamic-linker", + "-Wl,--as-needed", + "-Wl,--eh-frame-hdr", + "-fvisibility=hidden", +} toolchain("devkita64") add_defines("__SWITCH__") @@ -22,19 +63,23 @@ toolchain("devkita64") set_toolset("ranlib", "aarch64-none-elf-ranlib") set_toolset("as", "aarch64-none-elf-gcc") + add_cxflags(buildflags) + add_asflags(buildflags) + add_ldflags(executablelinkflags) + add_shflags(sharedlinkflags) + on_check("check") on_load(function(toolchain) - toolchain:add("defines", "SWITCH", "HAVE_LIBNX") - toolchain:add("arch", "-march=armv8-a+crc+crypto", "-mtune=cortex-a57", "-mtp=soft", "-fPIE") + toolchain:add("defines", "SWITCH", "__SWITCH__", "HAVE_LIBNX") + toolchain:add("arch", "-mcpu=cortex-a57", "-mtune=cortex-a57", "-mtp=soft", "-fPIE") toolchain:add("cflags", "-g", "-Wall", "-O2", "-ffunction-sections", "-fdata-sections", {force = true}) - toolchain:add("cxflags", "-march=armv8-a+crc+crypto", "-mtune=cortex-a57", "-mtp=soft", "-fPIE", {force = true}) + toolchain:add("cxflags", "-mcpu=cortex-a57", "-mtune=cortex-a57", "-mtp=soft", "-fPIE", {force = true}) toolchain:add("cxxflags", "-frtti", "-fexceptions", {force = true}) - toolchain:add("asflags", "-g", "-march=armv8-a+crc+crypto", "-mtune=cortex-a57", "-mtp=soft", "-fPIE", {force = true}) + toolchain:add("asflags", "-g", "-mcpu=cortex-a57", "-mtune=cortex-a57", "-mtp=soft", "-fPIE", {force = true}) toolchain:add("ldflags", "-specs=" .. path.join(DEVKITPRO, "/libnx/switch.specs"), "-g", "-W", "-fPIC","$(notdir $*.map)", {force = true}) - -- toolchain:add("linkdirs", path.join(DEVKITPRO, "/libnx/lib"), path.join(DEVKITPRO, "/portlibs/switch/lib")) - toolchain:add("syslinks", "gcc", "c", "m", "nx") - end) \ No newline at end of file + toolchain:add("syslinks", "gcc", "c", "m") + end)