22# v. 2.0. If a copy of the MPL was not distributed with this file, You can
33# obtain one at https://mozilla.org/MPL/2.0/
44#
5- # Copyright (C) 2009-2021 , Peter Johnson (gravatar.com/delphidabbler).
5+ # Copyright (C) 2009-2022 , Peter Johnson (gravatar.com/delphidabbler).
66#
77# Makefile for the CodeSnip project.
88
99
10- # Define macros giving relative paths to other directories from location of
11- # makefile
12- BIN = ..\Bin
13- EXE = ..\Exe
10+ # Define macros relative paths to various directories relative to the repo root
11+ BUILD_ROOT = _build
12+ BIN_ROOT = $(BUILD_ROOT ) \bin
13+ EXE_ROOT = $(BUILD_ROOT ) \exe
14+ RELEASE_ROOT = $(BUILD_ROOT ) \release
15+ DOCS_ROOT = Docs
16+ SRC_ROOT = Src
17+
18+ # Defines macros giving directories relative to location of the Makefile
19+ BIN_REL = ..\$(BIN_ROOT )
20+ EXE_REL = ..\$(EXE_ROOT )
1421
1522# Check for required environment variables
1623
@@ -75,11 +82,10 @@ DELPHIDEFINES =
7582
7683# Implicit rules
7784
78- # Resource files are compiled to the directory specified by BIN macro, which
79- # must have been set by the caller.
85+ # Resource files are compiled to the directory specified by BIN_REL macro.
8086.rc.res :
8187 @echo +++ Compiling Resource file $< +++
82- @$(BRCC32) $< -fo$(BIN )\$(@F)
88+ @$(BRCC32) $< -fo$(BIN_REL )\$(@F)
8389
8490# Version info files are compiled by VIEd. A temporary .rc file is left behind
8591.vi.rc :
@@ -104,11 +110,12 @@ config:
104110 @copy /Y CodeSnip.cfg.tplt CodeSnip.cfg
105111 # Create build folders
106112 @cd ..
107- @if exist Bin rmdir /S /Q Bin
108- @mkdir Bin
109- @if not exist Exe mkdir Exe
110- @if not exist Release mkdir Release
111- @cd Src
113+ @if not exist $(BUILD_ROOT) mkdir $(BUILD_ROOT)
114+ @if exist $(BIN_ROOT) rmdir /S /Q $(BIN_ROOT)
115+ @mkdir $(BIN_ROOT)
116+ @if not exist $(EXE_ROOT) mkdir $(EXE_ROOT)
117+ @if not exist $(RELEASE_ROOT) mkdir $(RELEASE_ROOT)
118+ @cd $(SRC_ROOT)
112119
113120# Builds CodeSnip pascal files and links program
114121pascal : CodeSnip.exe
@@ -118,14 +125,14 @@ pascal: CodeSnip.exe
118125CodeSnip.exe :
119126 @echo +++ Compiling Pascal +++
120127!ifdef PORTABLE
121- @if exist $(EXE )\$(@F) copy $(EXE )\$(@F) $(EXE )\$(@F).bak
128+ @if exist $(EXE_REL )\$(@F) copy $(EXE_REL )\$(@F) $(EXE_REL )\$(@F).bak
122129!endif
123130 @$(DCC32) $(@B).dpr -B $(DELPHIDEFINES)
124131!ifdef PORTABLE
125- @copy $(EXE )\$(@F) $(EXE )\$(@B)-p.exe /Y
126- @del $(EXE )\$(@F)
127- @if exist $(EXE )\$(@F).bak copy $(EXE )\$(@F).bak $(EXE )\$(@F)
128- @if exist $(EXE )\$(@F).bak del $(EXE )\$(@F).bak
132+ @copy $(EXE_REL )\$(@F) $(EXE_REL )\$(@B)-p.exe /Y
133+ @del $(EXE_REL )\$(@F)
134+ @if exist $(EXE_REL )\$(@F).bak copy $(EXE_REL )\$(@F).bak $(EXE_REL )\$(@F)
135+ @if exist $(EXE_REL )\$(@F).bak del $(EXE_REL )\$(@F).bak
129136!endif
130137
131138# Builds help file
@@ -144,49 +151,58 @@ resources: $(VERINFOFILEBASE).res Resources.res HTML.res
144151# Compiles HTMLres from .hrc file
145152HTML.res : HTML.hrc
146153 @echo +++ Compiling HTML Resource manifest file +++
147- @$(HTMLRES) -mHTML.hrc -o$(BIN )\HTML.res -r -q
154+ @$(HTMLRES) -mHTML.hrc -o$(BIN_REL )\HTML.res -r -q
148155
149156# Compiles type library from IDL
150157typelib :
151- @$(GENTLB) .\ExternalObj.ridl -D$(BIN ) -TExternalObj.tlb
158+ @$(GENTLB) .\ExternalObj.ridl -D$(BIN_REL ) -TExternalObj.tlb
152159
153160# Builds setup program
154161setup :
155162!ifndef PORTABLE
156- @del ..\Exe \CodeSnip-Setup-*
163+ @del $(EXE_REL) \CodeSnip-Setup-*
157164 @$(ISCC) Install\CodeSnip.iss
158165!else
159166 @echo **** Portable build - no setup file created ****
160167!endif
161168
162169# Creates auto generated files
163170autogen :
164- @$(TLIBIMP) -P+ -Ps+ -D.\AutoGen -FtIntfExternalObj $(BIN )\ExternalObj.tlb
171+ @$(TLIBIMP) -P+ -Ps+ -D.\AutoGen -FtIntfExternalObj $(BIN_REL )\ExternalObj.tlb
165172 @if exist .\AutoGen\IntfExternalObj.dcr del .\AutoGen\IntfExternalObj.dcr
166173
167174# Build release files (.zip)
175+ # If RELEASEFILENAME is defined by caller then it is used as name of zip file
176+ # otherwise default zip file name is used, which depends on whether PORTABLE
177+ # is defined.
178+ # If VERSION is defined by caller then it is appended to RELEASEFILENAME,
179+ # separated by a dash.
168180!ifndef RELEASEFILENAME
169- RELEASEFILENAME = dd-codesnip
170- !ifdef PORTABLE
171- RELEASEFILENAME = $(RELEASEFILENAME ) -portable
181+ !ifndef PORTABLE
182+ RELEASEFILENAME = codesnip-exe
183+ !else
184+ RELEASEFILENAME = codesnip-portable-exe
185+ !endif
172186!endif
187+ !ifdef VERSION
188+ RELEASEFILENAME = $(RELEASEFILENAME ) -$(VERSION )
173189!endif
174- OUTFILE = Release \$(RELEASEFILENAME ) .zip
190+ OUTFILE = $( RELEASE_ROOT ) \$(RELEASEFILENAME ) .zip
175191release :
176192 @echo ---------------------
177193 @echo Creating Release File
178194 @echo ---------------------
179195 @cd ..
180196 -@if exist $(OUTFILE) del $(OUTFILE)
181197!ifndef PORTABLE
182- @$(ZIP) -j -9 $(OUTFILE) Exe \CodeSnip-Setup-*.exe Docs \ReadMe.txt
198+ @$(ZIP) -j -9 $(OUTFILE) $(EXE_ROOT) \CodeSnip-Setup-*.exe $(DOCS_ROOT) \ReadMe.txt
183199!else
184- @$(ZIP) -j -9 $(OUTFILE) Exe \CodeSnip-p.exe
185- @$(ZIP) -j -9 $(OUTFILE) Exe \CodeSnip.chm
186- @$(ZIP) -j -9 $(OUTFILE) Docs \ReadMe.txt
187- @$(ZIP) -j -9 $(OUTFILE) Docs \License.html
200+ @$(ZIP) -j -9 $(OUTFILE) $(EXE_ROOT) \CodeSnip-p.exe
201+ @$(ZIP) -j -9 $(OUTFILE) $(EXE_ROOT) \CodeSnip.chm
202+ @$(ZIP) -j -9 $(OUTFILE) $(DOCS_ROOT) \ReadMe.txt
203+ @$(ZIP) -j -9 $(OUTFILE) $(DOCS_ROOT) \License.html
188204!endif
189- @cd Src
205+ @cd $(SRC_ROOT)
190206
191207# Clean up unwanted files
192208clean :
@@ -200,4 +216,4 @@ clean:
200216 -@del /S *.tvsconfig 2>nul
201217 # remove __history folders
202218 -@for /F "usebackq" % i in (`dir /S /B /A :D ..\__history`) do @rmdir /S /Q % i
203- @cd Src
219+ @cd $(SRC_ROOT)
0 commit comments