Usual makefile

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Rav
Posts: 11
Joined: Fri Jun 01, 2007 2:56 am
Location: France
Contact:

Usual makefile

Post by Rav »

I wonder if it's possible to use a standard makefile : I mean something with

Code: Select all

all: main.o
  gcc main.o

main.o: a.c
  gcc -c a.c -o a.o
Because it's hard for me to understand this one :

Code: Select all

TARGET = Sprite
OBJS = Fonctions/framebuffer.o Fonctions/graphics.o Sprite.o

CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

LIBDIR =
LIBS = -lpspgu -lpng -lz -lm -lstdc++
LDFLAGS =

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Sprite

PSPSDK = /usr/local/pspdev/psp/sdk/
include $(PSPSDK)/lib/build.mak
Can someone give me a file with the structure explained above ? Thanks
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

Sure it is but the end result will be little different to what you have already, in fact it will probably be worse :)
Rav
Posts: 11
Joined: Fri Jun 01, 2007 2:56 am
Location: France
Contact:

Hum...

Post by Rav »

I think that I should play with this :

Code: Select all

all: $(EXTRA_TARGETS) $(FINAL_TARGET)

kxploit: $(TARGET).elf $(PSP_EBOOT_SFO)
	mkdir -p "$(TARGET)"
	$(STRIP) $(TARGET).elf -o $(TARGET)/$(PSP_EBOOT)
	mkdir -p "$(TARGET)%"
	$(PACK_PBP) "$(TARGET)%/$(PSP_EBOOT)" $(PSP_EBOOT_SFO) $(PSP_EBOOT_ICON)  \
		$(PSP_EBOOT_ICON1) $(PSP_EBOOT_UNKPNG) $(PSP_EBOOT_PIC1)  \
		$(PSP_EBOOT_SND0) NULL $(PSP_EBOOT_PSAR)

SCEkxploit: $(TARGET).elf $(PSP_EBOOT_SFO)
	mkdir -p "__SCE__$(TARGET)"
	$(STRIP) $(TARGET).elf -o __SCE__$(TARGET)/$(PSP_EBOOT)
	mkdir -p "%__SCE__$(TARGET)"
	$(PACK_PBP) "%__SCE__$(TARGET)/$(PSP_EBOOT)" $(PSP_EBOOT_SFO) $(PSP_EBOOT_ICON)  \
		$(PSP_EBOOT_ICON1) $(PSP_EBOOT_UNKPNG) $(PSP_EBOOT_PIC1)  \
		$(PSP_EBOOT_SND0) NULL $(PSP_EBOOT_PSAR)

$(TARGET).elf: $(OBJS) $(EXPORT_OBJ)
	$(LINK.c) $^ $(LIBS) -o $@
	$(FIXUP) $@

$(TARGET_LIB): $(OBJS)
	$(AR) cru $@ $(OBJS)
	$(RANLIB) $@

$(PSP_EBOOT_SFO): 
	$(MKSFO) '$(PSP_EBOOT_TITLE)' $@

ifeq ($(BUILD_PRX),1)
$(PSP_EBOOT): $(TARGET).prx $(PSP_EBOOT_SFO)
	$(PACK_PBP) $(PSP_EBOOT) $(PSP_EBOOT_SFO) $(PSP_EBOOT_ICON)  \
		$(PSP_EBOOT_ICON1) $(PSP_EBOOT_UNKPNG) $(PSP_EBOOT_PIC1)  \
		$(PSP_EBOOT_SND0)  $(TARGET).prx $(PSP_EBOOT_PSAR)
else
$(PSP_EBOOT): $(TARGET).elf $(PSP_EBOOT_SFO)
	$(STRIP) $(TARGET).elf -o $(TARGET)_strip.elf
	$(PACK_PBP) $(PSP_EBOOT) $(PSP_EBOOT_SFO) $(PSP_EBOOT_ICON)  \
		$(PSP_EBOOT_ICON1) $(PSP_EBOOT_UNKPNG) $(PSP_EBOOT_PIC1)  \
		$(PSP_EBOOT_SND0)  $(TARGET)_strip.elf $(PSP_EBOOT_PSAR)
	-rm -f $(TARGET)_strip.elf
endif

%.prx: %.elf
	psp-prxgen $< $@

%.c&#58; %.exp
	psp-build-exports -b $< > $@
But I guess I'll need time to understand all these vars ^^.

But with that, I'll have a better understanding of what is hapenning.
Rav
Posts: 11
Joined: Fri Jun 01, 2007 2:56 am
Location: France
Contact:

Here is my usual makefile

