Tip: MakeFiles, double substitution within macros

Tip: MakeFiles, double substitution within macros

Postby Antonio Linares » Sun Nov 27, 2011 3:56 pm

This is a recent tip I discovered using Borland and Microsoft make utilities. Lets consider the files list:

Code: Select all  Expand view
PRG =          \
.\APPLICAT.PRG \
.\CODE.PRG     \
.\DATABASE.PRG \
.\DEBUG.PRG    \
.\DESIGN.PRG   \
.\INDEX.PRG    \
.\INSPECT.PRG  \
.\MENU.PRG     \
.\OPTIONS.PRG  \
.\PROGRAM.PRG  \
.\PROJECT.PRG  \
.\RECORD.PRG   \
.\REP.PRG      \
.\REPORT.PRG   \
.\RESOURCE.PRG \
.\TOOLBAR.PRG  \
.\TOOLS.PRG    \
.\VISUAL.PRG  


The macro:
OBJ = $(PRG:.PRG=.OBJ)
creates a new macro OBJ where .PRG ocurrences are replaced with .OBJ. The trick now is to create a new macro from this one and perform another substitution:

OBJS = $(OBJ:.\=.\obj\)
replacing ".\" with ".\obj\" in the list.

Now, we can use $(OBJS) to set the EXE dependencies and also to link the EXE:
VISUALFW.EXE : $(OBJS) VISUALFW.RES ..\lib\FiveH.lib ..\lib\FiveHC.lib
...
echo $(OBJS), + >> b32.bc

Here you have the complete makefile visualfw.mak
Code: Select all  Expand view
#VisualFW Borland make, (c) FiveTech Software 2005-2011

HBDIR=c:\harbour
BCDIR=c:\bcc582
FWDIR=c:\fwh

#change these paths as needed
.path.OBJ = .\obj
.path.PRG = .\
.path.CH  = $(FWDIR)\include;$(HBDIR)\include
.path.C   = .\
.path.rc  = .\

#important: Use Uppercase for filenames extensions!

PRG =          \
.\APPLICAT.PRG \
.\CODE.PRG     \
.\DATABASE.PRG \
.\DEBUG.PRG    \
.\DESIGN.PRG   \
.\INDEX.PRG    \
.\INSPECT.PRG  \
.\MENU.PRG     \
.\OPTIONS.PRG  \
.\PROGRAM.PRG  \
.\PROJECT.PRG  \
.\RECORD.PRG   \
.\REP.PRG      \
.\REPORT.PRG   \
.\RESOURCE.PRG \
.\TOOLBAR.PRG  \
.\TOOLS.PRG    \
.\VISUAL.PRG              

OBJ = $(PRG:.PRG=.OBJ)
OBJS = $(OBJ:.\=.\obj\)

PROJECT    : VISUALFW.EXE

VISUALFW.EXE : $(OBJS) VISUALFW.RES ..\lib\FiveH.lib ..\lib\FiveHC.lib
   echo off
   echo $(BCDIR)\lib\c0w32.obj + > b32.bc
   echo $(OBJS), + >> b32.bc
   echo visualfw.exe, + >> b32.bc
   echo visualfw.map, + >> b32.bc
   echo $(FWDIR)\lib\FiveH.lib $(FWDIR)\lib\FiveHC.lib + >> b32.bc
   echo $(HBDIR)\lib\hbrtl.lib + >> b32.bc
   echo $(HBDIR)\lib\hbvm.lib + >> b32.bc
   echo $(HBDIR)\lib\gtgui.lib + >> b32.bc
   echo $(HBDIR)\lib\hblang.lib + >> b32.bc
   echo $(HBDIR)\lib\hbmacro.lib + >> b32.bc
   echo $(HBDIR)\lib\hbrdd.lib + >> b32.bc
   echo $(HBDIR)\lib\rddntx.lib + >> b32.bc
   echo $(HBDIR)\lib\rddcdx.lib + >> b32.bc
   echo $(HBDIR)\lib\rddfpt.lib + >> b32.bc
   echo $(HBDIR)\lib\hbsix.lib + >> b32.bc
   echo $(HBDIR)\lib\hbdebug.lib + >> b32.bc
   echo $(HBDIR)\lib\hbcommon.lib + >> b32.bc
   echo $(HBDIR)\lib\hbpp.lib + >> b32.bc
   echo $(HBDIR)\lib\hbwin.lib + >> b32.bc
   echo $(HBDIR)\lib\hbcpage.lib + >> b32.bc
   echo $(HBDIR)\lib\hbct.lib + >> b32.bc
   echo $(HBDIR)\lib\hbcplr.lib + >> b32.bc
   echo $(HBDIR)\lib\png.lib + >> b32.bc
   echo $(HBDIR)\lib\hbzlib.lib + >> b32.bc
   echo $(HBDIR)\lib\xhb.lib + >> b32.bc
   
   rem Uncomment these two lines to use Advantage RDD
   rem echo $(HBDIR)\lib\rddads.lib + >> b32.bc
   rem echo $(HBDIR)\lib\Ace32.lib + >> b32.bc

   echo $(BCDIR)\lib\cw32.lib + >> b32.bc
   echo $(BCDIR)\lib\import32.lib + >> b32.bc
   echo $(BCDIR)\lib\psdk\odbc32.lib + >> b32.bc
   echo $(BCDIR)\lib\psdk\nddeapi.lib + >> b32.bc
   echo $(BCDIR)\lib\psdk\iphlpapi.lib + >> b32.bc
   echo $(BCDIR)\lib\psdk\msimg32.lib + >> b32.bc
   echo $(BCDIR)\lib\psdk\psapi.lib + >> b32.bc
   echo $(BCDIR)\lib\psdk\rasapi32.lib, >> b32.bc

   IF EXIST visualfw.res echo visualfw.res >> b32.bc
   $(BCDIR)\bin\ilink32 -Gn -aa -Tpe -s @b32.bc
   del b32.bc

.PRG.OBJ:
  $(HBDIR)\bin\harbour $< /N /W /Oobj\ /I$(FWDIR)\include;$(HBDIR)\include
  $(BCDIR)\bin\bcc32 -c -tWM -I$(HBDIR)\include -oobj\$& obj\$&.c

.C.OBJ:
  echo -c -tWM -D__HARBOUR__ > tmp
  echo -I$(HBDIR)\include;$(FWDIR)\include >> tmp
  $(BCDIR)\bin\bcc32 -oobj\$& @tmp $&.c
  del tmp

VISUALFW.RES : VISUALFW.RC
  $(BCDIR)\bin\brc32.exe -r -I$(BCDIR)\include visualfw.rc


http://basic.phatcode.net/TUT/GDE/NMAKE.HTM#AG
http://web.sau.edu/lilliskevinm/csci240/masmdocs/envtools/26LMAETC16.pdf
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42085
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 103 guests