diff --git a/.gitignore b/.gitignore index acccb6a..2498fdd 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ bin/* *.o *.a *.so.* +.DS_Store ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. diff --git a/BUILDING.md b/BUILDING.md index 2d94e78..ba5df5c 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -7,7 +7,10 @@ ### Using Makefile * `make` (default) - Compile program + * Compiling the program requires local dependencies to be compiled via `make deps` beforehand * `make clean` - Remove executable and object files +* `make deps` - Compile locally included dependency libraries +* `make clean_deps` - Remove compiled library binaries and object files ## Native Win32 - Visual Studio ### Requirements @@ -15,5 +18,5 @@ ### Compiling NSTool * Open `build/visualstudio/nstool.sln` in Visual Studio -* Select Target (e.g `Debug`|`Release` & `x64`) +* Select Target (e.g `Debug`|`Release` & `x86`|`x64`) * Navigate to `Build`->`Build Solution` \ No newline at end of file diff --git a/deps/libfnd b/deps/libfnd index 8cdd41b..a3da67f 160000 --- a/deps/libfnd +++ b/deps/libfnd @@ -1 +1 @@ -Subproject commit 8cdd41b13ed369638583f733b3f60494525976ff +Subproject commit a3da67f8bcbf794e3689b0496695a249e323b6e8 diff --git a/deps/liblz4 b/deps/liblz4 index c50865c..1dbb4a7 160000 --- a/deps/liblz4 +++ b/deps/liblz4 @@ -1 +1 @@ -Subproject commit c50865c96a87a86b8429e3b08a7c6e39e56e2815 +Subproject commit 1dbb4a7988f91f0dbe854cb841b4ad5cdaff912e diff --git a/deps/libnintendo-es b/deps/libnintendo-es index c294d8b..5b46763 160000 --- a/deps/libnintendo-es +++ b/deps/libnintendo-es @@ -1 +1 @@ -Subproject commit c294d8b81eda7f5cf75bb58f725d4b3c9189bc92 +Subproject commit 5b46763f7c35111bc67406ecadb4381436aa62b8 diff --git a/deps/libnintendo-hac b/deps/libnintendo-hac index 67a4242..71f5f5d 160000 --- a/deps/libnintendo-hac +++ b/deps/libnintendo-hac @@ -1 +1 @@ -Subproject commit 67a4242a76aaf1d4c7d40c7c3b1b1f7a640a77ba +Subproject commit 71f5f5d9488bf24ee3c9196911880c5ecda7c0cc diff --git a/deps/libnintendo-hac-hb b/deps/libnintendo-hac-hb index ff5570e..dc434e4 160000 --- a/deps/libnintendo-hac-hb +++ b/deps/libnintendo-hac-hb @@ -1 +1 @@ -Subproject commit ff5570e7642d4eadadf2b09c49e5b926cae9f4c0 +Subproject commit dc434e4605476c40f584e6e98f54fdd980eba2eb diff --git a/deps/libnintendo-pki b/deps/libnintendo-pki index add0fdd..509300a 160000 --- a/deps/libnintendo-pki +++ b/deps/libnintendo-pki @@ -1 +1 @@ -Subproject commit add0fddabea63a32248ae16b75d8dfb8bfda16a5 +Subproject commit 509300a121626a9221f2d8af42a06723481ebf33 diff --git a/deps/libpolarssl b/deps/libpolarssl index 374b573..6573a1b 160000 --- a/deps/libpolarssl +++ b/deps/libpolarssl @@ -1 +1 @@ -Subproject commit 374b573ea76e42bd07dd7cf983778eb7be8bb522 +Subproject commit 6573a1bd54a6a13bd468c6e17e631332eaff4449 diff --git a/makefile b/makefile index bd9fc60..fafc39f 100644 --- a/makefile +++ b/makefile @@ -1,90 +1,103 @@ -# Project Defines +# C++/C Recursive Project Makefile +# (c) Jack +# Version 3 + +# Project Name PROJECT_NAME = nstool + +# Project Relative Paths PROJECT_PATH = $(CURDIR) -PROJECT_SRC_PATH = ./src -PROJECT_INCLUDE_PATH = -PROJECT_TEST_PATH = -PROJECT_BIN_PATH = ./bin -PROJECT_DOCS_PATH = -PROJECT_DOXYFILE_PATH = +PROJECT_SRC_PATH = src +PROJECT_SRC_SUBDIRS = $(PROJECT_SRC_PATH) +#PROJECT_INCLUDE_PATH = include +#PROJECT_TESTSRC_PATH = test +#PROJECT_TESTSRC_SUBDIRS = $(PROJECT_TESTSRC_PATH) +PROJECT_BIN_PATH = bin +#PROJECT_DOCS_PATH = docs +#PROJECT_DOXYFILE_PATH = Doxyfile -# Project Library Defines -PROJECT_LIB_VER_MAJOR = 0 -PROJECT_LIB_VER_MINOR = 1 -PROJECT_LIB_VER_PATCH = 0 -PROJECT_SONAME = $(PROJECT_NAME).so.$(PROJECT_LIB_VER_MAJOR) -PROJECT_SO_FILENAME = $(PROJECT_SONAME).$(PROJECT_LIB_VER_MINOR).$(PROJECT_LIB_VER_PATCH) - -# Project Dependencies -PROJECT_DEPEND = nintendo-hac-hb nintendo-hac nintendo-es nintendo-pki fnd polarssl lz4 - -# Check if this is the root makefile +# Determine if the root makefile has been established, and if not establish this makefile as the root makefile ifeq ($(ROOT_PROJECT_NAME),) export ROOT_PROJECT_NAME = $(PROJECT_NAME) export ROOT_PROJECT_PATH = $(PROJECT_PATH) export ROOT_PROJECT_DEPENDENCY_PATH = $(ROOT_PROJECT_PATH)/deps endif -# Compiler Flags +# Shared Library Definitions +PROJECT_SO_VER_MAJOR = 0 +PROJECT_SO_VER_MINOR = 1 +PROJECT_SO_VER_PATCH = 0 +PROJECT_SONAME = $(PROJECT_NAME).so.$(PROJECT_SO_VER_MAJOR) +PROJECT_SO_FILENAME = $(PROJECT_SONAME).$(PROJECT_SO_VER_MINOR).$(PROJECT_SO_VER_PATCH) + +# Project Dependencies +PROJECT_DEPEND_LOCAL = nintendo-hac-hb nintendo-hac nintendo-es nintendo-pki fnd polarssl lz4 +PROJECT_DEPEND_EXTERNAL = + +# Generate compiler flags for including project include path ifneq ($(PROJECT_INCLUDE_PATH),) INC += -I"$(PROJECT_INCLUDE_PATH)" endif -ifneq ($(PROJECT_DEPEND),) - LIB += $(foreach dep,$(PROJECT_DEPEND), -L"$(ROOT_PROJECT_DEPENDENCY_PATH)/lib$(dep)/bin" -l$(dep)) - INC += $(foreach dep,$(PROJECT_DEPEND), -I"$(ROOT_PROJECT_DEPENDENCY_PATH)/lib$(dep)/include") + +# Generate compiler flags for local included dependencies +ifneq ($(PROJECT_DEPEND_LOCAL),) + LIB += $(foreach dep,$(PROJECT_DEPEND_LOCAL), -L"$(ROOT_PROJECT_DEPENDENCY_PATH)/lib$(dep)/bin" -l$(dep)) + INC += $(foreach dep,$(PROJECT_DEPEND_LOCAL), -I"$(ROOT_PROJECT_DEPENDENCY_PATH)/lib$(dep)/include") endif -CXXFLAGS = -std=c++11 $(INC) -fPIC -D__STDC_FORMAT_MACROS -Wall -Wno-unused-value -CFLAGS = -std=c11 $(INC) -fPIC -Wall -Wno-unused-value -ARFLAGS = cr -o -ifeq ($(OS),Windows_NT) - # Windows Only Flags/Libs - CC = x86_64-w64-mingw32-gcc - CXX = x86_64-w64-mingw32-g++ - CFLAGS += -Wno-unused-but-set-variable - CXXFLAGS += -Wno-unused-but-set-variable - LIB += -static -else - UNAME = $(shell uname -s) - ifeq ($(UNAME), Darwin) - # MacOS Only Flags/Libs - CFLAGS += -Wno-unused-private-field - CXXFLAGS += -Wno-unused-private-field - LIB += - ARFLAGS = rc - else - # *nix Only Flags/Libs - CFLAGS += -Wno-unused-but-set-variable - CXXFLAGS += -Wno-unused-but-set-variable - LIB += - endif + +# Generate compiler flags for external dependencies +ifneq ($(PROJECT_DEPEND_EXTERNAL),) + LIB += $(foreach dep,$(PROJECT_DEPEND_EXTERNAL), -l$(dep)) endif -ifeq ($(OS),Windows_NT) - # Windows Only Flags/Libs - CC = x86_64-w64-mingw32-gcc - CXX = x86_64-w64-mingw32-g++ - CFLAGS += -Wno-unused-but-set-variable - CXXFLAGS += -Wno-unused-but-set-variable - LIBS += -static -else - UNAME = $(shell uname -s) - ifeq ($(UNAME), Darwin) - # MacOS Only Flags/Libs - CFLAGS += -Wno-unused-private-field - CXXFLAGS += -Wno-unused-private-field - LIBS += + +# Detect Platform +ifeq ($(PROJECT_PLATFORM),) + ifeq ($(OS), Windows_NT) + export PROJECT_PLATFORM = WIN32 else - # *nix Only Flags/Libs - CFLAGS += -Wno-unused-but-set-variable - CXXFLAGS += -Wno-unused-but-set-variable - LIBS += + UNAME = $(shell uname -s) + ifeq ($(UNAME), Darwin) + export PROJECT_PLATFORM = MACOS + else + export PROJECT_PLATFORM = GNU + endif endif endif +# Generate platform specific compiler flags +ifeq ($(PROJECT_PLATFORM), WIN32) + # Windows Flags/Libs + CC = x86_64-w64-mingw32-gcc + CXX = x86_64-w64-mingw32-g++ + WARNFLAGS = -Wall -Wno-unused-value -Wno-unused-but-set-variable + INC += + LIB += -static + ARFLAGS = cr -o +else ifeq ($(PROJECT_PLATFORM), GNU) + # GNU/Linux Flags/Libs + #CC = + #CXX = + WARNFLAGS = -Wall -Wno-unused-value -Wno-unused-but-set-variable + INC += + LIB += + ARFLAGS = cr -o +else ifeq ($(PROJECT_PLATFORM), MACOS) + # MacOS Flags/Libs + #CC = + #CXX = + WARNFLAGS = -Wall -Wno-unused-value -Wno-unused-private-field + INC += + LIB += + ARFLAGS = rc +endif + +# Compiler Flags +CXXFLAGS = -std=c++11 $(INC) $(WARNFLAGS) -fPIC +CFLAGS = -std=c11 $(INC) $(WARNFLAGS) -fPIC + # Object Files -SRC_DIR = $(PROJECT_SRC_PATH) -SRC_OBJ = $(foreach dir,$(SRC_DIR),$(subst .cpp,.o,$(wildcard $(dir)/*.cpp))) -TEST_DIR = $(PROJECT_TEST_PATH) -TEST_OBJ = $(foreach dir,$(TEST_DIR),$(subst .cpp,.o,$(wildcard $(dir)/*.cpp))) +SRC_OBJ = $(foreach dir,$(PROJECT_SRC_SUBDIRS),$(subst .cpp,.o,$(wildcard $(dir)/*.cpp))) $(foreach dir,$(PROJECT_SRC_SUBDIRS),$(subst .c,.o,$(wildcard $(dir)/*.c))) +TESTSRC_OBJ = $(foreach dir,$(PROJECT_TESTSRC_SUBDIRS),$(subst .cpp,.o,$(wildcard $(dir)/*.cpp))) $(foreach dir,$(PROJECT_TESTSRC_SUBDIRS),$(subst .c,.o,$(wildcard $(dir)/*.c))) # all is the default, user should specify what the default should do # - 'static_lib' for building static library @@ -94,49 +107,71 @@ TEST_OBJ = $(foreach dir,$(TEST_DIR),$(subst .cpp,.o,$(wildcard $(dir)/*.cpp))) # These can typically be used together however *_lib and program should not be used together all: program -clean: clean_objs clean_bin_dir +clean: clean_object_files remove_binary_dir + +# Object Compile Rules +%.o: %.c + @echo CC $< + @$(CC) $(CFLAGS) -c $< -o $@ + +%.o: %.cpp + @echo CXX $< + @$(CXX) $(CXXFLAGS) -c $< -o $@ # Binary Directory -.PHONY: bin_dir -bin_dir: +.PHONY: create_binary_dir +create_binary_dir: @mkdir -p "$(PROJECT_BIN_PATH)" -.PHONY: clean_bin_dir -clean_bin_dir: +.PHONY: remove_binary_dir +remove_binary_dir: +ifneq ($(PROJECT_BIN_PATH),) @rm -rf "$(PROJECT_BIN_PATH)" +endif -.PHONY: clean_objs -clean_objs: - @rm -f $(SRC_OBJ) $(TEST_OBJ) +.PHONY: clean_object_files +clean_object_files: + @rm -f $(SRC_OBJ) $(TESTSRC_OBJ) # Build Library -static_lib: $(SRC_OBJ) bin_dir - ar $(ARFLAGS) "$(PROJECT_BIN_PATH)/$(PROJECT_NAME).a" $(SRC_OBJ) +static_lib: $(SRC_OBJ) create_binary_dir + @echo LINK $(PROJECT_BIN_PATH)/$(PROJECT_NAME).a + @ar $(ARFLAGS) "$(PROJECT_BIN_PATH)/$(PROJECT_NAME).a" $(SRC_OBJ) -shared_lib: $(SRC_OBJ) bin_dir - gcc -shared -Wl,-soname,$(PROJECT_SONAME) -o "$(PROJECT_BIN_PATH)/$(PROJECT_SO_FILENAME)" $(SRC_OBJ) +shared_lib: $(SRC_OBJ) create_binary_dir + @echo LINK $(PROJECT_BIN_PATH)/$(PROJECT_SO_FILENAME) + @gcc -shared -Wl,-soname,$(PROJECT_SONAME) -o "$(PROJECT_BIN_PATH)/$(PROJECT_SO_FILENAME)" $(SRC_OBJ) # Build Program -program: $(SRC_OBJ) bin_dir - $(CXX) $(SRC_OBJ) $(LIB) -o "$(PROJECT_BIN_PATH)/$(PROJECT_NAME)" +program: $(SRC_OBJ) create_binary_dir + @echo LINK $(PROJECT_BIN_PATH)/$(PROJECT_NAME) + @$(CXX) $(SRC_OBJ) $(LIB) -o "$(PROJECT_BIN_PATH)/$(PROJECT_NAME)" # Build Test Program -test_program: $(TEST_OBJ) $(SRC_OBJ) bin_dir - $(CXX) $(TEST_OBJ) $(SRC_OBJ) $(LIB) -o "$(PROJECT_BIN_PATH)/$(PROJECT_NAME)_test" +test_program: $(TESTSRC_OBJ) $(SRC_OBJ) create_binary_dir +ifneq ($(PROJECT_TESTSRC_PATH),) + @echo LINK $(PROJECT_BIN_PATH)/$(PROJECT_NAME)_test + @$(CXX) $(TESTSRC_OBJ) $(SRC_OBJ) $(LIB) -o "$(PROJECT_BIN_PATH)/$(PROJECT_NAME)_test" +endif # Documentation +.PHONY: docs docs: - doxygen $(PROJECT_DOXYFILE_PATH) +ifneq ($(PROJECT_DOCS_PATH),) + doxygen "$(PROJECT_DOXYFILE_PATH)" +endif .PHONY: clean_docs clean_docs: - @rm -rf $(PROJECT_DOCS_PATH) +ifneq ($(PROJECT_DOCS_PATH),) + @rm -rf "$(PROJECT_DOCS_PATH)" +endif # Dependencies -.PHONY: build_deps -build_deps: - @$(foreach lib,$(PROJECT_DEPEND), cd $(ROOT_PROJECT_DEPENDENCY_PATH)/lib$(lib) && $(MAKE) static_lib && cd $(PROJECT_PATH);) +.PHONY: deps +deps: + @$(foreach lib,$(PROJECT_DEPEND_LOCAL), cd "$(ROOT_PROJECT_DEPENDENCY_PATH)/lib$(lib)" && $(MAKE) static_lib && cd "$(PROJECT_PATH)";) .PHONY: clean_deps clean_deps: - @$(foreach lib,$(PROJECT_DEPEND), cd $(ROOT_PROJECT_DEPENDENCY_PATH)/lib$(lib) && $(MAKE) clean && cd $(PROJECT_PATH);) \ No newline at end of file + @$(foreach lib,$(PROJECT_DEPEND_LOCAL), cd "$(ROOT_PROJECT_DEPENDENCY_PATH)/lib$(lib)" && $(MAKE) clean && cd "$(PROJECT_PATH)";) \ No newline at end of file