Post by Rav »

I've modified the makefile in a way I better understand, here it comes :

Code: Select all

TARGET = Sprite2D
OBJS = Functions/framebuffer.o Functions/graphics.o ISprite.o Sprite2D.o TestSprite2D.o

CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

LIBDIR =
LIBS = -lpspgu -lpng -lz -lm -lstdc++
LDFLAGS =

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Sprite

PSPSDK = /usr/local/pspdev/psp/sdk

###########################################################################################################
# PSP Software Development Kit - http&#58;//www.pspdev.org
# -----------------------------------------------------------------------
# Licensed under the BSD license, see LICENSE in PSPSDK root for details.
#
# build.mak - Base makefile for projects using PSPSDK.
#
# Copyright &#40;c&#41; 2005 Marcus R. Brown <[email protected]>
# Copyright &#40;c&#41; 2005 James Forshaw <[email protected]>
# Copyright &#40;c&#41; 2005 John Kelley <[email protected]>
#
# $Id&#58; build.mak 2214 2007-04-12 20&#58;04&#58;48Z jim $

# Note&#58; The PSPSDK make variable must be defined before this file is included.
ifeq &#40;$&#40;PSPSDK&#41;,&#41;
$&#40;error $$&#40;PSPSDK&#41; is undefined.  Use "PSPSDK &#58;= $$&#40;shell psp-config --pspsdk-path&#41;" in your Makefile&#41;
endif

CC       = psp-gcc
CXX      = psp-g++
AS       = psp-gcc
LD       = psp-gcc
AR       = psp-ar
RANLIB   = psp-ranlib
STRIP    = psp-strip
MKSFO    = mksfo
PACK_PBP = pack-pbp
FIXUP    = psp-fixup-imports

# Add in PSPSDK includes and libraries.
INCDIR   &#58;= $&#40;INCDIR&#41; . $&#40;PSPSDK&#41;/include
LIBDIR   &#58;= $&#40;LIBDIR&#41; . $&#40;PSPSDK&#41;/lib

CFLAGS   &#58;= $&#40;addprefix -I,$&#40;INCDIR&#41;&#41; $&#40;CFLAGS&#41;
CXXFLAGS &#58;= $&#40;CFLAGS&#41; $&#40;CXXFLAGS&#41;
ASFLAGS  &#58;= $&#40;CFLAGS&#41; $&#40;ASFLAGS&#41;

ifeq &#40;$&#40;PSP_FW_VERSION&#41;,&#41;
PSP_FW_VERSION=150
endif

CFLAGS += -D_PSP_FW_VERSION=$&#40;PSP_FW_VERSION&#41;

ifeq &#40;$&#40;BUILD_PRX&#41;,1&#41;
LDFLAGS  &#58;= $&#40;addprefix -L,$&#40;LIBDIR&#41;&#41; -specs=$&#40;PSPSDK&#41;/lib/prxspecs -Wl,-q,-T$&#40;PSPSDK&#41;/lib/linkfile.prx $&#40;LDFLAGS&#41;
EXTRA_CLEAN += $&#40;TARGET&#41;.elf
# Setup default exports if needed
ifdef PRX_EXPORTS
EXPORT_OBJ=$&#40;patsubst %.exp,%.o,$&#40;PRX_EXPORTS&#41;&#41;
EXTRA_CLEAN += $&#40;EXPORT_OBJ&#41;
else 
EXPORT_OBJ=$&#40;PSPSDK&#41;/lib/prxexports.o
endif
else
LDFLAGS  &#58;= $&#40;addprefix -L,$&#40;LIBDIR&#41;&#41; $&#40;LDFLAGS&#41;
endif

# Library selection.  By default we link with Newlib's libc.  Allow the
# user to link with PSPSDK's libc if USE_PSPSDK_LIBC is set to 1.

ifeq &#40;$&#40;USE_KERNEL_LIBC&#41;,1&#41;
# Use the PSP's kernel libc
PSPSDK_LIBC_LIB = 
CFLAGS &#58;= -I$&#40;PSPSDK&#41;/include/libc $&#40;CFLAGS&#41;
else
ifeq &#40;$&#40;USE_PSPSDK_LIBC&#41;,1&#41;
# Use the pspsdk libc
PSPSDK_LIBC_LIB = -lpsplibc
CFLAGS &#58;= -I$&#40;PSPSDK&#41;/include/libc $&#40;CFLAGS&#41;
else
# Use newlib &#40;urgh&#41;
PSPSDK_LIBC_LIB = -lc
endif
endif


