Improved Makefile For PSP C/C++ Game Programming

This Makefile improves on the one included in the default PSPSDK from ps2dev.org (which always seems to be down by the way?).

Improvements:
  • Changes in header files cause recompilation of source files (if needed).

    You may not realize this, but unless you have a Makefile dependency on each header file that your C/C++ file includes, when that header file changes (and it will, if you wrote it), you will need to clean your project and recompile. This Makefile avoids all that mess by managing it for you with mini Makefiles called dependency files (.d)

  • Easy addition of icons to your eboot.

    With ICON0.PNG and title screen backdrop for menu with PIC1.PNG etc (uncomment and change the names of ICON or PIC to your image if you want to use it).

  • Addition of PSPSDK tags for vim and your project

    With "make sdk_ctags" to build the PSPSDK tags file and there already is automatic tag generation for your local project files when you compile (it will generate an ignored error if you don't have ctags enabled. Just emlinate the lines: "$(MAKE) tags" if it annoys you)

TARGET = YourPSPGameName

#---------------------------------------------------------------------------------
#  Icon and picture for your game in menu
#---------------------------------------------------------------------------------
#   Uncomment and change to your picture name
#PSP_EBOOT_PIC1 = PIC1.PNG
#PSP_EBOOT_ICON = ICON0.PNG

CFILES := $(wildcard *.c)
CPPFILES := $(wildcard *.cpp)

export OBJS = \
       $(CFILES:.c=.o) \
       $(CPPFILES:.cpp=.o) \

#---------------------------------------------------------------------------------
## Any other build targets you want to add
#---------------------------------------------------------------------------------
#OBJS += logo.o

CDEPS = $(CFILES:.c=.d)
CPPDEPS = $(CPPFILES:.cpp=.d)
DEPS = $(CDEPS) $(CPPDEPS)


INCDIR = ./

INCDIR  +=  $(PSPSDK)/include
CFLAGS = -g -G0 -Wall -DPSP_BUILD
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

LIBDIR =
LDFLAGS =
LIBS= -lpspmp3 -lc -lpspaudio -lpspgum -lpspgu -lm -lpsprtc -lstdc++

EXTRA_TARGETS = EBOOT.PBP
EXTRA_CLEAN = $(DEPS)  
PSP_EBOOT_TITLE = $(TARGET)


export PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak


#---------------------------------------------------------------------------------
#    Remake editor tags
#---------------------------------------------------------------------------------
tags: $(SOURCES)
  -ctags -R --sort=yes --c++-kinds=+cdefgmnpstux \
    --fields=+iaKS --extra=+q ./ ../

ctags: tags

sdk_ctags:
  -ctags -R -o $(HOME)/.vim/ctags/psp_cpp --sort=yes --c++-kinds=+cdefgmnpstux \
    --fields=+iaKS --extra=+q $(INCDIR)


#---------------------------------------------------------------------------------
# Rules for building cpp files (if you have them)
#---------------------------------------------------------------------------------
%.o: %.cpp
  @echo $(notdir $<)
  $(MAKE) tags
  $(CXX) -MMD -MP -MF $*.d $(CXXFLAGS) -c $< -o $@
  
#---------------------------------------------------------------------------------
#  Rules for building c files if you have them
#---------------------------------------------------------------------------------
%.o:  %.c
  @echo $(notdir $<)
  $(MAKE) tags
  $(CC) -MMD -MP -MF $*.d $(CFLAGS) -c $< -o $@


-include $(DEPS)


#---------------------------------------------------------------------------------
#   Maybe for a logo/image target, you could use something like this
#---------------------------------------------------------------------------------
#logo.o: logo.raw
# bin2o -i logo.raw logo.o logo

#---------------------------------------------------------------------------------
#   Get rid of all the intermediary makefiles (.d files)
#---------------------------------------------------------------------------------
clean-deps:
  -rm $(DEPS)

#---------------------------------------------------------------------------------
#  Maybe use this target if you have usbhostfs_pc running and want to use
#    psplink
#---------------------------------------------------------------------------------
run:
  pspsh -e $(PWD)/EBOOT

Comments

Popular posts from this blog

Development on Android NDK Tutorial - Gluing C++ Native Code to Java

Creating a Fake Refraction, Bubble Shader for your 2D Godot Game!

Godot Tutorial: How to read all files in EVERY sub directory (Breadth/Depth first Search)