aboutsummaryrefslogtreecommitdiff
path: root/examples/system/childexec
diff options
context:
space:
mode:
authorJohn "Lameguy" Wilbert Villamor <lameguy64@gmail.com>2021-10-15 09:22:45 +0800
committerGitHub <noreply@github.com>2021-10-15 09:22:45 +0800
commitdd0f088aaa4c6bf013643be2d1d8621dbffdb000 (patch)
treed848d6ce007d8bb9357c8b99d6a0a39ec41d244e /examples/system/childexec
parent9e08d1047fa8deeb3ccb3ce9bb11d69e25a52d56 (diff)
parenteb719a424e6a16fb64209139a32c9f8a7235a929 (diff)
downloadpsn00bsdk-dd0f088aaa4c6bf013643be2d1d8621dbffdb000.tar.gz
Merge pull request #38 from spicyjpeg/cmake
Full CMake support (in place of makefiles)
Diffstat (limited to 'examples/system/childexec')
-rw-r--r--examples/system/childexec/CMakeLists.txt41
-rw-r--r--examples/system/childexec/child_exe.s.template (renamed from examples/system/childexec/child_exe.s)2
-rw-r--r--examples/system/childexec/makefile93
3 files changed, 42 insertions, 94 deletions
diff --git a/examples/system/childexec/CMakeLists.txt b/examples/system/childexec/CMakeLists.txt
new file mode 100644
index 0000000..c9983c4
--- /dev/null
+++ b/examples/system/childexec/CMakeLists.txt
@@ -0,0 +1,41 @@
+# PSn00bSDK example CMake script
+# (C) 2021 spicyjpeg - MPL licensed
+
+cmake_minimum_required(VERSION 3.21)
+
+if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS})
+ set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake)
+endif()
+
+project(
+ childexec
+ LANGUAGES C ASM
+ VERSION 1.0.0
+ DESCRIPTION "PSn00bSDK child process example"
+ HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk"
+)
+
+configure_file(child_exe.s.template child_exe.s)
+
+file(GLOB _sources *.c)
+file(GLOB _child_sources child/*.c)
+psn00bsdk_add_executable(
+ parent STATIC
+ ${_sources}
+ ${PROJECT_BINARY_DIR}/child_exe.s
+)
+psn00bsdk_add_executable(child STATIC ${_child_sources})
+#psn00bsdk_add_cd_image(childexec_iso childexec iso.xml DEPENDS parent)
+
+# Relocate the child executable to a non-default address to prevent it from
+# overlapping with the main one at 0x80010000.
+# NOTE: child executables are not position-independent and can't be relocated
+# at runtime. If you need your code to be relocatable (e.g. to load it into a
+# dynamically-allocated buffer), consider using a DLL instead.
+target_link_options(child PRIVATE -Ttext=0x80030000)
+
+# Make sure the child executable is built before the parent (so it can be
+# embedded via child_exe.s).
+add_dependencies(parent child)
+
+install(FILES ${PROJECT_BINARY_DIR}/parent.exe DESTINATION .)
diff --git a/examples/system/childexec/child_exe.s b/examples/system/childexec/child_exe.s.template
index 66bd0e2..f76bb3d 100644
--- a/examples/system/childexec/child_exe.s
+++ b/examples/system/childexec/child_exe.s.template
@@ -3,4 +3,4 @@
.global child_exe # Insert spoopypasta
.type child_exe, @object
child_exe:
- .incbin "build/child/child.exe" \ No newline at end of file
+ .incbin "${PROJECT_BINARY_DIR}/child.exe"
diff --git a/examples/system/childexec/makefile b/examples/system/childexec/makefile
deleted file mode 100644
index e801739..0000000
--- a/examples/system/childexec/makefile
+++ /dev/null
@@ -1,93 +0,0 @@
-# PSn00bSDK makefile template
-# Part of the PSn00bSDK Project
-# 2019 - 2021 Lameguy64 / Meido-Tek Productions
-
-## Settings
-
-PSN00BSDK_LIBS ?= ../../../libpsn00b
-
-# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's
-# root folder (it only depends on environment variables).
-include ../../../psn00bsdk-setup.mk
-
-# Project target name
-#TARGET = childexec
-
-## Files
-
-# Searches for C, C++ and S (assembler) files in local directory
-CFILES_PARENT = $(notdir $(wildcard *.c))
-CPPFILES_PARENT = $(notdir $(wildcard *.cpp))
-AFILES_PARENT = $(notdir $(wildcard *.s))
-
-CFILES_CHILD = $(notdir $(wildcard child/*.c))
-CPPFILES_CHILD = $(notdir $(wildcard child/*.cpp))
-AFILES_CHILD = $(notdir $(wildcard child/*.s))
-
-# Create names for object files
-OFILES_PARENT = $(addprefix build/,$(CFILES_PARENT:.c=.o)) \
- $(addprefix build/,$(CPPFILES_PARENT:.cpp=.o)) \
- $(addprefix build/,$(AFILES_PARENT:.s=.o))
-OFILES_CHILD = $(addprefix build/child/,$(CFILES_CHILD:.c=.o)) \
- $(addprefix build/child/,$(CPPFILES_CHILD:.cpp=.o)) \
- $(addprefix build/child/,$(AFILES_CHILD:.s=.o))
-
-# Project specific includes and libraries
-# (use -I for include dirs, -L for library dirs, -l for static libraries)
-INCLUDE +=
-LIBDIRS +=
-LIBS +=
-
-# Relocate the child executable to 0x30000
-LDFLAGS_CHILD = -Ttext=0x80030000
-
-## Build rules
-
-#all: iso
-all: build/child/child build/parent
-
-iso: build/child/child build/parent resources
- $(MKPSXISO) -y -q iso.xml
-
-resources:
- # Add commands to build/convert your assets here
- #$(LZPACK) data.xml
-
-build/child/child: $(OFILES_CHILD)
- @mkdir -p $(dir $@)
- $(LD) $(LDFLAGS_EXE) $(LDFLAGS_CHILD) $(LIBDIRS) $^ $(LIBS) -o $@
- $(NM) -f posix -l -n $@ >$@.map
- $(ELF2X) -q $@ $@.exe
-
-build/parent: $(OFILES_PARENT)
- @mkdir -p $(dir $@)
- $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@
- $(NM) -f posix -l -n $@ >$@.map
- $(ELF2X) -q $@ $@.exe
-
-build/child/%.o: child/%.c
- @mkdir -p $(dir $@)
- $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@
-
-build/child/%.o: child/%.cpp
- @mkdir -p $(dir $@)
- $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@
-
-build/child/%.o: child/%.s
- @mkdir -p $(dir $@)
- $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@
-
-build/%.o: %.c
- @mkdir -p $(dir $@)
- $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@
-
-build/%.o: %.cpp
- @mkdir -p $(dir $@)
- $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@
-
-build/%.o: %.s
- @mkdir -p $(dir $@)
- $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@
-
-clean:
- rm -rf build