about summary refs log tree commit diff
path: root/nixpkgs/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/mescc-tools/build.kaem
blob: 128ff360fd2c9b133d788d4e613916e1b0095c55 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# This is a modified version of stage0-posix/x86/mescc-tools-full-kaem.kaem
# https://github.com/oriansj/stage0-posix-x86/blob/56e6b8df3e95f4bc04f8b420a4cd8c82c70b9efa/mescc-tools-full-kaem.kaem
# - Paths to build inputs have been changed for nix

# Mes --- Maxwell Equations of Software
# Copyright © 2017,2019 Jan Nieuwenhuizen <janneke@gnu.org>
# Copyright © 2017,2019 Jeremiah Orians
#
# This file is part of Mes.
#
# Mes 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 3 of the License, or (at
# your option) any later version.
#
# Mes 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 Mes.  If not, see <http://www.gnu.org/licenses/>.

${mkdir} -p ${out}/bin
${cp} ${M2} ${out}/bin/M2
${chmod} 0555 ${out}/bin/M2
${cp} ${M1} ${out}/bin/M1
${chmod} 0555 ${out}/bin/M1
${cp} ${hex2} ${out}/bin/hex2
${chmod} 0555 ${out}/bin/hex2

# M2-Mesoplanet searches for runtime dependencies in environment variables
# We can hardcode them with the "replace" utility from mescc-tools-extra
${replace} \
	--file ${src}/M2-Mesoplanet/cc.c \
	--output ./cc_patched.c \
	--match-on "env_lookup(\"M2LIBC_PATH\")" \
	--replace-with "\"${m2libc}\""
${replace} \
	--file ${src}/M2-Mesoplanet/cc_spawn.c \
	--output ./cc_spawn_patched.c \
	--match-on "env_lookup(\"PATH\")" \
	--replace-with "\"${out}/bin:\""

###############################################
# Phase-12 Build M2-Mesoplanet from M2-Planet #
###############################################

${M2} --architecture ${m2libcArch} \
  -f ${m2libc}/sys/types.h \
  -f ${m2libc}/stddef.h \
  -f ${m2libc}/${m2libcArch}/linux/fcntl.c \
  -f ${m2libc}/fcntl.c \
  -f ${m2libc}/${m2libcArch}/linux/unistd.c \
  -f ${m2libc}/${m2libcArch}/linux/sys/stat.c \
  -f ${m2libc}/stdlib.c \
  -f ${m2libc}/stdio.h \
  -f ${m2libc}/stdio.c \
  -f ${m2libc}/string.c \
  -f ${m2libc}/bootstrappable.c \
  -f ${src}/M2-Mesoplanet/cc.h \
  -f ${src}/M2-Mesoplanet/cc_globals.c \
  -f ${src}/M2-Mesoplanet/cc_env.c \
  -f ${src}/M2-Mesoplanet/cc_reader.c \
  -f ./cc_spawn_patched.c \
  -f ${src}/M2-Mesoplanet/cc_core.c \
  -f ${src}/M2-Mesoplanet/cc_macro.c \
  -f ./cc_patched.c \
  --debug \
  -o ./M2-Mesoplanet-1.M1

${blood-elf-0} ${endianFlag} ${bloodFlag} -f ./M2-Mesoplanet-1.M1 -o ./M2-Mesoplanet-1-footer.M1

${M1} --architecture ${m2libcArch} \
  ${endianFlag} \
  -f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \
  -f ${m2libc}/${m2libcArch}/libc-full.M1 \
  -f ./M2-Mesoplanet-1.M1 \
  -f ./M2-Mesoplanet-1-footer.M1 \
  -o ./M2-Mesoplanet-1.hex2

${hex2} --architecture ${m2libcArch} \
  ${endianFlag} \
  --base-address ${baseAddress} \
  -f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \
  -f ./M2-Mesoplanet-1.hex2 \
  -o ${out}/bin/M2-Mesoplanet

#################################################
# Phase-13 Build final blood-elf from C sources #
#################################################

