@@ -0,0 +1,119 @@
1+{ stdenv
2+, lib
3+, fetchFromGitHub
4+
5+# Docs cause an immense increase in build time, up to 2 additional hours
6+, withDocs ? false
7+, dosbox
8+, ghostscript
9+, withGUI ? false
10+}:
11+
12+stdenv.mkDerivation rec {
13+ pname = "open-watcom-v2";
14+ version = "unstable-2021-11-30";
15+ name = "${pname}-unwrapped-${version}";
16+
17+ src = fetchFromGitHub {
18+ owner = "open-watcom";
19+ repo = "open-watcom-v2";
20+ rev = "982c958eb4840e1c6a98773ba0600f652500f5a7";
21+ sha256 = "18dp9nd1gjnpd1870149v67vzxbna25l6zi052z1r51xvaqwc3cx";
22+ };
23+
24+ postPatch = ''
25+ patchShebangs *.sh
26+
27+ for dateSource in cmnvars.sh bld/wipfc/configure; do
28+ substituteInPlace $dateSource \
29+ --replace '`date ' '`date -ud "@$SOURCE_DATE_EPOCH" '
30+ done
31+
32+ substituteInPlace bld/watcom/h/banner.h \
33+ --replace '__DATE__' "\"$(date -ud "@$SOURCE_DATE_EPOCH" +'%b %d %Y')\"" \
34+ --replace '__TIME__' "\"$(date -ud "@$SOURCE_DATE_EPOCH" +'%T')\""
35+
36+ substituteInPlace build/makeinit \
37+ --replace '%__CYEAR__' '%OWCYEAR'
38+ '' + lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
39+ substituteInPlace build/mif/local.mif \
40+ --replace '-static' ""
41+ '';
42+
43+ nativeBuildInputs = [ ]
44+ ++ lib.optional (withDocs || withGUI) dosbox
45+ ++ lib.optional withDocs ghostscript;
46+
47+ configurePhase = ''
48+ runHook preConfigure
49+
50+ export OWROOT=$(realpath $PWD)
51+ export OWTOOLS=${if stdenv.cc.isClang then "CLANG" else "GCC"}
52+ export OWDOCBUILD=${if withDocs then "1" else "0"}
53+ export OWGHOSTSCRIPTPATH=${lib.optionalString withDocs "${ghostscript}/bin"}
54+ export OWGUINOBUILD=${if withGUI then "0" else "1"}
55+ export OWNOBUILD=
56+ export OWDISTRBUILD=0
57+ export OWDOSBOX=${lib.optionalString (withDocs || withGUI) "${dosbox}/bin/dosbox"}
58+ export OWVERBOSE=0
59+ export OWRELROOT=$out
60+
61+ source cmnvars.sh
62+
63+ runHook postConfigure
64+ '';
65+
66+ buildPhase = ''
67+ runHook preBuild
68+
69+ ./build.sh build
70+
71+ runHook postBuild
72+ '';
73+
74+ installPhase = ''
75+ runHook preInstall
76+
77+ ./build.sh cprel
78+
79+ runHook postInstall
80+ '';
81+
82+ # Stripping breaks many tools
83+ dontStrip = true;
84+
85+ meta = with lib; {
86+ description = "The v2 fork of the Open Watcom suite of compilers and tools";
87+ longDescription = ''
88+ A fork of Open Watcom: A C/C++/Fortran compiler and assembler suite
89+ targeting a multitude of architectures (x86, IA-32, Alpha AXP, MIPS,
90+ PowerPC) and operating systems (DOS, OS/2, Windows, Linux).
91+
92+ Main differences from Open Watcom 1.9:
93+
94+ - New two-phase build system - Open Watcom can be built by the host's
95+ native C/C++ compiler or by itself
96+ - Code generator properly initializes pointers by DLL symbol addresses
97+ - DOS tools now support long file names (LFN) if appropriate LFN driver
98+ is loaded by DOS
99+ - Open Watcom is ported to 64-bit hosts (Win64, Linux x64)
100+ - Librarian supports x64 CPU object modules and libraries
101+ - RDOS 32-bit C run-time compact memory model libraries are fixed
102+ - Resource compiler and Resource editors support Win64 executables
103+ - Open Watcom text editor is now self-contained, it can be used as
104+ standalone tool without any requirements for any additional files or
105+ configuration
106+ - Broken C++ compiler pre-compiled header template support is fixed
107+ - Many C++ compiler crashes are fixed
108+ - Debugger has no length limit for any used environment variable
109+ '' + lib.optionalString (!withDocs) ''
110+
111+ The documentation has been excluded from this build for build time reasons. It can be found here:
112+ https://github.com/open-watcom/open-watcom-v2/wiki/Open-Watcom-Documentation
113+ '';
114+ homepage = "https://open-watcom.github.io";
115+ license = licenses.watcom;
116+ platforms = [ "x86_64-linux" "i686-linux" "x86_64-darwin" "x86_64-windows" "i686-windows" ];
117+ maintainers = with maintainers; [ OPNA2608 ];
118+ };
119+}