Page 1 of 1

My General Purpose makefile for Psy-Q PlayStation Projects

Posted: January 31st, 2016, 10:38 pm
by LameGuy64
This is an extensively written makefile script I wrote as my general makefile for PlayStation projects which I'm giving out as it may come really handy.

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.
Here's the makefile script (copy and paste into notepad and save as makefile without a file extension):

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

Re: My General Purpose makefile for Psy-Q PlayStation Projec

Posted: February 1st, 2016, 8:59 am
by gwald
LameGuy64 wrote:This is an extensively written makefile script I wrote as my general makefile for PlayStation projects which I'm giving out as it may come really handy.
Your make looks like it runs in cygwin ie: rm cp

You shouldn't need dogbox :lol: for the cdrom stuff:
This is what I use, it works in native winXP:

To make the iso:
http://opensourcepack.blogspot.co.il/p/cdrtools.html

To make it bootable: -- edit -- just notice you use win64, not sure if it works, but source is included :clap

http://www.psxdev.net/forum/viewtopic.php?f=60&t=448

Code: Select all

mkisofs -xa -o psx-iso.iso  -V GWALD -sysid PLAYSTATION ISOROOT
mkpsxiso psx-iso.iso psx-cd.bin infoeur.dat

I need dosbox for combine (NetYaroze) By any chance, do you have the source to combine/combine2 ? :crying or a win32 build of it :(

Re: My General Purpose makefile for Psy-Q PlayStation Projec

Posted: February 2nd, 2016, 12:41 am
by LameGuy64
gwald wrote: Your make looks like it runs in cygwin ie: rm cp
Actually, I used MSys' make and whoops, looks like the GNU Make link I provided does not point to a ready-to-use copy of the make program... So, I fixed the post up now with a stripped down copy of MSys which only contains make, rm and cp.
gwald wrote: You shouldn't need dogbox :lol: for the cdrom stuff:
This is what I use, it works in native winXP:
If you're producing plain iso images with no CD-XA data (for streaming audio or video), then your method is good enough for you.

Since I (and some others) use XA audio on my projects, I use BUILDCD which came with the PsyQ SDK as it is the only program I know of that can embed CD-XA data into the disc image plus it gives you full control as to how the files are ordered (by LBA)... Since BUILDCD is an old DOS program, I had to use Dosbox to get it to work on x64 systems. Yeah its slower but it has more options than mkisofs.
gwald wrote: I need dosbox for combine (NetYaroze) By any chance, do you have the source to combine/combine2 ? :crying or a win32 build of it :(
Well, I don't have the source of that program as I never used the Net Yaroze SDK at all... Sorry.

Re: My General Purpose makefile for Psy-Q PlayStation Projec

Posted: February 5th, 2016, 12:49 am
by SCPH-1002
@ gwald

In case that is what you looking for

Re: My General Purpose makefile for Psy-Q PlayStation Projec

Posted: February 5th, 2016, 10:16 am
by gwald
SCPH-1002 wrote:@ gwald

In case that is what you looking for

Wow nice one man! thanks heaps :praise
No more dosbox for me :clap

Re: My General Purpose makefile for Psy-Q PlayStation Projec

Posted: February 6th, 2016, 5:56 am
by SCPH-1002
I also can offer combine2 but only a precompiled build.
Is there something else what you are looking for about Net Yaroze stuff?

Feel free to ask

Re: My General Purpose makefile for Psy-Q PlayStation Projec

Posted: February 11th, 2016, 5:28 pm
by gwald
I had huge problems with that one lol
It broke my workflow and it took me a day to find out that combine2 didn't work 100% :/
Anyway, i've combined all the source code to make a single exe.. which works very well for me, in winXP+ and win98 :)
Thank again for the code :)

Re: My General Purpose makefile for Psy-Q PlayStation Projec

Posted: February 13th, 2016, 3:43 am
by SCPH-1002
I'm sorry about your trouble with combine2 and also glad to read about your success with the source.

Re: My General Purpose makefile for Psy-Q PlayStation Projects

Posted: July 22nd, 2018, 4:08 pm
by NITROYUASH
If i can't use PSYMAKE, what i need to use instead? make.exe from msys/bin?

Re: My General Purpose makefile for Psy-Q PlayStation Projects

Posted: July 22nd, 2018, 8:56 pm
by LameGuy64
Yes. But if you're using it in Win98, I recommend using MinGW's make (mingw32-make) because msys' make is a little buggy on it and will end up deleting your source files during a clean operation when using my makefile.

Cygwin may work but I haven't tested it yet.

Re: My General Purpose makefile for Psy-Q PlayStation Projects

Posted: July 23rd, 2018, 11:24 pm
by NITROYUASH
Anyone can help me with creating correct MAKEFILE for mingw32-make? Trying to compile from Win7x64 (patched CPE2X)
I did it! :>