My NEW General Purpose Makefile for PlayStation Projects

Downloadable items posted by PSXDEV members are within this forum.
Post Reply
User avatar
LameGuy64
Verified
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 388
Joined: Apr 10, 2013
I am a: Hobbyist Game Developer
Motto: Commercial or not, play it!
PlayStation Model: H2000/7000
Location: Philippines
Contact:

My NEW General Purpose Makefile for PlayStation Projects

Post by LameGuy64 » April 10th, 2017, 12:40 pm

Thought of posting my new makefile script as a far superior follow-up to my old one which I've posted here a long time ago. Unlike my previous makefile script, this one now supports assembling ASM source (with an .s file extension), uses mkpsxiso for ISO builds (which does not require Dosbox) and supports separate options for debug capable systems (such as a DTL-H2000 equipped PC). It is also written much better than my previous makefile script and therefore, should perform better all around.

To run this makefile, I recommend using mingw32-make from the MinGW GCC Compiler suite (also known as TDM-GCC) usually bundled with CodeBlocks and Dev-C++.

You may also need to install msys for the clean rule to work as I cannot use the del command to delete files under make so I'm using rm from msys to delete files instead:
https://sourceforge.net/projects/devkit ... e/download

However, do not use msys' make program as it is bugged under Win9x when you clean which will result in deleted source files and that asmpsx cannot read its arguments correctly when run by it.

For ISO build to work, you will need mkpsxiso and Orion's Win32 version of cpe2x as the version included with the SDK is an old DOS application and will not work under 64-bit versions of Windows.
mkpsxiso: https://github.com/Lameguy64/mkpsxiso
cpe2x: http://onorisoft.free.fr/rdl.php?url=psx/cpe2x.zip

Code: Select all

#---------------------------------------------------------------------------------
# Lameguy's general-purpose makefile for PSX development
# (for official PlayStation SDK)
# 2017 Meido-Tek Productions
#
# Use mingw32-make (included with MinGW GCC compiler) to run this makefile. You may
# also need to setup msys and assign it to your PATH environment to get the clean
# and cleanall rules to work as make cannot execute del and rm is used instead.
#
# Download msys here:
# https://sourceforge.net/projects/devkitpro/files/tools/msys%201.0.17/msys-1.0.17-1.exe/download
#
# NOTE: Do not use msys' make program! Its bugged in Win9x and may delete your souce
# files when you clean and some programs such as asmpsx cannot read the arguments
# when run by it.
#
# For ISO build to work, you will need mkpsxiso and Orion's Win32 version of cpe2x.
# mkpsxiso: https://github.com/Lameguy64/mkpsxiso
# cpe2x: http://onorisoft.free.fr/rdl.php?url=psx/cpe2x.zip
#---------------------------------------------------------------------------------

#---------------------------------------------------------------------------------
# TARGET	- Name of the output
# PROGADDR	- Program load address (0x80010000 is the default)
# SOURCES	- Source directories (. for current directory)
# INCLUDES	- Include search directories
# ISOXML	- Name of mkpsxiso ISO project script
#---------------------------------------------------------------------------------
TARGET      = $(notdir $(CURDIR))
PROGADDR	= 0x80010000
SOURCES		= .
INCLUDES	=
ISOXML		=

#---------------------------------------------------------------------------------
# LIBDIRS	- Library search directories
# LIBS		- Libraries to link during linking stage
#---------------------------------------------------------------------------------
LIBDIRS		=
LIBS		=

#---------------------------------------------------------------------------------
# CFLAGS	- Base C compiler options
# AFLAGS	- Base assembler options
#---------------------------------------------------------------------------------
CFLAGS		= -Xm -Wall
AFLAGS		= /q /l

#---------------------------------------------------------------------------------
# Specific options to debug capable environments (debug options are only usable with
# SN Debugger and a DTL-H2000, 2500 or the Parallel Port based PsyQ/SN Blue Dongle)
# (you must set an H2000 environment variable with TRUE to compile with debug options)
#---------------------------------------------------------------------------------
ifeq "$(H2000)" "TRUE"
CFLAGS		+= -g -DH2000
AFLAGS		+= /zd
SYMFILE		= $(TARGET).sym
else
CFLAGS		+= -O2
SYMFILE		=
endif

#---------------------------------------------------------------------------------
## CC		- C compiler (usually ccpsx)
## AS		- Assembler (usually asmpsx)
#---------------------------------------------------------------------------------
CC			= ccpsx
AS			= asmpsx

#---------------------------------------------------------------------------------
# Parse source directories for source files
#---------------------------------------------------------------------------------
CFILES		= $(foreach dir,$(SOURCES),$(wildcard $(dir)/*.c))
AFILES		= $(foreach dir,$(SOURCES),$(wildcard $(dir)/*.s))

#---------------------------------------------------------------------------------
# Generate file names for object binaries
#---------------------------------------------------------------------------------
OFILES		= $(CFILES:.c=.obj) $(AFILES:.s=.obj)

#---------------------------------------------------------------------------------
# Default rule, compiles all source files
#---------------------------------------------------------------------------------
all: $(OFILES)
	$(CC) -Xo$(PROGADDR) $(CFLAGS) $(addprefix -L,$(LIBDIRS)) $(addprefix -l,$(LIBS)) $(OFILES) -o $(TARGET).cpe,$(SYMFILE),$(TARGET).map

#---------------------------------------------------------------------------------
# Clean-up rule
#---------------------------------------------------------------------------------
cleanall:
	rm -f $(OFILES) $(TARGET).cpe $(TARGET).sym $(TARGET).map

clean: cleanall

#---------------------------------------------------------------------------------
# ISO build rule (requires MKPSXISO)
#---------------------------------------------------------------------------------
iso:
	cpe2x $(TARGET).cpe
	mkpsxiso -q -y $(ISOXML)

#---------------------------------------------------------------------------------
# Rule for compiling C source
#---------------------------------------------------------------------------------
%.obj: %.c
	$(CC) $(CFLAGS) $(addprefix -I,$(INCLUDES)) -c $< -o $@

#---------------------------------------------------------------------------------
# Rule for assembling assembly source
#---------------------------------------------------------------------------------
%.obj: %.s
	$(AS) $(AFLAGS) $<,$@
Please don't forget to include my name if you share my work around. Credit where it is due.

Dev. Console: SCPH-7000 with SCPH-7501 ROM, MM3, PAL color fix, Direct AV ports, DB-9 port for Serial I/O, and a Xplorer FX with Caetla 0.35.

DTL-H2000 PC: Dell Optiplex GX110, Windows 98SE & Windows XP, Pentium III 933MHz, 384MB SDRAM, ATI Radeon 7000 VE 64MB, Soundblaster Audigy, 40GB Seagate HDD, Hitachi Lite-on CD-RW Drive, ZIP 250 and 3.5" Floppy.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests