aboutsummaryrefslogtreecommitdiff
path: root/examples/system/childexec/makefile
diff options
context:
space:
mode:
authorJohn "Lameguy" Wilbert Villamor <lameguy64@gmail.com>2021-08-31 13:23:20 +0800
committerGitHub <noreply@github.com>2021-08-31 13:23:20 +0800
commitffa679d4d24b891cb59aba10946368f2ec00c391 (patch)
tree0cf6061915ebf48acdedf6d77b0c1b76eec5b8c3 /examples/system/childexec/makefile
parent317dc2b91d3afcdbaddb035f38611d12af161970 (diff)
parentf2fc18f82dd7900465d6ab3ae2080726d5589d39 (diff)
downloadpsn00bsdk-ffa679d4d24b891cb59aba10946368f2ec00c391.tar.gz
Merge pull request #36 from spicyjpeg/dynlink
Dynamic linker, gp-relative addressing, ldscripts and more
Diffstat (limited to 'examples/system/childexec/makefile')
-rw-r--r--examples/system/childexec/makefile105
1 files changed, 81 insertions, 24 deletions
diff --git a/examples/system/childexec/makefile b/examples/system/childexec/makefile
index 30229ae..e801739 100644
--- a/examples/system/childexec/makefile
+++ b/examples/system/childexec/makefile
@@ -1,36 +1,93 @@
-include ../../examples-setup.mk
+# PSn00bSDK makefile template
+# Part of the PSn00bSDK Project
+# 2019 - 2021 Lameguy64 / Meido-Tek Productions
-INCLUDE +=
-LIBDIRS +=
+## Settings
-LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc
+PSN00BSDK_LIBS ?= ../../../libpsn00b
-CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections
-CPPFLAGS = $(CFLAGS) -fno-exceptions
-AFLAGS = -g -msoft-float
-LDFLAGS = -g -gc-sections \
- -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x
+# 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
-LDFLAGS_P = $(LDFLAGS) -Ttext=0x80010000
-LDFLAGS_C = $(LDFLAGS) -Ttext=0x80030000
+# Project target name
+#TARGET = childexec
-all: child parent
+## Files
-child: build/child.o
- $(LD) $(LDFLAGS_C) $(LIBDIRS) build/child.o $(LIBS) -o child.elf
- elf2x -q child.elf
+# 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 $@
-parent: build/parent.o build/child_exe.o
- $(LD) $(LDFLAGS_P) $(LIBDIRS) build/parent.o build/child_exe.o $(LIBS) -o parent.elf
- elf2x -q parent.elf
-
build/%.o: %.c
@mkdir -p $(dir $@)
- $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
-
+ $(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) $(INCLUDE) -c $< -o $@
-
+ $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@
+
clean:
- rm -rf build parent.elf parent.exe child.elf child.exe
+ rm -rf build