{"id":681,"date":"2010-06-03T21:57:21","date_gmt":"2010-06-03T20:57:21","guid":{"rendered":"http:\/\/www.thomaskeller.biz\/blog\/?p=681"},"modified":"2010-06-03T22:31:53","modified_gmt":"2010-06-03T21:31:53","slug":"makefile-based-innosetup-automation-with-qmake","status":"publish","type":"post","link":"https:\/\/www.thomaskeller.biz\/blog\/2010\/06\/03\/makefile-based-innosetup-automation-with-qmake\/","title":{"rendered":"Makefile-based InnoSetup automation with QMake"},"content":{"rendered":"<p>Over the last couple of weeks I did several major improvements to the QMake-based build setup <a href=\"http:\/\/guitone.thomaskeller.biz\">guitone<\/a> uses: The project file comes now with one target to create a tarball, one to create a Mac OS X disk image containing all the needed Qt libraries and one target to install the application, which can be configured to use all the options you know from autotool-based projects (like PREFIX, BINDIR or DESTDIR, to name a few).<\/p>\n<p>But yes, there was one task which was yet missing there &#8211; one to automatically create a Win32 installer. The steps to produce that had been so far:<\/p>\n<ol>\n<li>enter the to-be-packaged version in the InnoSetup script file<\/li>\n<li>convert the supplied text files from Unix to DOS line endings, while giving them a .txt extension<\/li>\n<li>call the InnoSetup compiler on the script file and create the executable<\/li>\n<\/ol>\n<p>Especially the first and second action looked hard to automate, given the fact that Windows does not come with a rich set of tools to process text streams &#8211; and requiring a Cygwin installation just for using <code>sed<\/code> seemed awkward to me. Obviously other people had similar problems before and <a href=\"http:\/\/stackoverflow.com\/questions\/127318\/is-there-any-sed-like-utility-for-cmd-exe\">somebody proposed<\/a> to emulate sed with a VBScript which would be executed by the Windows Scripting Host (WSH). Wow, cool thing &#8211; if I&#8217;d just remember my broken Visual Basic knowledge. But didn&#8217;t Microsoft have this Javascript Look-a-Like, JScript? Shouldn&#8217;t this be executable as well?<\/p>\n<p>Apparently it was and I sat down to hack an improved JScript <code>sed<\/code> version:<\/p>\n<p>    var patterns  = new Array();<br \/>\n    var replacements = new Array();<br \/>\n    var argcount = 0;<\/p>\n<p>    for (var i=0; i<WScript.Arguments.length; ++i)\n    {\n        pat = WScript.Arguments(i).split(\"\/\");\n        if (pat.length != 4)\n            continue;\n        \n        patterns[argcount] = new RegExp(pat[1]);\n        replacements[argcount] = pat[2];  \n        ++argcount;\n    }\n     \n    while (!WScript.StdIn.AtEndOfStream)\n    {\n        var line = WScript.StdIn.ReadLine();\n        for (var i=0; i<argcount; ++i)\n        {\n            line = line.replace(patterns[i], replacements[i]);\n        }\n        WScript.Echo(line);\n    }\n\n\nNow the only thing what was left was to fiddle around with the WSH command line tool <code>cscript<\/code> and to combine everything for a proper QMake target. Here we go:<\/p>\n<pre>\r\nDOCFILES=\"NEWS README README.driver COPYING\"\r\n...\r\nwin32 {\r\n    isEmpty(QTDIR):QTDIR           = \"c:\\Qt\\4.6.2\"\r\n    isEmpty(MINGWDIR):MINGWDIR     = \"c:\\MinGW\"\r\n    isEmpty(OPENSSLDIR):OPENSSLDIR = \"c:\\OpenSSL\"\r\n    isEmpty(ISCC):ISCC = \"c:\\Program Files\\Inno Setup 5\\ISCC.exe\"\r\n&nbsp;&nbsp;&nbsp;&nbsp;\r\n    win32setup.depends  = make_first\r\n    win32setup.target   = win32setup\r\n    win32setup.commands = \\\r\n        cscript \/\/NoLogo res\\win32\\sed.js \\\r\n            s\/@@VERSION@@\/$${VERSION}\/ \\\r\n            s\/@@QTDIR@@\/$${QTDIR}\/ \\\r\n            s\/@@MINGWDIR@@\/$${MINGWDIR}\/ \\\r\n            s\/@@OPENSSLDIR@@\/$${OPENSSLDIR}\/ \\\r\n            < res\\win32\\guitone.iss.in > res\\win32\\guitone.iss && \\\r\n        ( for %%f in ($$DOCFILES) do \\\r\n            cscript \/\/NoLogo res\\win32\\sed.js \\\r\n                s\/\\n\\$$\/\\r\\n\/ \\\r\n                < %%f > %%f.txt ) && \\\r\n        \\\"$$ISCC\\\" res\\win32\\guitone.iss && \\\r\n        ( for %%f IN ($$DOCFILES) do del %%f.txt )\r\n&nbsp;&nbsp;&nbsp;&nbsp;\r\n    QMAKE_EXTRA_TARGETS += win32setup\r\n}\r\n<\/pre>\n<p>So if you know enough Javascript you can probably emulate whatever tool you&#8217;re missing on Win32 without having to depend on any external dependency. Very cool!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Over the last couple of weeks I did several major improvements to the QMake-based build setup guitone uses: The project file comes now with one target to create a tarball, one to create a Mac OS X disk image containing all the needed Qt libraries and one target to install the application, which can be &hellip; <a href=\"https:\/\/www.thomaskeller.biz\/blog\/2010\/06\/03\/makefile-based-innosetup-automation-with-qmake\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Makefile-based InnoSetup automation with QMake<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,5,9],"tags":[],"class_list":["post-681","post","type-post","status-publish","format-standard","hentry","category-coding","category-guitone","category-qt"],"_links":{"self":[{"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/posts\/681","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/comments?post=681"}],"version-history":[{"count":10,"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/posts\/681\/revisions"}],"predecessor-version":[{"id":691,"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/posts\/681\/revisions\/691"}],"wp:attachment":[{"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/media?parent=681"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/categories?post=681"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thomaskeller.biz\/blog\/wp-json\/wp\/v2\/tags?post=681"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}