aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/windows/mcode
diff options
context:
space:
mode:
authorumarcor <unai.martinezcorral@ehu.eus>2021-01-05 20:46:15 +0100
committertgingold <tgingold@users.noreply.github.com>2021-01-06 07:30:46 +0100
commit99853361819bff87e7cf8103c5205721ec195c32 (patch)
tree29a6dda1199534497f5a09ea1268aa3a619c41b8 /scripts/windows/mcode
parent301f442a6e66a83b47ed7d40e5b61389b9c33446 (diff)
downloadghdl-99853361819bff87e7cf8103c5205721ec195c32.tar.gz
ghdl-99853361819bff87e7cf8103c5205721ec195c32.tar.bz2
ghdl-99853361819bff87e7cf8103c5205721ec195c32.zip
mv dist/* scripts/
Diffstat (limited to 'scripts/windows/mcode')
-rw-r--r--scripts/windows/mcode/Makefile.in54
-rw-r--r--scripts/windows/mcode/binary_file-format.ads3
-rw-r--r--scripts/windows/mcode/compile.bat31
-rw-r--r--scripts/windows/mcode/complib.bat119
-rw-r--r--scripts/windows/mcode/default_paths.ads9
-rw-r--r--scripts/windows/mcode/ghdl.nsi458
-rw-r--r--scripts/windows/mcode/ghdlfilter.adb132
-rw-r--r--scripts/windows/mcode/ghdlversion.adb30
-rw-r--r--scripts/windows/mcode/grt-backtraces-impl.ads3
-rw-r--r--scripts/windows/mcode/grt-modules.adb39
-rw-r--r--scripts/windows/mcode/ortho_code-x86-flags.ads2
-rw-r--r--scripts/windows/mcode/winbuild.bat20
-rw-r--r--scripts/windows/mcode/windows_default_path.adb68
-rw-r--r--scripts/windows/mcode/windows_default_path.ads30
14 files changed, 998 insertions, 0 deletions
diff --git a/scripts/windows/mcode/Makefile.in b/scripts/windows/mcode/Makefile.in
new file mode 100644
index 000000000..be1f11516
--- /dev/null
+++ b/scripts/windows/mcode/Makefile.in
@@ -0,0 +1,54 @@
+PREFIX=/usr/local
+target=i686-pc-linux-gnu
+
+CFLAGS=-O
+GNATFLAGS=$(CFLAGS) -gnatn
+
+GRT_FLAGS=$(CFLAGS)
+
+all: ghdl_mcode std.v93 std.v87 ieee.v93 ieee.v87 synopsys.v93 synopsys.v87 mentor.v93
+
+
+GRTSRCDIR=grt
+
+####grt Makefile.inc
+
+ghdl_mcode: default_paths.ads $(GRT_ADD_OBJS) mmap_binding.o force
+ gnatmake -aIghdldrv -aIghdl -aIortho -aIgrt $(GNATFLAGS) ghdl_mcode $(GNAT_BARGS) -largs mmap_binding.o $(GNAT_LARGS) $(GRT_ADD_OBJS) $(GRT_EXTRA_LIB) -Wl,--version-script=$(GRTSRCDIR)/grt.ver -Wl,--export-dynamic
+
+mmap_binding.o: ortho/mmap_binding.c
+ $(CC) -c -g -o $@ $<
+
+default_paths.ads: Makefile
+ echo "-- DO NOT EDIT" > tmp-dpaths.ads
+ echo "-- This file is created by Makefile" >> tmp-dpaths.ads
+ echo "package Default_Paths is" >> tmp-dpaths.ads
+ echo " Prefix : constant String :=">> tmp-dpaths.ads
+ echo " \"$(PREFIX)/lib/ghdl/\";" >> tmp-dpaths.ads
+ echo "end Default_Paths;" >> tmp-dpaths.ads
+ if test -r $@ && cmp tmp-dpaths.ads $@; then \
+ echo "$@ unchanged"; \
+ else \
+ mv tmp-dpaths.ads $@; \
+ fi
+ $(RM) tmp-dpaths.ads
+
+force:
+
+LIB93_DIR:=./lib/v93
+LIB87_DIR:=./lib/v87
+LIBSRC_DIR:=./libraries
+ANALYZE=../../../ghdl_mcode -a --ieee=none
+REL_DIR=../../..
+VHDLLIBS_COPY_OBJS:=no
+CP=cp
+LN=ln -s
+
+./lib:
+ mkdir $@
+
+$(LIB93_DIR) $(LIB87_DIR): ./lib
+ mkdir $@
+
+
+####libraries Makefile.inc
diff --git a/scripts/windows/mcode/binary_file-format.ads b/scripts/windows/mcode/binary_file-format.ads
new file mode 100644
index 000000000..daf2afe2e
--- /dev/null
+++ b/scripts/windows/mcode/binary_file-format.ads
@@ -0,0 +1,3 @@
+with Binary_File.Coff;
+
+package Binary_File.Format renames Binary_File.Coff;
diff --git a/scripts/windows/mcode/compile.bat b/scripts/windows/mcode/compile.bat
new file mode 100644
index 000000000..9a1825e46
--- /dev/null
+++ b/scripts/windows/mcode/compile.bat
@@ -0,0 +1,31 @@
+mkdir build
+cd build
+
+rem Do the compilation
+set CFLAGS= -O -Wall
+
+gcc -c %CFLAGS% ../../../src/grt/grt-cstdio.c
+if errorlevel 1 goto failed
+
+gcc -c %CFLAGS% ../../../src/grt/grt-cvpi.c
+if errorlevel 1 goto failed
+
+gcc -c %CFLAGS% ../../../src/grt/config/clock.c
+if errorlevel 1 goto failed
+
+gcc -c %CFLAGS% ../../../src/ortho/mcode/memsegs_c.c
+if errorlevel 1 goto failed
+
+gcc -c %CFLAGS% -DWITH_GNAT_RUN_TIME ../../../src/grt/config/win32.c
+if errorlevel 1 goto failed
+
+gnatmake %CFLAGS% -gnatn -aI../windows -aI../../../src -aI../../../src/ghdldrv -aI../../../src/psl -aI../../../src/grt -aI../../../src/ortho/mcode -aI../../../src/vhdl -aI../../../src/vhdl/translate ghdl_jit -aI../../../src/ortho -o ghdl.exe -largs grt-cstdio.o clock.o grt-cvpi.o memsegs_c.o win32.o -ldbghelp -Wl,--stack,8404992
+if errorlevel 1 goto failed
+
+cd ..
+exit /b 0
+
+:failed
+echo "Compilation failed"
+cd ..
+exit /b 1
diff --git a/scripts/windows/mcode/complib.bat b/scripts/windows/mcode/complib.bat
new file mode 100644
index 000000000..e7291ad03
--- /dev/null
+++ b/scripts/windows/mcode/complib.bat
@@ -0,0 +1,119 @@
+set GHDL=ghdl
+
+cd build
+gnatmake -aI..\windows ghdlfilter
+cd ..
+
+set REL=..\..\..
+set LIBSRC=%REL%\..\..\libraries
+
+::
+:: library sources
+::
+set STD_SRCS= textio textio-body
+set IEEE_SRCS= std_logic_1164 std_logic_1164-body numeric_std numeric_std-body numeric_bit numeric_bit-body
+set MATH_SRCS= math_real math_real-body math_complex math_complex-body
+
+set STD08_SRCS= textio textio-body env env-body
+set IEEE08_SRCS= std_logic_1164 std_logic_1164-body std_logic_textio math_real math_real-body math_complex math_complex-body numeric_bit numeric_bit-body numeric_bit_unsigned numeric_bit_unsigned-body numeric_std numeric_std-body numeric_std_unsigned numeric_std_unsigned-body fixed_float_types fixed_generic_pkg fixed_generic_pkg-body fixed_pkg float_generic_pkg float_generic_pkg-body float_pkg ieee_bit_context ieee_std_context
+
+set VITAL95_SRCS= vital_timing vital_timing-body vital_primitives vital_primitives-body
+set VITAL2000_SRCS= timing_p timing_b prmtvs_p prmtvs_b memory_p memory_b
+
+set SYNOPSYS_SRCS= std_logic_arith std_logic_textio std_logic_unsigned std_logic_signed std_logic_misc std_logic_misc-body
+set MENTOR_SRCS= std_logic_arith std_logic_arith-body
+
+
+mkdir lib
+cd lib
+
+:::::::::::::::::
+echo v87 libraries...
+
+mkdir v87
+cd v87
+
+echo std
+mkdir std
+cd std
+for %%F in (%STD_SRCS%) do %REL%\build\ghdlfilter -v87 < %LIBSRC%\std\%%F.vhdl > %%F.v87 && %REL%\build\%GHDL% -a --std=87 --bootstrap --work=std %%F.v87
+cd ..
+
+echo ieee
+mkdir ieee
+cd ieee
+for %%F in (%IEEE_SRCS%) do %REL%\build\ghdlfilter -v87 < %LIBSRC%\ieee\%%F.vhdl > %%F.v87 && %REL%\build\%GHDL% -a --std=87 -P..\std --work=ieee %%F.v87
+for %%F in (%VITAL95_SRCS%) do copy %LIBSRC%\vital95\%%F.vhdl %%F.vhd && %REL%\build\%GHDL% -a --std=87 -P..\std --work=ieee %%F.vhd
+cd ..
+
+echo synopsys
+mkdir synopsys
+cd synopsys
+for %%F in (%IEEE_SRCS%) do %REL%\build\%GHDL% -a --std=87 -P..\std --work=ieee ..\ieee\%%F.v87
+for %%F in (%VITAL95_SRCS%) do %REL%\build\%GHDL% -a --std=87 -P..\std --work=ieee ..\ieee\%%F.vhd
+for %%F in (%SYNOPSYS_SRCS%) do copy %LIBSRC%\synopsys\%%F.vhdl %%F.vhd && %REL%\build\%GHDL% -a --std=87 -P..\std --work=ieee %%F.vhd
+cd ..
+
+cd ..
+
+:::::::::::::::::
+echo v93 libraries...
+
+mkdir v93
+cd v93
+
+echo std
+mkdir std
+cd std
+for %%F in (%STD_SRCS%) do %REL%\build\ghdlfilter -v93 < %LIBSRC%\std\%%F.vhdl > %%F.v93 && %REL%\build\%GHDL% -a --std=93 --bootstrap --work=std %%F.v93
+cd ..
+
+echo ieee
+mkdir ieee
+cd ieee
+for %%F in (%IEEE_SRCS%) do %REL%\build\ghdlfilter -v93 < %LIBSRC%\ieee\%%F.vhdl > %%F.v93 && %REL%\build\%GHDL% -a --std=93 -P..\std --work=ieee %%F.v93
+for %%F in (%VITAL2000_SRCS%) do copy %LIBSRC%\vital2000\%%F.vhdl %%F.vhd && %REL%\build\%GHDL% -a --std=93 -P..\std --work=ieee %%F.vhd
+for %%F in (%MATH_SRCS%) do copy %LIBSRC%\ieee\%%F.vhdl %%F.vhd && %REL%\build\%GHDL% -a --std=93 -P..\std --work=ieee %%F.vhd
+cd ..
+
+echo synopsys
+mkdir synopsys
+cd synopsys
+for %%F in (%IEEE_SRCS%) do %REL%\build\%GHDL% -a --std=93 -P..\std --work=ieee ..\ieee\%%F.v93
+for %%F in (%VITAL2000_SRCS%) do %REL%\build\%GHDL% -a --std=93 -P..\std --work=ieee ..\ieee\%%F.vhd
+for %%F in (%MATH_SRCS%) do %REL%\build\%GHDL% -a --std=93 -P..\std --work=ieee ..\ieee\%%F.vhd
+for %%F in (%SYNOPSYS_SRCS%) do %REL%\build\%GHDL% -a --std=93 -P..\std --work=ieee ..\..\v87\synopsys\%%F.vhd
+cd ..
+
+echo mentor
+mkdir mentor
+cd mentor
+for %%F in (%IEEE_SRCS%) do %REL%\build\%GHDL% -a --std=93 -P..\std --work=ieee ..\ieee\%%F.v93
+for %%F in (%VITAL2000_SRCS%) do %REL%\build\%GHDL% -a --std=93 -P..\std --work=ieee ..\ieee\%%F.vhd
+for %%F in (%MATH_SRCS%) do %REL%\build\%GHDL% -a --std=93 -P..\std --work=ieee ..\ieee\%%F.vhd
+for %%F in (%MENTOR_SRCS%) do copy %LIBSRC%\mentor\%%F.vhdl %%F.vhd && %REL%\build\%GHDL% -a --std=93 -P..\std --work=ieee %%F.vhd
+cd ..
+
+cd ..
+
+:::::::::::::::::
+echo v08 libraries...
+
+mkdir v08
+cd v08
+
+echo std
+mkdir std
+cd std
+for %%F in (%STD08_SRCS%) do %REL%\build\ghdlfilter -v08 < %LIBSRC%\std\%%F.vhdl > %%F.v08 && %REL%\build\%GHDL% -a --std=08 --bootstrap --work=std %%F.v08
+cd ..
+
+echo ieee
+mkdir ieee
+cd ieee
+for %%F in (%IEEE08_SRCS%) do %REL%\build\ghdlfilter -v08 < %LIBSRC%\ieee2008\%%F.vhdl > %%F.v08 && %REL%\build\%GHDL% -a --std=08 -P..\std --work=ieee %%F.v08
+cd ..
+
+:::::::::::::::::
+
+cd ..\..
diff --git a/scripts/windows/mcode/default_paths.ads b/scripts/windows/mcode/default_paths.ads
new file mode 100644
index 000000000..6b1d9d952
--- /dev/null
+++ b/scripts/windows/mcode/default_paths.ads
@@ -0,0 +1,9 @@
+with Windows_Default_Path;
+pragma Elaborate_All (Windows_Default_Path);
+
+package Default_Paths is
+ Install_Prefix : constant String :=
+ Windows_Default_Path.Get_Windows_Exec_Path;
+ Lib_Prefix : constant String := "lib";
+ Shared_Library_Extension : constant String := ".dll";
+end Default_Paths;
diff --git a/scripts/windows/mcode/ghdl.nsi b/scripts/windows/mcode/ghdl.nsi
new file mode 100644
index 000000000..21ecb50c4
--- /dev/null
+++ b/scripts/windows/mcode/ghdl.nsi
@@ -0,0 +1,458 @@
+; ghdl.nsi
+;
+; This script is based on example2.nsi.
+; remember the directory,
+; Check if administrator
+; uninstall support
+; TODO:
+; * allow multiple version
+; * command line installation
+; * Allow user install
+
+;--------------------------------
+!include version.nsi
+;--------------------------------
+
+; The name of the installer
+Name "Ghdl"
+
+; The file to write
+OutFile "ghdl-installer-${VERSION}.exe"
+
+SetDateSave on
+
+; The default installation directory
+InstallDir $PROGRAMFILES\Ghdl
+
+; Registry key to check for directory (so if you install again, it will
+; overwrite the old one automatically)
+InstallDirRegKey HKLM "Software\Ghdl" "Install_Dir"
+
+LicenseData ..\..\..\COPYING
+; LicenseForceSelection
+
+;--------------------------------
+
+; Pages
+
+Page license
+Page components
+Page directory
+Page instfiles
+
+UninstPage uninstConfirm
+UninstPage instfiles
+
+;--------------------------------
+Function .onInit
+ Call IsNT
+ pop $R0
+ StrCmp $R0 1 nt_ok
+ MessageBox MB_OK|MB_ICONEXCLAMATION "You must use Windows NT (XP/2000/Me...)"
+ Quit
+
+nt_ok:
+ Call IsUserAdmin
+ Pop $R0
+ StrCmp $R0 "true" Admin
+ MessageBox MB_OK|MB_ICONEXCLAMATION "You must have Admin rights"
+ Quit
+
+Admin:
+
+ ;;; Check if already installed.
+ ReadRegStr $0 HKLM "Software\Ghdl" "Install_Dir"
+ IfErrors not_installed
+ ReadRegStr $0 HKLM "Software\Ghdl" "Version"
+ IfErrors unknown_prev_version
+ Goto known_version
+unknown_prev_version:
+ StrCpy $0 "(unknown)"
+known_version:
+ MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "You already have GHDL version $0 installed. Deinstall ?" IDCANCEL install_abort IDOK deinstall
+install_abort:
+ Abort "Installation aborted"
+deinstall:
+ ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Ghdl" "UninstallString"
+ IfErrors deinstall_failed
+
+ ; First version of the GHDL installer adds quotes
+ StrCpy $1 $0 1
+ StrCmp $1 '"' 0 str_ok
+ StrCpy $1 $0 "" 1
+ StrCpy $0 $1 -1
+str_ok:
+
+ ; Read install dir
+ ReadRegStr $1 HKLM "Software\Ghdl" "Install_Dir"
+ IfErrors deinstall_failed
+
+; MessageBox MB_OK 'copy $0 to $TEMP'
+
+ ClearErrors
+; MessageBox MB_OK 'copy $0 to $TEMP'
+ CopyFiles $0 $TEMP
+ IfErrors deinstall_failed
+ ExecWait '"$TEMP\uninst-ghdl.exe" /S _?=$1'
+ IfErrors deinstall_failed
+ Delete "$TEMP\uninst-ghdl.exe"
+ Return
+deinstall_failed:
+ Delete $TEMP\uninst-ghdl.exe
+ MessageBox MB_YESNO|MB_ICONSTOP "Can't deinstall GHDL: de-installer not found or failed. Continue installation ?" IDNO install_abort
+not_installed:
+ Return
+FunctionEnd
+
+;--------------------------------
+
+; The stuff to install
+Section "Ghdl Compiler (required)"
+
+ SectionIn RO
+
+ ; Set output path to the installation directory.
+ SetOutPath $INSTDIR\bin
+ File /oname=ghdl.exe ..\build\ghdl.exe
+
+ SetOutPath $INSTDIR
+ File /oname=COPYING.txt ..\..\..\COPYING
+
+ ; Write the installation path into the registry
+ WriteRegStr HKLM "Software\Ghdl" "Install_Dir" $INSTDIR
+ ; Write te version
+ WriteRegStr HKLM "Software\Ghdl" "Version" ${VERSION}
+
+ ; Write the uninstall keys for Windows
+ WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Ghdl" "DisplayName" "Ghdl"
+ WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Ghdl" "UninstallString" $INSTDIR\uninst-ghdl.exe
+ WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Ghdl" "NoModify" 1
+ WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Ghdl" "NoRepair" 1
+ WriteUninstaller $INSTDIR\uninst-ghdl.exe"
+
+SectionEnd
+
+Section "VHDL standard and ieee libraries"
+ SectionIn RO
+ SetOutPath $INSTDIR\lib\v87
+ File /r ..\lib\v87\std ..\lib\v87\ieee
+ SetOutPath $INSTDIR\lib\v93
+ File /r ..\lib\v93\std ..\lib\v93\ieee
+ SetOutPath $INSTDIR\lib\v08
+ File /r ..\lib\v08\std ..\lib\v08\ieee
+SectionEnd
+
+Section "Synopsys libraries (Recommended)"
+ SetOutPath $INSTDIR\lib\v87
+ File /r ..\lib\v87\synopsys
+ SetOutPath $INSTDIR\lib\v93
+ File /r ..\lib\v93\synopsys
+SectionEnd
+
+Section "Documentation (Recommended)"
+ SetOutPath $INSTDIR
+ File /oname=ghdl.htm ..\..\..\doc\ghdl.html
+SectionEnd
+
+Section "Add in PATH (Recommended)"
+ WriteRegDWORD HKLM "Software\Ghdl" "PathSet" 1
+ Push $INSTDIR\Bin
+ Call AddToPath
+SectionEnd
+
+; Optional section (can be disabled by the user)
+;Section "Start Menu Shortcuts"
+;
+; CreateDirectory "$SMPROGRAMS\Ghdl"
+; CreateShortCut "$SMPROGRAMS\Ghdl\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
+; CreateShortCut "$SMPROGRAMS\Ghdl\Ghdl.lnk" "$INSTDIR\example2.nsi" "" "$INSTDIR\example2.nsi" 0
+;
+;SectionEnd
+;
+
+;--------------------------------
+
+; Uninstaller
+
+Section "Uninstall"
+
+ ReadRegDWORD $0 HKLM "Software\Ghdl" "PathSet"
+ StrCmp $0 "1" "" path_not_set
+ Push $INSTDIR\Bin
+ Call un.RemoveFromPath
+
+path_not_set:
+
+ ; Remove registry keys
+ DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Ghdl"
+ DeleteRegKey HKLM Software\Ghdl
+
+ ; Remove files and uninstaller
+ Delete $INSTDIR\bin\ghdl.exe
+ Delete $INSTDIR\bin\ghdl.htm
+ Delete $INSTDIR\uninst-ghdl.exe
+ Delete $INSTDIR\COPYING.txt
+ RMDir $INSTDIR\bin
+ RMDir /r $INSTDIR\lib
+
+
+ ; Remove shortcuts, if any
+ ; Delete "$SMPROGRAMS\Ghdl\*.*"
+
+ ; Remove directories used
+ ; RMDir "$SMPROGRAMS\Ghdl"
+ RMDir "$INSTDIR"
+
+SectionEnd
+
+;;;;;;;; Misc functions
+
+; Author: Lilla (lilla@earthlink.net) 2003-06-13
+; function IsUserAdmin uses plugin \NSIS\PlusgIns\UserInfo.dll
+; This function is based upon code in \NSIS\Contrib\UserInfo\UserInfo.nsi
+; This function was tested under NSIS 2 beta 4 (latest CVS as of this writing).
+;
+; Usage:
+; Call IsUserAdmin
+; Pop $R0 ; at this point $R0 is "true" or "false"
+;
+Function IsUserAdmin
+Push $R0
+Push $R1
+Push $R2
+
+ClearErrors
+UserInfo::GetName
+IfErrors Win9x
+Pop $R1
+UserInfo::GetAccountType
+Pop $R2
+
+StrCmp $R2 "Admin" 0 Continue
+; Observation: I get here when running Win98SE. (Lilla)
+; The functions UserInfo.dll looks for are there on Win98 too,
+; but just don't work. So UserInfo.dll, knowing that admin isn't required
+; on Win98, returns admin anyway. (per kichik)
+; MessageBox MB_OK 'User "$R1" is in the Administrators group'
+StrCpy $R0 "true"
+Goto Done
+
+Continue:
+; You should still check for an empty string because the functions
+; UserInfo.dll looks for may not be present on Windows 95. (per kichik)
+StrCmp $R2 "" Win9x
+StrCpy $R0 "false"
+;MessageBox MB_OK 'User "$R1" is in the "$R2" group'
+Goto Done
+
+Win9x:
+; comment/message below is by UserInfo.nsi author:
+; This one means you don't need to care about admin or
+; not admin because Windows 9x doesn't either
+;MessageBox MB_OK "Error! This DLL can't run under Windows 9x!"
+StrCpy $R0 "true"
+
+Done:
+;MessageBox MB_OK 'User= "$R1" AccountType= "$R2" IsUserAdmin= "$R0"'
+
+Pop $R2
+Pop $R1
+Exch $R0
+FunctionEnd
+
+
+!define ALL_USERS
+
+!ifndef WriteEnvStr_RegKey
+ !ifdef ALL_USERS
+ !define WriteEnvStr_RegKey \
+ 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
+ !else
+ !define WriteEnvStr_RegKey 'HKCU "Environment"'
+ !endif
+!endif
+
+!verbose 3
+!include "WinMessages.NSH"
+!verbose 4
+
+; AddToPath - Adds the given dir to the search path.
+; Input - head of the stack
+; Note - Win9x systems requires reboot
+
+Function AddToPath
+ Exch $0
+ Push $1
+ Push $2
+ Push $3
+
+ # don't add if the path doesn't exist
+ IfFileExists "$0\*.*" "" AddToPath_done
+
+ ReadEnvStr $1 PATH
+ Push "$1;"
+ Push "$0;"
+ Call StrStr
+ Pop $2
+ StrCmp $2 "" "" AddToPath_done
+ Push "$1;"
+ Push "$0\;"
+ Call StrStr
+ Pop $2
+ StrCmp $2 "" "" AddToPath_done
+ GetFullPathName /SHORT $3 $0
+ Push "$1;"
+ Push "$3;"
+ Call StrStr
+ Pop $2
+ StrCmp $2 "" "" AddToPath_done
+ Push "$1;"
+ Push "$3\;"
+ Call StrStr
+ Pop $2
+ StrCmp $2 "" "" AddToPath_done
+
+ ReadRegStr $1 ${WriteEnvStr_RegKey} "PATH"
+ StrCpy $2 $1 1 -1 # copy last char
+ StrCmp $2 ";" 0 +2 # if last char == ;
+ StrCpy $1 $1 -1 # remove last char
+ StrCmp $1 "" AddToPath_NTdoIt
+ StrCpy $0 "$1;$0"
+ AddToPath_NTdoIt:
+ WriteRegExpandStr ${WriteEnvStr_RegKey} "PATH" $0
+ SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
+
+ AddToPath_done:
+ Pop $3
+ Pop $2
+ Pop $1
+ Pop $0
+FunctionEnd
+
+; RemoveFromPath - Remove a given dir from the path
+; Input: head of the stack
+
+Function un.RemoveFromPath
+ Exch $0
+ Push $1
+ Push $2
+ Push $3
+ Push $4
+ Push $5
+ Push $6
+
+ IntFmt $6 "%c" 26 # DOS EOF
+
+ ReadRegStr $1 ${WriteEnvStr_RegKey} "PATH"
+ StrCpy $5 $1 1 -1 # copy last char
+ StrCmp $5 ";" +2 # if last char != ;
+ StrCpy $1 "$1;" # append ;
+ Push $1
+ Push "$0;"
+ Call un.StrStr ; Find `$0;` in $1
+ Pop $2 ; pos of our dir
+ StrCmp $2 "" unRemoveFromPath_done
+ ; else, it is in path
+ # $0 - path to add
+ # $1 - path var
+ StrLen $3 "$0;"
+ StrLen $4 $2
+ StrCpy $5 $1 -$4 # $5 is now the part before the path to remove
+ StrCpy $6 $2 "" $3 # $6 is now the part after the path to remove
+ StrCpy $3 $5$6
+
+ StrCpy $5 $3 1 -1 # copy last char
+ StrCmp $5 ";" 0 +2 # if last char == ;
+ StrCpy $3 $3 -1 # remove last char
+
+ WriteRegExpandStr ${WriteEnvStr_RegKey} "PATH" $3
+ SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
+
+ unRemoveFromPath_done:
+ Pop $6
+ Pop $5
+ Pop $4
+ Pop $3
+ Pop $2
+ Pop $1
+ Pop $0
+FunctionEnd
+
+###########################################
+# Utility Functions #
+###########################################
+
+; IsNT
+; no input
+; output, top of the stack = 1 if NT or 0 if not
+;
+; Usage:
+; Call IsNT
+; Pop $R0
+; ($R0 at this point is 1 or 0)
+
+!macro IsNT un
+Function ${un}IsNT
+ Push $0
+ ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
+ StrCmp $0 "" 0 IsNT_yes
+ ; we are not NT.
+ Pop $0
+ Push 0
+ Return
+
+ IsNT_yes:
+ ; NT!!!
+ Pop $0
+ Push 1
+FunctionEnd
+!macroend
+!insertmacro IsNT ""
+;!insertmacro IsNT "un."
+
+; StrStr
+; input, top of stack = string to search for
+; top of stack-1 = string to search in
+; output, top of stack (replaces with the portion of the string remaining)
+; modifies no other variables.
+;
+; Usage:
+; Push "this is a long ass string"
+; Push "ass"
+; Call StrStr
+; Pop $R0
+; ($R0 at this point is "ass string")
+
+!macro StrStr un
+Function ${un}StrStr
+Exch $R1 ; st=haystack,old$R1, $R1=needle
+ Exch ; st=old$R1,haystack
+ Exch $R2 ; st=old$R1,old$R2, $R2=haystack
+ Push $R3
+ Push $R4
+ Push $R5
+ StrLen $R3 $R1
+ StrCpy $R4 0
+ ; $R1=needle
+ ; $R2=haystack
+ ; $R3=len(needle)
+ ; $R4=cnt
+ ; $R5=tmp
+ loop:
+ StrCpy $R5 $R2 $R3 $R4
+ StrCmp $R5 $R1 done
+ StrCmp $R5 "" done
+ IntOp $R4 $R4 + 1
+ Goto loop
+done:
+ StrCpy $R1 $R2 "" $R4
+ Pop $R5
+ Pop $R4
+ Pop $R3
+ Pop $R2
+ Exch $R1
+FunctionEnd
+!macroend
+!insertmacro StrStr ""
+!insertmacro StrStr "un."
+
diff --git a/scripts/windows/mcode/ghdlfilter.adb b/scripts/windows/mcode/ghdlfilter.adb
new file mode 100644
index 000000000..d75526dbd
--- /dev/null
+++ b/scripts/windows/mcode/ghdlfilter.adb
@@ -0,0 +1,132 @@
+--
+-- Preprocessor to handle library source metacomments
+--
+-- Limitations:
+-- - line metacomments must occur at end of line with no trailing space before the line break
+-- - block metacomments must start in column 1
+--
+-- Supported line metacomments:
+--
+-- --!V87
+-- --V87
+-- --V93
+-- --V08
+--
+-- Supported block metacomments:
+--
+-- --START-!V87
+-- --END-!V87
+--
+-- --START-V93
+-- --END-V93
+--
+-- --START-V08
+-- --END-V08
+--
+--
+with Ada.Command_Line; use Ada.Command_Line;
+with Ada.Text_IO; use Ada.Text_IO;
+
+procedure Ghdlfilter is
+ type Mode_Kind is (Mode_93, Mode_87, Mode_08);
+ Mode : Mode_Kind;
+
+ Line : String (1 .. 128);
+ Len : Natural;
+
+ Comment : Boolean;
+ Block_Comment : Boolean;
+begin
+ if Argument_Count /= 1 then
+ Put_Line (Standard_Error, "usage: " & Command_Name & " -v93|-v87|-v08");
+ return;
+ end if;
+
+ if Argument (1) = "-v93" then
+ Mode := Mode_93;
+ elsif Argument (1) = "-v87" then
+ Mode := Mode_87;
+ elsif Argument (1) = "-v08" then
+ Mode := Mode_08;
+ else
+ Put_Line (Standard_Error, "bad mode");
+ return;
+ end if;
+
+ Block_Comment := False;
+
+ loop
+ exit when End_Of_File;
+ Get_Line (Line, Len);
+
+ Comment := Block_Comment;
+
+ --
+ -- look for line metacomments
+ --
+ if Len > 6 then
+
+ if Mode = Mode_87 and ( Line (Len - 5 .. Len) = "--!V87" ) then
+ Comment := True;
+ end if;
+
+ end if;
+
+
+ if Len > 5 then
+
+ if Mode = Mode_87 and ( (Line (Len - 4 .. Len) = "--V93") or (Line (Len - 4 .. Len) = "--V08") ) then
+ Comment := True;
+
+ elsif Mode = Mode_93 and ( (Line (Len - 4 .. Len) = "--V87") or (Line (Len - 4 .. Len) = "--V08") ) then
+ Comment := True;
+
+ elsif Mode = Mode_08 and ( (Line (Len - 4 .. Len) = "--V87") or (Line (Len - 4 .. Len) = "--V93") ) then
+ Comment := True;
+ end if;
+
+ end if;
+
+ --
+ -- look for block metacomment start
+ --
+ if Len = 12
+ and then Mode /= Mode_93
+ and then Line (1 .. 12) = "--START-!V87" then
+ Block_Comment := True;
+ end if;
+
+ if Len = 11
+ and then Mode /= Mode_93
+ and then Line (1 .. 11) = "--START-V93" then
+ Block_Comment := True;
+ end if;
+
+ if Len = 11
+ and then Mode /= Mode_08
+ and then Line (1 .. 11) = "--START-V08" then
+ Block_Comment := True;
+ end if;
+
+ --
+ -- look for block metacomment end
+ --
+ if Len = 9 and then ( (Line (1 .. 9) = "--END-V93") or (Line (1 .. 9) = "--END-V08") ) then
+ Block_Comment := False;
+ end if;
+
+ if Len = 10 and then ( Line (1 .. 10) = "--END-!V87" ) then
+ Block_Comment := False;
+ end if;
+
+ --
+ -- comment output lines as needed
+ --
+ if Comment then
+ Put ("-- ");
+ end if;
+
+ Put_Line (Line (1 .. Len));
+
+ end loop;
+end Ghdlfilter;
diff --git a/scripts/windows/mcode/ghdlversion.adb b/scripts/windows/mcode/ghdlversion.adb
new file mode 100644
index 000000000..d2f1c28be
--- /dev/null
+++ b/scripts/windows/mcode/ghdlversion.adb
@@ -0,0 +1,30 @@
+with Ada.Text_IO; use Ada.Text_IO;
+with Ada.Strings.Fixed; use Ada.Strings.Fixed;
+
+procedure Ghdlversion is
+ Line : String (1 .. 128);
+ Len : Natural;
+ Pos : Natural;
+ E : Natural;
+begin
+ loop
+ exit when End_Of_File;
+ Get_Line (Line, Len);
+
+ -- Search GHDL
+ Pos := Index (Line (1 .. Len), "GHDL ");
+ if Pos /= 0 then
+ Pos := Pos + 5;
+ E := Pos;
+ while Line (E) in '0' .. '9'
+ or Line (E) in 'a' .. 'z'
+ or Line (E) = '.'
+ loop
+ exit when E = Len;
+ E := E + 1;
+ end loop;
+ Put_Line ("!define VERSION """ & Line (Pos .. E - 1) & """");
+ return;
+ end if;
+ end loop;
+end Ghdlversion;
diff --git a/scripts/windows/mcode/grt-backtraces-impl.ads b/scripts/windows/mcode/grt-backtraces-impl.ads
new file mode 100644
index 000000000..81db677ed
--- /dev/null
+++ b/scripts/windows/mcode/grt-backtraces-impl.ads
@@ -0,0 +1,3 @@
+with Grt.Backtraces.Jit;
+
+package Grt.Backtraces.Impl renames Grt.Backtraces.Jit;
diff --git a/scripts/windows/mcode/grt-modules.adb b/scripts/windows/mcode/grt-modules.adb
new file mode 100644
index 000000000..de5eb79b8
--- /dev/null
+++ b/scripts/windows/mcode/grt-modules.adb
@@ -0,0 +1,39 @@
+-- GHDL Run Time (GRT) - Modules.
+-- Copyright (C) 2005 Tristan Gingold
+--
+-- GHDL is free software; you can redistribute it and/or modify it under
+-- the terms of the GNU General Public License as published by the Free
+-- Software Foundation; either version 2, or (at your option) any later
+-- version.
+--
+-- GHDL is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or
+-- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+-- for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with GCC; see the file COPYING. If not, write to the Free
+-- Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+-- 02111-1307, USA.
+with System.Storage_Elements; -- Work around GNAT bug.
+with Grt.Vcd;
+with Grt.Vpi;
+with Grt.Waves;
+with Grt.Vital_Annotate;
+with Grt.Disp_Tree;
+with Grt.Disp_Rti;
+with Grt.Backtraces;
+
+package body Grt.Modules is
+ procedure Register_Modules is
+ begin
+ -- List of modules to be registered.
+ Grt.Disp_Tree.Register;
+ Grt.Vcd.Register;
+ Grt.Waves.Register;
+ Grt.Vpi.Register;
+ Grt.Vital_Annotate.Register;
+ Grt.Disp_Rti.Register;
+ Grt.Backtraces.Register;
+ end Register_Modules;
+end Grt.Modules;
diff --git a/scripts/windows/mcode/ortho_code-x86-flags.ads b/scripts/windows/mcode/ortho_code-x86-flags.ads
new file mode 100644
index 000000000..8915f3122
--- /dev/null
+++ b/scripts/windows/mcode/ortho_code-x86-flags.ads
@@ -0,0 +1,2 @@
+with Ortho_Code.X86.Flags_Windows;
+package Ortho_Code.X86.Flags renames Ortho_Code.X86.Flags_Windows;
diff --git a/scripts/windows/mcode/winbuild.bat b/scripts/windows/mcode/winbuild.bat
new file mode 100644
index 000000000..670b77d1e
--- /dev/null
+++ b/scripts/windows/mcode/winbuild.bat
@@ -0,0 +1,20 @@
+call windows\compile
+if errorlevel 1 goto end
+
+call windows\complib
+if errorlevel 1 goto end
+
+strip build\ghdl.exe
+
+gnatmake windows/ghdlversion -o windows/ghdlversion.exe
+windows\ghdlversion < ..\..\src\version.ads > windows\version.nsi
+
+"c:\Program Files\NSIS\makensis" windows\ghdl.nsi
+if errorlevel 1 goto end
+
+exit /b 0
+
+:end
+echo "Error during compilation"
+exit /b 1
+
diff --git a/scripts/windows/mcode/windows_default_path.adb b/scripts/windows/mcode/windows_default_path.adb
new file mode 100644
index 000000000..c627356f9
--- /dev/null
+++ b/scripts/windows/mcode/windows_default_path.adb
@@ -0,0 +1,68 @@
+-- Find installation path (using executable).
+-- Copyright (C) 2002 - 2016 Tristan Gingold
+--
+-- GHDL is free software; you can redistribute it and/or modify it under
+-- the terms of the GNU General Public License as published by the Free
+-- Software Foundation; either version 2, or (at your option) any later
+-- version.
+--
+-- GHDL is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or
+-- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+-- for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with GCC; see the file COPYING. If not, write to the Free
+-- Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+-- 02111-1307, USA.
+--
+-- As a special exception, if other files instantiate generics from this
+-- unit, or you link this unit with other files to produce an executable,
+-- this unit does not by itself cause the resulting executable to be
+-- covered by the GNU General Public License. This exception does not
+-- however invalidate any other reasons why the executable file might be
+-- covered by the GNU Public License.
+
+with Interfaces.C; use Interfaces.C;
+with System; use System;
+
+package body Windows_Default_Path is
+
+ subtype DWORD is Interfaces.C.Unsigned_Long;
+ subtype HINSTANCE is Address;
+ function GetModuleFileName (Inst : HINSTANCE; Buf : Address; Size : DWORD)
+ return DWORD;
+ pragma Import (Stdcall, GetModuleFileName, "GetModuleFileNameA");
+
+ function Get_Windows_Exec_Path return String
+ is
+ File : String (1 .. 256);
+ Size : DWORD;
+ P : Natural;
+ begin
+ -- Get exe file path.
+ Size := GetModuleFileName (Null_Address, File'Address, File'Length);
+ if Size = 0 or Size = File'Length then
+ return "{cannot find install path}\lib";
+ end if;
+
+ -- Remove Program file.
+ P := Natural (Size);
+ while P > 0 loop
+ exit when File (P) = '\';
+ exit when File (P) = ':' and P = 2;
+ P := P - 1;
+ end loop;
+ if File (P) = '\' and P > 1 then
+ -- Remove directory
+ P := P - 1;
+ while P > 0 loop
+ exit when File (P) = '\';
+ exit when File (P) = ':' and P = 2;
+ P := P - 1;
+ end loop;
+ end if;
+
+ return File (1 .. P);
+ end Get_Windows_Exec_Path;
+end Windows_Default_Path;
diff --git a/scripts/windows/mcode/windows_default_path.ads b/scripts/windows/mcode/windows_default_path.ads
new file mode 100644
index 000000000..9da3be559
--- /dev/null
+++ b/scripts/windows/mcode/windows_default_path.ads
@@ -0,0 +1,30 @@
+-- Find installation path (using executable).
+-- Copyright (C) 2002 - 2016 Tristan Gingold
+--
+-- GHDL is free software; you can redistribute it and/or modify it under
+-- the terms of the GNU General Public License as published by the Free
+-- Software Foundation; either version 2, or (at your option) any later
+-- version.
+--
+-- GHDL is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or
+-- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+-- for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with GCC; see the file COPYING. If not, write to the Free
+-- Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+-- 02111-1307, USA.
+--
+-- As a special exception, if other files instantiate generics from this
+-- unit, or you link this unit with other files to produce an executable,
+-- this unit does not by itself cause the resulting executable to be
+-- covered by the GNU General Public License. This exception does not
+-- however invalidate any other reasons why the executable file might be
+-- covered by the GNU Public License.
+
+package Windows_Default_Path is
+ -- Get the default path from executable name.
+ -- This function is called during elaboration!
+ function Get_Windows_Exec_Path return String;
+end Windows_Default_Path;