From 79aff56b62b8f814cf7f9338420e0ad7e8ccdbdb Mon Sep 17 00:00:00 2001 From: David Given Date: Tue, 19 Jul 2022 21:21:23 +0200 Subject: [PATCH 1/6] Actually honour LDFLAGS. --- first/build.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/first/build.lua b/first/build.lua index 20d834437..9fbc78080 100644 --- a/first/build.lua +++ b/first/build.lua @@ -225,7 +225,7 @@ definerule("cprogram", commands = { type="strings", default={ - "$(CC) -o %{outs[1]} %{ins} %{ins}" + "$(CC) $LDFLAGS -o %{outs[1]} %{ins} %{ins}" }, } }, From 4555352a1888959418a901a651a55281acc57926 Mon Sep 17 00:00:00 2001 From: David Given Date: Tue, 19 Jul 2022 21:21:48 +0200 Subject: [PATCH 2/6] Build a Windows installer when doing a CI build. --- .github/workflows/ccpp.yml | 12 +++++- Makefile | 10 ++++- etc/windows-installer.nsi | 79 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 etc/windows-installer.nsi diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index fe34f1587..4228fe23a 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -36,6 +36,7 @@ jobs: make mingw-w64-i686-gcc mingw-w64-i686-lua + mingw-w64-i686-nsis ninja bison flex @@ -44,5 +45,12 @@ jobs: - uses: actions/checkout@v3 - name: build run: | - make - + make LDFLAGS=-s CFLAGS=-Os + - name: package + run: | + make ack-setup.exe + - name: upload setup + uses: actions/upload-artifact@v2 + with: + name: ${{ github.event.repository.name }}.${{ github.sha }} + path: ack-setup.exe diff --git a/Makefile b/Makefile index 4db53e18e..7e04293f0 100644 --- a/Makefile +++ b/Makefile @@ -15,8 +15,12 @@ ACK_TEMP_DIR ?= /tmp # install it and just want to run the ACK from the build directory # (/tmp/ack-build/staging, by default), leave this as $(INSDIR). +ifeq ($(OS),Windows_NT) +PREFIX ?= c:/Program Files (x86)/Amsterdam Compiler Kit +else PREFIX ?= /usr/local #PREFIX = $(INSDIR) +endif # Where do you want to put the object files used when building? @@ -119,12 +123,16 @@ $(build-file): first/ackbuilder.lua Makefile $(lua-files) INSDIR=$(INSDIR) \ PLATIND=$(PLATIND) \ PLATDEP=$(PLATDEP) \ - PREFIX=$(PREFIX) \ + PREFIX="$(PREFIX)" \ AR=$(AR) \ CC=$(CC) \ CFLAGS="$(CFLAGS)" \ + LDFLAGS="$(LDFLAGS)" \ > $(build-file) +ack-setup.exe: etc/windows-installer.nsi + makensis -dBUILDDIR=$(BUILDDIR)/staging -dOUTFILE="$$(realpath $@)" $< + install: mkdir -p $(PREFIX) tar cf - -C $(INSDIR) . | tar xvf - -C $(PREFIX) diff --git a/etc/windows-installer.nsi b/etc/windows-installer.nsi new file mode 100644 index 000000000..7a1abe9a0 --- /dev/null +++ b/etc/windows-installer.nsi @@ -0,0 +1,79 @@ +!include MUI2.nsh + +Name "The Amsterdam Compiler Kit" +OutFile "${OUTFILE}" +Unicode True + +InstallDir "$PROGRAMFILES\Amsterdam Compiler Kit" + +RequestExecutionLevel admin +SetCompressor /solid lzma + +;-------------------------------- + +!define MUI_WELCOMEPAGE_TITLE "The Amsterdam Compiler Kit" +!define MUI_WELCOMEPAGE_TEXT "The ACK is a compiler toolchain supporting a \ + variety of frontend and backends. It's not easy to use, so if you don't \ + know what you're doing you shouldn't install this.$\r$\n\ + $\r$\n\ + This wizard will install the ACK on your computer.$\r$\n\ + $\r$\n\ + $_CLICK" + +!define MUI_HEADERIMAGE +!define MUI_HEADERIMAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Header\nsis.bmp" +!define MUI_ABORTWARNING + +!insertmacro MUI_PAGE_WELCOME + +!define MUI_COMPONENTSPAGE_NODESC +!insertmacro MUI_PAGE_COMPONENTS +!insertmacro MUI_PAGE_DIRECTORY +!insertmacro MUI_PAGE_INSTFILES + +!define MUI_FINISHPAGE_TITLE "Installation complete" +!define MUI_FINISHPAGE_TEXT_LARGE +!define MUI_FINISHPAGE_TEXT "The ACK is now ready to use, but \ + hasn't been added to your path.$\r$\n\ + $\r$\n\ + Have fun!" + +!insertmacro MUI_PAGE_FINISH + +!insertmacro MUI_UNPAGE_CONFIRM +!insertmacro MUI_UNPAGE_INSTFILES +!insertmacro MUI_UNPAGE_FINISH + +!insertmacro MUI_LANGUAGE "English" + +; The stuff to install +Section "The ACK (required)" + SectionIn RO + SetOutPath $INSTDIR + File /r "${BUILDDIR}\*.*" + ;File /oname=wordgrinder.exe "bin\wordgrinder-builtin-sdl-release.exe" + ;File /oname=cwordgrinder.exe "bin\wordgrinder-builtin-wincon-release.exe" + ;File "README.wg" + ;File "licenses\COPYING.*" + + ;CreateDirectory $INSTDIR\Dictionaries + ;File /oname=Dictionaries\British.dictionary "extras\british.dictionary" + ;File /oname=Dictionaries\American-Canadian.dictionary "extras\american-canadian.dictionary" + + ; Write the uninstall keys for Windows + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\WordGrinder" "DisplayName" "WordGrinder for Windows" + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\WordGrinder" "UninstallString" '"$INSTDIR\uninstall.exe"' + WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\WordGrinder" "NoModify" 1 + WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\WordGrinder" "NoRepair" 1 + WriteUninstaller "uninstall.exe" +SectionEnd + +;-------------------------------- + +; Uninstaller + +Section "Uninstall" + ; Remove registry keys + ; Remove files and uninstaller + RMDir /r $INSTDIR +SectionEnd From 3e394b95e4e9db370441ae35840696eb8c74b814 Mon Sep 17 00:00:00 2001 From: David Given Date: Tue, 19 Jul 2022 21:44:34 +0200 Subject: [PATCH 3/6] Actually make the binaries runnable... and a fraction of the size. --- .github/workflows/ccpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 4228fe23a..a3e2ff387 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -45,7 +45,7 @@ jobs: - uses: actions/checkout@v3 - name: build run: | - make LDFLAGS=-s CFLAGS=-Os + make LDFLAGS="-s -static" CFLAGS=-Os - name: package run: | make ack-setup.exe From 6a3c94a9d0a33887cb5a746d304b65b26f39c389 Mon Sep 17 00:00:00 2001 From: David Given Date: Wed, 20 Jul 2022 00:24:20 +0200 Subject: [PATCH 4/6] Better string escaping, but it's still not good enough to support paths with spaces. --- modules/src/system/syssystem.c | 69 ++++++++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 12 deletions(-) diff --git a/modules/src/system/syssystem.c b/modules/src/system/syssystem.c index c86b0be65..6013ade8d 100644 --- a/modules/src/system/syssystem.c +++ b/modules/src/system/syssystem.c @@ -2,34 +2,79 @@ #include #include "system.h" +#if defined WIN32 + #define ESCAPECHAR '^' + + static int needs_escaping(char c) + { + switch (c) + { + case ' ': + case '"': + case '\'': + case '(': + case ')': + case '^': + return 1; + + default: + return 0; + } + } +#else + #define ESCAPECHAR '\\' + + static int needs_escaping(char c) + { + switch (c) + { + case ' ': + case '"': + case '\'': + case '\\': + case '(': + case ')': + return 1; + + default: + return 0; + } + } +#endif + +static char* append_escaped(char* buffer, const char* word) +{ + for (;;) + { + char c = *word++; + if (!c) + break; + if (needs_escaping(c)) + *buffer++ = ESCAPECHAR; + *buffer++ = c; + } + return buffer; +} + int sys_system(const char* prog, const char* const* arglist) { /* Calculate the maximum length of the command line. */ - int len = strlen(prog); + int len = strlen(prog) * 2 + 1; for (const char* const* arg = arglist+1; *arg; arg++) len += strlen(*arg) * 2 + 1; /* Now actually build the command line. */ char* cmdline = malloc(len + 1); - strcpy(cmdline, prog); - char* p = cmdline + strlen(prog); + char* p = append_escaped(cmdline, prog); for (const char* const* arg = arglist+1; *arg; arg++) { const char* word = *arg; *p++ = ' '; - for (;;) - { - char c = *word++; - if (!c) - break; - if ((c == ' ') || (c == '\"') || (c == '\'')) - *p++ = '\\'; - *p++ = c; - } + p = append_escaped(p, word); } *p = 0; From f5acf7091110a96aee070e52574827cd06b3a8cc Mon Sep 17 00:00:00 2001 From: David Given Date: Wed, 20 Jul 2022 00:24:52 +0200 Subject: [PATCH 5/6] Typo fix. --- h/build.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/h/build.lua b/h/build.lua index 4163e8249..93b1715d8 100644 --- a/h/build.lua +++ b/h/build.lua @@ -3,7 +3,7 @@ normalrule { ins = {}, outleaves = { "em_path.h" }, commands = { - "echo '#define EM_DIR \"$(PREFIX)\"' >> %{outs}", + "echo '#define EM_DIR \"$(PREFIX)\"' > %{outs}", "echo '#define ACK_PATH \"share/ack/descr\"' >> %{outs}", } } From c295920696a38013ada8534d05ca9b7293791fad Mon Sep 17 00:00:00 2001 From: David Given Date: Wed, 20 Jul 2022 00:25:07 +0200 Subject: [PATCH 6/6] Make the Windows binaries actually run. --- Makefile | 2 +- etc/windows-installer.nsi | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 7e04293f0..3f4a66716 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ ACK_TEMP_DIR ?= /tmp # (/tmp/ack-build/staging, by default), leave this as $(INSDIR). ifeq ($(OS),Windows_NT) -PREFIX ?= c:/Program Files (x86)/Amsterdam Compiler Kit +PREFIX ?= c:/ack else PREFIX ?= /usr/local #PREFIX = $(INSDIR) diff --git a/etc/windows-installer.nsi b/etc/windows-installer.nsi index 7a1abe9a0..ecd0b69f8 100644 --- a/etc/windows-installer.nsi +++ b/etc/windows-installer.nsi @@ -4,7 +4,7 @@ Name "The Amsterdam Compiler Kit" OutFile "${OUTFILE}" Unicode True -InstallDir "$PROGRAMFILES\Amsterdam Compiler Kit" +InstallDir "c:\ack" RequestExecutionLevel admin SetCompressor /solid lzma @@ -18,6 +18,11 @@ SetCompressor /solid lzma $\r$\n\ This wizard will install the ACK on your computer.$\r$\n\ $\r$\n\ + Please note that it doesn't support being installed into a path \ + with a space in it, and if you put it anywhere other than the default \ + then you'll need to set the ACKDIR environment variable to point to it \ + before use.$\r$\n\ + $\r$\n\ $_CLICK" !define MUI_HEADERIMAGE @@ -51,14 +56,6 @@ Section "The ACK (required)" SectionIn RO SetOutPath $INSTDIR File /r "${BUILDDIR}\*.*" - ;File /oname=wordgrinder.exe "bin\wordgrinder-builtin-sdl-release.exe" - ;File /oname=cwordgrinder.exe "bin\wordgrinder-builtin-wincon-release.exe" - ;File "README.wg" - ;File "licenses\COPYING.*" - - ;CreateDirectory $INSTDIR\Dictionaries - ;File /oname=Dictionaries\British.dictionary "extras\british.dictionary" - ;File /oname=Dictionaries\American-Canadian.dictionary "extras\american-canadian.dictionary" ; Write the uninstall keys for Windows WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\WordGrinder" "DisplayName" "WordGrinder for Windows"