File: simple.make

package info (click to toggle)
mes 0.24.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 6,908 kB
  • sloc: ansic: 24,104; lisp: 11,490; sh: 6,609; asm: 187; makefile: 36
file content (269 lines) | stat: -rw-r--r-- 6,879 bytes parent folder | download
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# GNU Mes --- Maxwell Equations of Software
# Copyright © 2019 Jeremiah Orians <jeremiah@pdp10.guru>
# Copyright © 2018,2019,2020,2021,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
#
# This file is part of GNU Mes.
#
# GNU 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.
#
# GNU 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 GNU Mes.  If not, see <http://www.gnu.org/licenses/>.

CC = gcc
MES_CPU=x86_64
MES = bin/mes-gcc

MESCC_CPU=x86
MES = bin/mes-gcc

#CC = i686-unknown-linux-gnu-gcc
#MES_CPU = x86

M2_PLANET = M2-Planet
M2_PLANET_ARCH = x86
M2_PLANET_FUBAR = i386

#M2_PLANET_ARCH = amd64
#M2_PLANET_FUBAR = amd64
M2_PLANET_FLAGS = --bootstrap-mode --debug --architecture $(M2_PLANET_ARCH)

CFLAGS:=					\
  $(CFLAGS)					\
 -D _GNU_SOURCE					\
 -D const=					\
 -ggdb						\
 -D SYSTEM_LIBC=1				\
 -D 'MES_VERSION="git"'				\
 -D 'MES_PKGDATADIR="/usr/local/share/mes"'	\
 -I include					\
 -fno-builtin

LIBMES_SOURCES =				\
 src/builtins.c					\
 src/core.c					\
 src/display.c					\
 src/eval-apply.c				\
 src/gc.c					\
 src/hash.c					\
 src/lib.c					\
 src/math.c					\
 src/module.c					\
 src/posix.c					\
 src/reader.c					\
 src/string.c					\
 src/stack.c					\
 src/struct.c					\
 src/symbol.c					\
 src/vector.c

MES_SOURCES =					\
 $(LIBMES_SOURCES)				\
 src/mes.c

TEST_GC_SOURCES =				\
 $(LIBMES_SOURCES)				\
 src/test/gc.c

M2_SOURCES =					\
 lib/linux/x86-mes-m2/crt1.c			\
 lib/linux/x86-mes-m2/_exit.c			\
 lib/linux/x86-mes-m2/_write.c			\
 lib/mes/globals.c	                        \
 lib/m2/cast.c					\
 lib/m2/exit.c					\
 lib/mes/mini-write.c				\
 lib/linux/x86-mes-m2/syscall.c			\
 lib/stub/__raise.c				\
 lib/linux/brk.c				\
 lib/m2/malloc.c				\
 lib/string/memset.c				\
						\
 lib/m2/read.c					\
 lib/mes/fdgetc.c				\
 lib/stdio/getchar.c				\
 lib/stdio/putchar.c				\
 lib/m2/open.c					\
 lib/m2/mes_open.c				\
 lib/string/strlen.c				\
 lib/mes/eputs.c				\
 lib/mes/fdputc.c				\
 lib/mes/eputc.c				\
						\
 lib/mes/__assert_fail.c			\
 lib/mes/assert_msg.c				\
						\
 lib/mes/fdputc.c				\
 lib/string/strncmp.c				\
 lib/posix/getenv.c				\
 lib/mes/fdputs.c				\
 lib/mes/ntoab.c				\
 lib/ctype/isdigit.c				\
 lib/ctype/isxdigit.c				\
 lib/ctype/isspace.c				\
 lib/ctype/isnumber.c				\
 lib/mes/abtol.c				\
 lib/stdlib/atoi.c				\
 lib/string/memcpy.c				\
 lib/stdlib/free.c				\
 lib/stdlib/realloc.c				\
 lib/string/strcpy.c				\
 lib/mes/itoa.c					\
 lib/mes/ltoa.c					\
 lib/mes/fdungetc.c				\
 lib/posix/setenv.c				\
 lib/linux/access.c				\
 lib/m2/chmod.c					\
 lib/linux/ioctl3.c  				\
 lib/m2/isatty.c				\
 lib/linux/fork.c				\
 lib/m2/execve.c				\
 lib/m2/execv.c					\
 lib/m2/waitpid.c				\
 lib/linux/gettimeofday.c			\
 lib/m2/clock_gettime.c				\
 lib/m2/time.c					\
 lib/linux/_getcwd.c				\
 lib/m2/getcwd.c				\
 lib/linux/dup.c				\
 lib/linux/dup2.c				\
 lib/string/strcmp.c				\
 lib/string/memcmp.c				\
 lib/linux/unlink.c				\
 src/m2.c

M2_TODO =					\
 lib/m2/file_print.c				\
 lib/mes/ntoab.c				\
 lib/mes/fdgetc.c				\
 lib/mes/fdungetc.c

INCLUDES =					\
 include/mes/builtins.h				\
 include/mes/constants.h			\
 include/mes/mes.h				\
 include/mes/lib.h				\
 include/mes/lib-mini.h

MES_LIBC =					\
 lib/linux/$(MES_CPU)-mes-gcc/syscall.c		\
 lib/linux/_read.c				\
 lib/linux/_read.c				\
 lib/mes/__buffered_read.c

GCC_SOURCES =					\
 lib/mes/__mes_debug.c				\
 lib/mes/cast.c					\
 lib/mes/eputc.c				\
 lib/mes/eputs.c				\
 lib/mes/fdgetc.c				\
 lib/mes/fdputc.c				\
 lib/mes/fdputs.c				\
 lib/mes/fdungetc.c				\
 lib/mes/mes_open.c				\
 lib/mes/ntoab.c				\
 lib/mes/itoa.c					\
 lib/mes/ltoa.c					\
 lib/mes/assert_msg.c				\
 src/cc.c					\
 src/globals.c

mes-gcc: bin/mes-gcc
mes-m2: bin/mes-m2

gc-gcc: bin/gc-gcc
gc-m2: bin/gc-m2

bin/mes-gcc: simple.make $(GCC_SOURCES) $(MES_SOURCES) $(INCLUDES) | bin
	$(CC) $(CFLAGS) -o $@ $(GCC_SOURCES) $(MES_SOURCES)
	cp -f $@ bin/mes

bin/gc-gcc: simple.make $(GCC_SOURCES) $(TEST_GC_SOURCES) $(INCLUDES) | bin
	$(CC) $(CFLAGS) -D GC_TEST=1 -o $@ $(GCC_SOURCES) $(TEST_GC_SOURCES)

M2_PLANET_INCLUDES =				\
 include/m2/lib.h				\
 include/linux/x86/syscall.h			\
 include/mes/mes.h				\
 include/mes/builtins.h				\
 include/mes/constants.h			\
 include/mes/symbols.h				\
 include/linux/$(M2_PLANET_ARCH)/syscall.h

M2_PLANET_SOURCES =				\
 $(M2_PLANET_INCLUDES:%.h=%.h)			\
 $(M2_SOURCES)

m2/mes-m2.M1: simple.make $(M2_PLANET_SOURCES) $(MES_SOURCES) $(M2_PLANET_INCLUDES) | m2
	$(M2_PLANET) $(M2_PLANET_FLAGS) $(M2_PLANET_SOURCES:%=-f %)  $(MES_SOURCES:%.c=-f %.c) -o $@ || rm -f $@

m2/mes-m2.blood-elf.M1: m2/mes-m2.M1 | m2
	blood-elf --little-endian -f $< -o $@

m2/mes-m2.hex2: m2/mes-m2.blood-elf.M1
	M1					\
	    --architecture $(M2_PLANET_ARCH)	\
	    --little-endian			\
	    -f lib/m2/x86/x86_defs.M1		\
	    -f lib/x86-mes/x86.M1		\
	    -f lib/linux/x86-mes-m2/crt1.M1	\
	    -f m2/mes-m2.M1			\
	    -f m2/mes-m2.blood-elf.M1		\
	    -o $@

bin/mes-m2: m2/mes-m2.hex2 | bin
	hex2						\
	    --architecture $(M2_PLANET_ARCH)		\
	    --little-endian				\
	    --base-address 0x1000000			\
	    -f lib/linux/x86-mes/elf32-header.hex2	\
	    -f m2/mes-m2.hex2				\
	    -o $@
	cp -f $@ bin/mes

# Clean up after ourselves
.PHONY: clean
clean:
	rm -rf bin/

.PHONY: check check-gcc check-m2 check-hello check-base check-gc check-mescc
check-gcc:
	$(MAKE) -f simple.make check MES=bin/mes-gcc
check-m2:
	$(MAKE) -f simple.make check MES=bin/mes-m2

check: check-hello check-base check-gc check-mescc

check-hello: $(MES)
	echo '(display "hello\n")' | MES_BOOT=boot-01.scm $(MES)

check-base: $(MES)
	MES_DEBUG=4 MES_PREFIX=mes MES=$(MES) tests/base.test

check-gc: $(MES)
	MES_DEBUG=3 MES_ARENA=10000 MES_MAX_ARENA=10000 MES_BOOT=tests/gc.test $(MES)

check-mescc: $(MES)
	rm -f a.out
# this already needs succesful GC
#	LIBRARY_PATH=lib MES_DEBUG=1 MES_PREFIX=mes MES=$(MES) sh -x scripts/mescc -- -I include -nostdlib lib/mes/globals.c lib/string/strlen.c lib/mes/eputs.c scaffold/hello.c
	LIBRARY_PATH=lib MES_DEBUG=1 MES_PREFIX=mes MES=$(MES) sh -x scripts/mescc -- -m 32 -I include -nostdlib lib/mes/globals.c lib/linux/$(MESCC_CPU)-mes-mescc/crt1.c scaffold/main.c
	./a.out; r=$$?; if [ $$r != 42 ]; then exit 1; fi


# Directories
bin:
	mkdir -p $@

m2:
	mkdir -p $@

TAGS:
	etags $(shell find . -name '*.c' -o -name '*.h') --language=scheme $(shell find mes module -name '*.mes' -o -name '*.scm')