# Link with following default libraries.  Other libraries should be specified in the $&#40;LIBS&#41; variable.
# TODO&#58; This library list needs to be generated at configure time.
#
ifeq &#40;$&#40;USE_KERNEL_LIBS&#41;,1&#41;
PSPSDK_LIBS = -lpspdebug -lpspdisplay_driver -lpspctrl_driver -lpspsdk
LIBS     &#58;= $&#40;LIBS&#41; $&#40;PSPSDK_LIBS&#41; $&#40;PSPSDK_LIBC_LIB&#41; -lpspkernel
else
ifeq &#40;$&#40;USE_USER_LIBS&#41;,1&#41;
PSPSDK_LIBS = -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk
LIBS     &#58;= $&#40;LIBS&#41; $&#40;PSPSDK_LIBS&#41; $&#40;PSPSDK_LIBC_LIB&#41; -lpspnet \
			-lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility \
			-lpspuser
else
PSPSDK_LIBS = -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk
LIBS     &#58;= $&#40;LIBS&#41; $&#40;PSPSDK_LIBS&#41; $&#40;PSPSDK_LIBC_LIB&#41; -lpspnet \
			-lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility \
			-lpspuser -lpspkernel
endif
endif

# Define the overridable parameters for EBOOT.PBP
ifndef PSP_EBOOT_TITLE
PSP_EBOOT_TITLE = $&#40;TARGET&#41;
endif

ifndef PSP_EBOOT_SFO
PSP_EBOOT_SFO = PARAM.SFO
endif

ifndef PSP_EBOOT_ICON
PSP_EBOOT_ICON = NULL
endif

ifndef PSP_EBOOT_ICON1
PSP_EBOOT_ICON1 = NULL
endif

ifndef PSP_EBOOT_UNKPNG
PSP_EBOOT_UNKPNG = NULL
endif

ifndef PSP_EBOOT_PIC1
PSP_EBOOT_PIC1 = NULL
endif

ifndef PSP_EBOOT_SND0
PSP_EBOOT_SND0 = NULL
endif

ifndef PSP_EBOOT_PSAR
PSP_EBOOT_PSAR = NULL
endif

ifndef PSP_EBOOT
PSP_EBOOT = EBOOT.PBP
endif

ifeq &#40;$&#40;BUILD_PRX&#41;,1&#41;
ifneq &#40;$&#40;TARGET_LIB&#41;,&#41;
$&#40;error TARGET_LIB should not be defined when building a prx&#41;
else
FINAL_TARGET = $&#40;TARGET&#41;.prx
endif
else
ifneq &#40;$&#40;TARGET_LIB&#41;,&#41;
FINAL_TARGET = $&#40;TARGET_LIB&#41;
else
FINAL_TARGET = $&#40;TARGET&#41;.elf
endif
endif

###########################################################################################################

all&#58; $&#40;EXTRA_TARGETS&#41; $&#40;FINAL_TARGET&#41;

include Functions/Makefile
	
#Functions/graphics.o&#58; Functions/graphics.c Functions/graphics.h  Functions/framebuffer.o
#	$&#40;CC&#41; -o $@ -c $< $&#40;CFLAGS&#41;
	
ISprite.o&#58; ISprite.cpp ISprite.hpp
	$&#40;CC&#41; -o $@ -c $< $&#40;CFLAGS&#41;
	
Sprite2D.o&#58; Sprite2D.cpp Sprite2D.hpp Functions/graphics.o
	$&#40;CC&#41; -o $@ -c $< $&#40;CFLAGS&#41;
	
TestSprite2D.o&#58; TestSprite2D.cpp Sprite2D.hpp Sprite2D.cpp
	$&#40;CC&#41; -o $@ -c $< $&#40;CFLAGS&#41;
	
###########################################################################################################

kxploit&#58; $&#40;TARGET&#41;.elf $&#40;PSP_EBOOT_SFO&#41;
	mkdir -p "$&#40;TARGET&#41;"
	$&#40;STRIP&#41; $&#40;TARGET&#41;.elf -o $&#40;TARGET&#41;/$&#40;PSP_EBOOT&#41;
	mkdir -p "$&#40;TARGET&#41;%"
	$&#40;PACK_PBP&#41; "$&#40;TARGET&#41;%/$&#40;PSP_EBOOT&#41;" $&#40;PSP_EBOOT_SFO&#41; $&#40;PSP_EBOOT_ICON&#41;  \
		$&#40;PSP_EBOOT_ICON1&#41; $&#40;PSP_EBOOT_UNKPNG&#41; $&#40;PSP_EBOOT_PIC1&#41;  \
		$&#40;PSP_EBOOT_SND0&#41; NULL $&#40;PSP_EBOOT_PSAR&#41;

SCEkxploit&#58; $&#40;TARGET&#41;.elf $&#40;PSP_EBOOT_SFO&#41;
	mkdir -p "__SCE__$&#40;TARGET&#41;"
	$&#40;STRIP&#41; $&#40;TARGET&#41;.elf -o __SCE__$&#40;TARGET&#41;/$&#40;PSP_EBOOT&#41;
	mkdir -p "%__SCE__$&#40;TARGET&#41;"
	$&#40;PACK_PBP&#41; "%__SCE__$&#40;TARGET&#41;/$&#40;PSP_EBOOT&#41;" $&#40;PSP_EBOOT_SFO&#41; $&#40;PSP_EBOOT_ICON&#41;  \
		$&#40;PSP_EBOOT_ICON1&#41; $&#40;PSP_EBOOT_UNKPNG&#41; $&#40;PSP_EBOOT_PIC1&#41;  \
		$&#40;PSP_EBOOT_SND0&#41; NULL $&#40;PSP_EBOOT_PSAR&#41;

$&#40;TARGET&#41;.elf&#58; $&#40;OBJS&#41; $&#40;EXPORT_OBJ&#41;
	$&#40;LINK.c&#41; $^ $&#40;LIBS&#41; -o $@
	$&#40;FIXUP&#41; $@

$&#40;TARGET_LIB&#41;&#58; $&#40;OBJS&#41;
	$&#40;AR&#41; cru $@ $&#40;OBJS&#41;
	$&#40;RANLIB&#41; $@

$&#40;PSP_EBOOT_SFO&#41;&#58; 
	$&#40;MKSFO&#41; '$&#40;PSP_EBOOT_TITLE&#41;' $@

ifeq &#40;$&#40;BUILD_PRX&#41;,1&#41;
$&#40;PSP_EBOOT&#41;&#58; $&#40;TARGET&#41;.prx $&#40;PSP_EBOOT_SFO&#41;
	$&#40;PACK_PBP&#41; $&#40;PSP_EBOOT&#41; $&#40;PSP_EBOOT_SFO&#41; $&#40;PSP_EBOOT_ICON&#41;  \
		$&#40;PSP_EBOOT_ICON1&#41; $&#40;PSP_EBOOT_UNKPNG&#41; $&#40;PSP_EBOOT_PIC1&#41;  \
		$&#40;PSP_EBOOT_SND0&#41;  $&#40;TARGET&#41;.prx $&#40;PSP_EBOOT_PSAR&#41;
else
$&#40;PSP_EBOOT&#41;&#58; $&#40;TARGET&#41;.elf $&#40;PSP_EBOOT_SFO&#41;
	$&#40;STRIP&#41; $&#40;TARGET&#41;.elf -o $&#40;TARGET&#41;_strip.elf
	$&#40;PACK_PBP&#41; $&#40;PSP_EBOOT&#41; $&#40;PSP_EBOOT_SFO&#41; $&#40;PSP_EBOOT_ICON&#41;  \
		$&#40;PSP_EBOOT_ICON1&#41; $&#40;PSP_EBOOT_UNKPNG&#41; $&#40;PSP_EBOOT_PIC1&#41;  \
		$&#40;PSP_EBOOT_SND0&#41;  $&#40;TARGET&#41;_strip.elf $&#40;PSP_EBOOT_PSAR&#41;
	-rm -f $&#40;TARGET&#41;_strip.elf
endif

%.prx&#58; %.elf
	psp-prxgen $< $@

%.c&#58; %.exp
	psp-build-exports -b $< > $@

clean&#58; 
	-rm -f $&#40;FINAL_TARGET&#41; $&#40;EXTRA_CLEAN&#41; $&#40;OBJS&#41; $&#40;PSP_EBOOT_SFO&#41; $&#40;PSP_EBOOT&#41; $&#40;EXTRA_TARGETS&#41;

rebuild&#58; clean all
I had to put my rules above the "exotic" ones in order to have them used. I tried adding my rules at the end of the original makefile but it didn't work.
User avatar
Wally
Posts: 663
Joined: Mon Sep 26, 2005 11:25 am

Post by Wally »

i like that one, it makes much more sense
ufoz
Posts: 86
Joined: Thu Nov 10, 2005 2:36 am
Location: Tokyo
Contact:

Post by ufoz »

TyRaNiD wrote:Sure it is but the end result will be little different to what you have already, in fact it will probably be worse :)
Lo and behold...
Post Reply