Old 22nd January 2021, 18:42   #1
risingfire
Junior Member
 
Join Date: Jan 2021
Posts: 5
Using /D with makensis.exe

I am trying to define and/or override some !defines in script using /D on the command line. But I can't get it to work correctly.

I made the following test installation script:

code:
!include "MUI.nsh"

!define TESTDEFINE "in script"
!define MUI_FINISHPAGE_NOAUTOCLOSE
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"

Name "TestSetup"
OutFile "c:\temp\TestSetup.exe"
InstallDir "c:\temp\My application"
ShowInstDetails show

Section "MainSection" SEC01
SetOutPath "$INSTDIR"
SetOverwrite ifnewer
File "c:\temp\files\*.*"
MessageBox MB_OK "Def is ${TESTDEFINE}"
SectionEnd



I'm calling makensis.exe like this:

"C:\Program Files (x86)\NSIS\makensis.exe" "testscript.nsi" /DTESTDEFINE="from command line"

If working correctly, then the pop-up message window when the script creates the setup EXE should read "Def is from command line".

But it instead reads "Def is in script"

If I remove TESTDEFINE from the script, I get this compilation error:

code:
C:\temp>"C:\Program Files (x86)\NSIS\makensis.exe" "testscript.nsi" /DTESTDEFINE="from command line"
Processing config: C:\Program Files (x86)\NSIS\nsisconf.nsh
Processing script file: "testscript.nsi" (ACP)
warning 6000: unknown variable/constant "{TESTDEFINE}" detected, ignoring (testscript.nsi:21)
Command line defined: "TESTDEFINE=from command line"

Processed 1 file, writing output (x86-ansi):
warning 7998: ANSI targets are deprecated

Output: "c:\temp\TestSetup.exe"
Install: 2 pages (128 bytes), 1 section (2072 bytes), 47 instructions (1316 bytes), 68 strings (1211 bytes), 1 language table (262 bytes).

Using zlib compression.

EXE header size: 51200 / 38400 bytes
Install code: 1248 / 4429 bytes
Install data: 852 / 2107 bytes
CRC (0xFC6E3AA7): 4 / 4 bytes

Total size: 53304 / 44940 bytes (118.6%)

2 warnings:
6000: unknown variable/constant "{TESTDEFINE}" detected, ignoring (testscript.nsi:21)



If I have it defined in the script, the compilation completes with no errors and makensis says:

Command line defined: "TESTDEFINE=from command line"

But it does not change TESTDEFINE in the script.

What am I doing wrong?

Dave
risingfire is offline   Reply With Quote
Old 22nd January 2021, 21:05   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,356
Read the makensis command line help one more time. It specifically tells you
Quote:
Parameters are processed in order. makensis /Ddef script.nsi is not the same as makensis script.nsi /Ddef.
And in your script you need

Quote:
!define /IfNDef TESTDEFINE "in script"

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 22nd January 2021, 22:05   #3
risingfire
Junior Member
 
Join Date: Jan 2021
Posts: 5
Ugh... obviously totally missed that. Thank you!
risingfire is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump