Define Macro: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
(Initial Release) |
(→Macro Source: Added DefineOnce and RedefineOnce Macros) |
||
Line 59: | Line 59: | ||
!macroend | !macroend | ||
!endif | !endif | ||
!endif | |||
!ifndef DefineOnce | |||
!define DefineOnce `!insertmacro _DefineOnce` | |||
!macro _DefineOnce _Name | |||
${Define} ${_Name} `${Define} ${_Name}` | |||
!macroend | |||
!endif | |||
!ifndef ReDefineOnce | |||
!define ReDefineOnce `!insertmacro _ReDefineOnce` | |||
!macro _ReDefineOnce _Name | |||
${ReDefine} ${_Name} `${ReDefine} ${_Name}` | |||
!macroend | |||
!endif | !endif | ||
</highlight-nsis> | </highlight-nsis> |
Revision as of 19:15, 30 September 2009
Author: Zinthose (talk, contrib) |
Summary
Pure Pre-compiler macro that enhances the !define command.
- Once defined, value is locked and will not raise an error or be redefined. This is useful for assigning default values.
- Recursive define trick to allow a define to assign itself.
- ReDefine macro to reassign a define easily.
Usage
Example
## Recursive Define trick for one time value setting ${Define} MSI_FilePath `${Define} MSI_FilePath` ${MSI_FilePath} `$TEMP` DetailPrint `MSI_FilePath = "${MSI_FilePath}"` ## Standard Define ${Define} MSI_FileName `Install.msi` DetailPrint `MSI_FileName = "${MSI_FileName}"` ## Redefine a previously defined value or create a new one ${ReDefine} MSI_FileName `Setup.msi` DetailPrint `MSI_FileName = "${MSI_FileName}"` ${ReDefine} MSI_FileName `Deployment.msi` DetailPrint `MSI_FileName = "${MSI_FileName}"`
Macro Source
!ifmacrondef _Define !ifndef Define !define Define `!insertmacro _Define` !macro _Define _Name _Value !ifdef ${_Name} !if `${${_Name}}` == `` !undef ${_Name} !define ${_Name} `${_Value}` !else if `${${_Name}}` == `!insertmacro _Define ${_Name}` !undef ${_Name} !define ${_Name} `${_Value}` !endif !else !define ${_Name} `${_Value}` !endif !macroend !endif !endif !ifmacrondef _ReDefine !ifndef ReDefine !define ReDefine `!insertmacro _ReDefine` !macro _ReDefine _Name _Value !ifdef ${_Name} !undef ${_Name} !endif !insertmacro _Define ${_Name} `${_Value}` !macroend !endif !endif !ifndef DefineOnce !define DefineOnce `!insertmacro _DefineOnce` !macro _DefineOnce _Name ${Define} ${_Name} `${Define} ${_Name}` !macroend !endif !ifndef ReDefineOnce !define ReDefineOnce `!insertmacro _ReDefineOnce` !macro _ReDefineOnce _Name ${ReDefine} ${_Name} `${ReDefine} ${_Name}` !macroend !endif