Skip to content

Commit 51dd0ef

Browse files
committed
Overhaul build script to be more like a makefile.
1 parent 34733dd commit 51dd0ef

File tree

1 file changed

+43
-24
lines changed

1 file changed

+43
-24
lines changed

OpenOrbis/build.bat

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,71 @@
11
SETLOCAL EnableDelayedExpansion
22

3-
REM Libraries to link in
4-
SET libraries=-lc -lkernel
3+
SET TOOLCHAIN=%OO_PS4_TOOLCHAIN%
54

6-
REM Read the script arguments into local vars
7-
SET intdir=%1
8-
SET targetname=%~2
9-
SET outputPath=%~3
5+
SET LIBS=-lc -lkernel
106

11-
SET outputElf=%intdir%%targetname%.elf
12-
SET outputOelf=%intdir%%targetname%.oelf
13-
SET outputPrx=%intdir%%targetname%.prx
14-
SET outputStub=%intdir%%targetname%_stub.so
7+
REM Compiler options. You likely won't need to touch these.
8+
SET CC=clang
9+
SET CXX=clang++
10+
SET LD=ld.lld
11+
12+
SET TARGET=%~2
13+
14+
SET ODIR=%1
15+
SET SDIR=%~3
16+
17+
REM Trim trailing \'s
18+
IF %TOOLCHAIN:~-1%==\ SET TOOLCHAIN=%TOOLCHAIN:~0,-1%
19+
IF %ODIR:~-1%==\ SET ODIR=%ODIR:~0,-1%
20+
IF %SDIR:~-1%==\ SET SDIR=%SDIR:~0,-1%
21+
22+
SET IDIRS="-I%TOOLCHAIN%\include"
23+
SET LDIRS="-L%TOOLCHAIN%\lib"
24+
25+
SET CFLAGS=-cc1 -triple x86_64-scei-ps4-elf -munwind-tables %IDIRS% -emit-obj
26+
SET CXXFLAGS=%CFLAGS%
27+
SET LFLAGS=-m elf_x86_64 -pie --version-script="%SDIR%\%TARGET%.version" --script "%TOOLCHAIN%\link.x" --eh-frame-hdr %LDIRS% %LIBS% --verbose "%TOOLCHAIN%\lib\crtlib.o"
28+
29+
SET STUBCFLAGS=-target x86_64-pc-linux-gnu -ffreestanding -nostdlib -fno-builtin -fPIC -c %IDIRS%
30+
SET STUBCXXFLAGS=%STUBCFLAGS%
31+
SET STUBLFLAGS=-target x86_64-pc-linux-gnu -shared -fuse-ld=lld -ffreestanding -nostdlib -fno-builtin %LDIRS% %LIBS%
32+
33+
REM Make!
1534

16-
REM Compile object files for all the source files
1735
FOR %%f in (..\*.c) DO (
1836
ECHO Compiling %%~f...
19-
clang -cc1 -triple x86_64-scei-ps4-elf -munwind-tables -I"%OO_PS4_TOOLCHAIN%\include" -emit-obj -o %intdir%\%%~nf.o "%%~f"
37+
%CC% %CFLAGS% -o %ODIR%\%%~nf.o "%%~f"
2038
)
2139
FOR %%f in (..\*.cpp) DO (
2240
ECHO Compiling %%~f...
23-
clang++ -cc1 -triple x86_64-scei-ps4-elf -munwind-tables -I"%OO_PS4_TOOLCHAIN%\include" -emit-obj -o %intdir%\%%~nf.o "%%~f"
41+
%CXX% %CXXFLAGS% -o %ODIR%\%%~nf.o "%%~f"
2442
)
2543

2644
REM Get a list of object files for linking
27-
SET obj_files=
28-
FOR %%f IN (%intdir%\\*.o) DO SET obj_files=!obj_files! .\%%f
45+
SET OBJS=
46+
FOR %%f IN (%ODIR%\*.o) DO SET OBJS=!OBJS! %%f
2947

3048
REM Link the input ELF
3149
ECHO Linking...
32-
ld.lld -m elf_x86_64 -pie --version-script="%targetname%.version" --script "%OO_PS4_TOOLCHAIN%\link.x" --eh-frame-hdr -o "%outputElf%" "-L%OO_PS4_TOOLCHAIN%\lib" -lc -lkernel --verbose "%OO_PS4_TOOLCHAIN%\lib\crtlib.o" %obj_files%
50+
%LD% %OBJS% -o "%ODIR%\%TARGET%.elf" %LFLAGS%
3351

3452
REM Create stub shared libraries
3553
FOR %%f in (..\*.c) DO (
36-
clang -target x86_64-pc-linux-gnu -ffreestanding -nostdlib -fno-builtin -fPIC -c -I"%OO_PS4_TOOLCHAIN%\include" -o %intdir%\%%~nf.o.stub "%%~f"
54+
%CC% %STUBCFLAGS% -o %ODIR%\%%~nf.o.stub "%%~f"
3755
)
3856
FOR %%f in (..\*.cpp) DO (
39-
clang++ -target x86_64-pc-linux-gnu -ffreestanding -nostdlib -fno-builtin -fPIC -c -I"%OO_PS4_TOOLCHAIN%\include" -o %intdir%\%%~nf.o.stub "%%~f"
57+
%CXX% %STUBCXXFLAGS% -o %ODIR%\%%~nf.o.stub "%%~f"
4058
)
4159

42-
SET stub_obj_files=
43-
FOR %%f in (%intdir%\\*.o.stub) DO SET stub_obj_files=!stub_obj_files! .\%%f
60+
SET STUBOBJS=
61+
FOR %%f in (%ODIR%\*.o.stub) DO SET STUBOBJS=!STUBOBJS! .\%%f
4462

45-
clang++ -target x86_64-pc-linux-gnu -shared -fuse-ld=lld -ffreestanding -nostdlib -fno-builtin "-L%OO_PS4_TOOLCHAIN%\lib" %libraries% %stub_obj_files% -o "%outputStub%"
63+
%CC% %STUBOBJS% -o "%ODIR%\%TARGET%_stub.so" %STUBLFLAGS%
4664

4765
REM Create the prx
48-
%OO_PS4_TOOLCHAIN%\bin\windows\create-lib.exe -in "%outputElf%" --out "%outputOelf%" --paid 0x3800000000000011
66+
ECHO Creating OELF/PRX...
67+
%TOOLCHAIN%\bin\windows\create-lib.exe -in "%ODIR%\%TARGET%.elf" -out "%ODIR%\%TARGET%.oelf"
4968

5069
REM Cleanup
51-
COPY "%outputPrx%" "%outputPath%\%targetname%.prx"
52-
DEL "%outputPrx%"
70+
COPY "%ODIR%\%TARGET%.prx" "%SDIR%\%TARGET%.prx"
71+
DEL "%ODIR%\%TARGET%.prx"

0 commit comments

Comments
 (0)