Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Compile multiple files at once


  • Please log in to reply
1 reply to this topic
jtran21
  • Members
  • 10 posts
  • Last active: Jan 16 2005 11:56 PM
  • Joined: 01 Dec 2004
I often have several AHK files that I work on at the same time on one project. I find myself right-clicking on all the AHK scripts and selecting "Compile" from the right-click menu. One shortcoming of the right-click approach is that I can't specify the different icons which the resulting .EXE files will have.

So I set up a quick AHK script which performs a batch compile, and only compiles the AHK files which have changed. (If the Shift key is held down while this script is run, it will perform a fresh recompile of all scripts, regardless of whether the AHK files have changed or not.)

The script below is very straightforward (unlike Rajat's works of genius!), but it gets the job done and hopefully it will save you time.

compile_app = "C:\Program Files\Utils\AutoHotkey\Compiler\Ahk2Exe.exe"
icondir=%A_ScriptDir%\pics


; if the shift key is held down, then fresh recompile no matter what
shouldcompileall=no
GetKeyState __shift, Shift
if __shift = D
	shouldcompileall=yes

; ==============================================

infile=%A_ScriptDir%\script1.ahk
outfile=%A_ScriptDir%\script1.exe
iconfile= page04.ico
GoSub CompileFile


infile=%A_ScriptDir%\script2.ahk
outfile=%A_ScriptDir%\script2.exe
iconfile= page04.ico
GoSub CompileFile

infile=%A_ScriptDir%\script3.ahk
outfile=%A_ScriptDir%\script4.exe
iconfile= page04.ico
GoSub CompileFile

return

; ==============================================

CompileFile:

	If infile=
	{
		MsgBox No infile specified!
		return
	}
	If outfile=
	{
		MsgBox No outfile specified!
		return
	}
	If iconfile=
	{
		MsgBox No iconfile specified!
		return
	}

	IfNotExist %infile%
	{
		MsgBox %infile% does not exist!
		return
	}

	; --------------------------------------------------------------
	; conditions for recompilation

	; Detect whether files have changed
	; Only compiled changed files to speed up process

	shouldcompile=no

	; if the output file was somehow deleted
	IfNotExist %outfile%
		shouldcompile=yes

	; the archive-bit is set for the file attributes
	FileGetAttrib, attribs, %infile%
	IfInString attribs, A
		shouldcompile=yes	

	if shouldcompileall=yes
		shouldcompile=yes

	; --------------------------------------------------------------
	; perform the compile
	
	if shouldcompile=yes
	{
		FileSetAttrib,-A, %infile% 
		if outfile=
			runme = %compile_app% /in "%infile%" /icon "%icondir%\%iconfile%"
		else
			runme = %compile_app% /in "%infile%" /out "%outfile%" /icon "%icondir%\%iconfile%"
		RunWait %runme%
	}
	return


DukeProtocol
  • Guests
  • Last active:
  • Joined: --
I tried this, and was it supposed to compile multiple .ahk files into one EXE or compile 3 .ahk's into 3 EXEs?