${M2} --architecture ${m2libcArch} \
	-f ${m2libc}/sys/types.h \
	-f ${m2libc}/stddef.h \
	-f ${m2libc}/${m2libcArch}/linux/fcntl.c \
	-f ${m2libc}/fcntl.c \
	-f ${m2libc}/${m2libcArch}/linux/unistd.c \
	-f ${m2libc}/stdlib.c \
	-f ${m2libc}/stdio.h \
	-f ${m2libc}/stdio.c \
	-f ${m2libc}/bootstrappable.c \
	-f ${src}/mescc-tools/stringify.c \
	-f ${src}/mescc-tools/blood-elf.c \
	--debug \
	-o ./blood-elf-1.M1

${blood-elf-0} ${endianFlag} ${bloodFlag} -f ./blood-elf-1.M1 -o ./blood-elf-1-footer.M1

${M1} --architecture ${m2libcArch} \
	${endianFlag} \
	-f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \
	-f ${m2libc}/${m2libcArch}/libc-full.M1 \
	-f ./blood-elf-1.M1 \
	-f ./blood-elf-1-footer.M1 \
	-o ./blood-elf-1.hex2

${hex2} --architecture ${m2libcArch} \
	${endianFlag} \
	--base-address ${baseAddress} \
	-f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \
	-f ./blood-elf-1.hex2 \
	-o ${out}/bin/blood-elf

# Now we have our shipping debuggable blood-elf, the rest will be down hill from
# here as we have ALL of the core pieces of compiling and assembling debuggable
# programs in a debuggable form with corresponding C source code.

#############################################
# Phase-14 Build get_machine from C sources #
#############################################

${M2} --architecture ${m2libcArch} \
	-f ${m2libc}/sys/types.h \
	-f ${m2libc}/stddef.h \
	-f ${m2libc}/${m2libcArch}/linux/unistd.c \
	-f ${m2libc}/${m2libcArch}/linux/fcntl.c \
	-f ${m2libc}/fcntl.c \
	-f ${m2libc}/stdlib.c \
	-f ${m2libc}/stdio.h \
	-f ${m2libc}/stdio.c \
	-f ${m2libc}/bootstrappable.c \
	-f ${src}/mescc-tools/get_machine.c \
	--debug \
	-o get_machine.M1

${out}/bin/blood-elf ${endianFlag} ${bloodFlag} -f ./get_machine.M1 -o ./get_machine-footer.M1

${M1} --architecture ${m2libcArch} \
	${endianFlag} \
	-f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \
	-f ${m2libc}/${m2libcArch}/libc-full.M1 \
	-f ./get_machine.M1 \
	-f ./get_machine-footer.M1 \
	-o ./get_machine.hex2

${hex2} --architecture ${m2libcArch} \
	${endianFlag} \
	--base-address ${baseAddress} \
	-f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \
	-f ./get_machine.hex2 \
	-o ${out}/bin/get_machine

############################################
# Phase-15 Build M2-Planet from M2-Planet  #
############################################

${M2} --architecture ${m2libcArch} \
	-f ${m2libc}/sys/types.h \
	-f ${m2libc}/stddef.h \
	-f ${m2libc}/${m2libcArch}/linux/unistd.c \
	-f ${m2libc}/${m2libcArch}/linux/fcntl.c \
	-f ${m2libc}/fcntl.c \
	-f ${m2libc}/stdlib.c \
	-f ${m2libc}/stdio.h \
	-f ${m2libc}/stdio.c \
	-f ${m2libc}/bootstrappable.c \
	-f ${src}/M2-Planet/cc.h \
	-f ${src}/M2-Planet/cc_globals.c \
	-f ${src}/M2-Planet/cc_reader.c \
	-f ${src}/M2-Planet/cc_strings.c \
	-f ${src}/M2-Planet/cc_types.c \
	-f ${src}/M2-Planet/cc_core.c \
	-f ${src}/M2-Planet/cc_macro.c \
	-f ${src}/M2-Planet/cc.c \
	--debug \
	-o ./M2-1.M1

${out}/bin/blood-elf ${endianFlag} ${bloodFlag} -f ./M2-1.M1 -o ./M2-1-footer.M1

${M1} --architecture ${m2libcArch} \
	${endianFlag} \
	-f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \
	-f ${m2libc}/${m2libcArch}/libc-full.M1 \
	-f ./M2-1.M1 \
	-f ./M2-1-footer.M1 \
	-o ./M2-1.hex2

${hex2} --architecture ${m2libcArch} \
	${endianFlag} \
	--base-address ${baseAddress} \
	-f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \
	-f ./M2-1.hex2 \
	-o ${out}/bin/M2-Planet