Skip to content
⌘ NSIS Forum Archive

Using /D with makensis.exe

3 posts

risingfire#

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:

!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:

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
Anders#
Read the makensis command line help one more time. It specifically tells you
Parameters are processed in order. makensis /Ddef script.nsi is not the same as makensis script.nsi /Ddef.
And in your script you need

!define /IfNDef TESTDEFINE "in script"