How to use a makefile to automate PasForum compilation

Introduction

Creating a makefile with FPCMAKE offers automation. Want to rename all EXE or ELF files to POW or CGI extension after compiling? It is fairly simple in a make file.

UPDATE, 2008: Make files, although powerful, can become atrocious hard to maintain messes. Check out an alternative called PowBuild or FpMake instead of FpcMake/GnuMake.

Note: I've included below the way to rename all exe files to psp extension on MS Windows. On unix it is different since bash treats wildcards differently. I will update this makefile soon so you can see a simple rename or cp command on unix to do the job. (Update in Year 2008: This is another reason for choosing PowBuild or FpMake instead of make files)

#   PasForum: makefile.fpc
#

[package]
name=pasforum
version=0.2.0

[target]
programs=index login logout new_topic forum moderate register reply rules support
units=psp4umfunctions

[compiler]
options=-CX -Xs -XX
unittargetdir=.

targetdir=.

[clean]
files=$(wildcard *$(OEXT)) $(wildcard *$(PPUEXT))

[rules]
ifeq ($(OS_TARGET),win32) 
all: fpc_all
        copy *$(EXEEXT) *.psp 
endif

ifeq ($(OS_TARGET),linux) 
all: fpc_all
endif

[install]
fpcpackage=n
After creating the above text file, save it as makefile.fpc. Run the command prompt and type in fpcmake in the same directory that the makefile.fpc is in (pasforum source directory).

Now type in make to test your make file, if fpcmake made the makefile successfully. Note: before typing in make, setup your psp paths first, using an fpc.cfg file.

Setting up an FPC config file

You can place an FPC.CFG file in your local pasforum directory and include the following so that the makefile knows where to search for your Powtils units (pwmain.pas, pwumain.pas, etc.)
#-------------fpc.cfg begin--------#

# put your correct psp path here! 
-Fu c:\psp\psp-1.5.2-release   # MS Windows
-Fu /etc/psp/psp-1.5.2-release # Unix

# smart link and strip, if you like
-XX
-CX
-Xs

#-------------fpc.cfg end----------#

FPC cfg file or an environment path?

Alternatively, you can set an Environment path so that your operating system knows where your psp files are without you having to setup a fpc.cfg file.

On MS Windows, do this in /control panel/system/advanced/environment variables/. You may have to restart your pc for the environment variables to take affect. This is like old Dos SET PATH= and it helps you setup commonly used paths - dont' be lazy, set this up! FPC itself sets up one for RTL files, so why not setup a PSP one too? PSP is like your web RTL! It gets used over and over again in each web program.

On unix like OS, just set up your permanent environment paths so that each time you reboot that path is there for you.. something like /etc/psp/psp-1.5.2-release/

With a makefile, compiling the entire forum is easy

You only create the makefile once, and you use it over and over again - it is really easy to type "make" and have all the forum CGI programs compiled on your platform (unix, windows, etc.).

This article was composed by the PSP Development Team member L505.
Do you have an article? We can publish it here. Sign your name, and even link to your website at the end.
Submit to psp-articles@z505.com