It can compile both C and MIP source files as individual object files which will then be linked together to produce a cpe and exe file of the compiled program. Plus, it also has a target to produce an iso image of your project if a proper cti script is specified. However, it only works on GNU Make which means that it will not work on the extremely outdated and useless PSYMAKE.
Unlike the batch file method that most people here seem to use, compiling using a makefile like this with GNU Make is more efficient especially when working on large projects as you can split code across multiple C files and GNU Make will only compile the files that have been modified since the last compile (in other words, faster compile times especially when using the -j 2 or -j 4 switch on make).
You will need the following programs/tools to get this makefile to work:
Dosbox (for iso creation to work on 64-bit systems)
cpe2x (32-bit replacement of cpe2x that came with the Psy-Q SDK)
And msys-lite.zip attached to this post which contains the make program.
Setting up:
- Install Dosbox as you would with pretty much any installer program.
- You may want to go into Dosbox's options and set the cycles variable to max.
- Extract cpe2x.exe from cpe2x.zip into your psyq\bin folder.
- Extract the bin and etc folders inside msys.zip into your psyq folder. Make sure that the bin folder will merge its contents into the already existing bin folder.
- If you haven't already, you may want to add a path to your PsyQ SDK's bin folder into your PATH environment variable.
Code: Select all
#---------------------------------------------------------------------------------
# General-purpose makefile for Psy-Q PlayStation projects by Lameguy64
# 2016 Meido-Tek Productions
# Supports compiling C and MIP assembly source files as well as disc image
# creation for convenience (requires Dosbox if you're using a 64-bit version of windows).
# NOTE: Do not use PSYMAKE that came with the Psy-Q SDK to execute this makefile!
# Use GNU Make that comes included with MinGW-GCC and similar compilers instead or
# get a standalone copy of it here: https://www.gnu.org/software/make/
#---------------------------------------------------------------------------------
# Target name (or project name) for compiled executable and iso image file
TARGET = myproject
# File name of CTI script file (optional, required for iso creation)
CTIFILE = mydisc.cti
# Source directories
# (can be blank if your source files are in the same directory as the makefile)
SOURCES =
# C compiler flags
CFLAGS = -Wall -O3
# Executable load address (0x80010000 is the standard load address)
PROGADDR = 0x80010000
#---------------------------------------------------------------------------------
# Executable names of the C compiler and assembler
CC = ccpsx
ASM = asmpsx
# DOS emulator path (starting from the Program Files directory)
DOSEMU = DOSBox-0.74\DOSBox.exe
# Search directories for C and MIP files
CFILES = $(notdir $(wildcard ./*.c)) $(foreach dir,$(SOURCES),$(wildcard $(dir)/*.c))
AFILES = $(notdir $(wildcard ./*.mip)) $(foreach dir,$(SOURCES),$(wildcard $(dir)/*.mip))
# Generate file names for the object files
OFILES = $(CFILES:.c=.obj) $(AFILES:.mip=.obj)
#---------------------------------------------------------------------------------
# Default target, compiles all C and MIP source files found
all: $(OFILES)
$(CC) -Xo$(PROGADDR) $(CFLAGS) $(OFILES) -o $(TARGET).cpe
cpe2x $(TARGET).cpe
# Compile C source
%.obj: %.c
rm -f $(TARGET).cpe
$(CC) $(CFLAGS) -c $< -o $@
# Compile MIP assembler source
# For some reason, asmpsx would not take program arguments properly when
# executed through GNU Make. As a workaround, a temporary batch file had to be
# created so that asmpsx can take the arguments properly.
%.obj: %.mip
rm -f $(TARGET).cpe
@echo $(ASM) /l $<,$@ >_asm.bat
@echo exit >>_asm.bat
cmd < _asm.bat
rm -f _asm.bat
#---------------------------------------------------------------------------------
# Build iso image
# Produces buildcd.log on x64 platforms
iso:
rm -f $(TARGET).img
cp -f \psyq\cdgen\lcnsfile\licensea.dat licensea.dat
ifdef PROGRAMW6432
cp -f \psyq\bin\buildcd.exe _buildcd.exe
@echo @echo off >_buildcd.bat
@echo cls >>_buildcd.bat
@echo echo Image file is being created... >>_buildcd.bat
@echo _buildcd -l $(CTIFILE) -i$(TARGET).img \>buildcd.log >>_buildcd.bat
@echo exit >>_buildcd.bat
@"$(PROGRAMFILES)\$(DOSEMU)" _buildcd.bat
rm -f _buildcd.exe
else
buildcd -l $(CTIFILE) -i$(TARGET).img
endif
rm -f CDW900E.TOC
rm -f QSHEET.TOC
@echo stripiso s 2352 $(TARGET).img $(TARGET).iso >_buildcd.bat
@echo exit >>_buildcd.bat
@cmd < _buildcd.bat
rm -f $(TARGET).img
rm -f _buildcd.bat
rm -f licensea.dat
#---------------------------------------------------------------------------------
# Clean target, delete all object files, target executable and disc image
clean:
rm -f $(OFILES) $(TARGET).cpe $(TARGET).exe $(TARGET).iso