-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile.gcc6
256 lines (206 loc) · 7.79 KB
/
Makefile.gcc6
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
# simple libnix Makefile.gcc6 - for Bebbo's gcc-6
MAJOR=0
MINOR=1
PREFIX ?= /opt/amiga
CFLAGS ?= -Os -fomit-frame-pointer
uname := $(shell uname)
root ?= $(shell echo $$PWD)
export root
MAKEFILES=$(root)/Makefile.gcc6
# special path handling for msys2 started from Eclipse
ifneq (,$(findstring MSYS_NT,$(uname)))
ifneq (,$(findstring /cygdrive/,$(root)))
troot := $(root)
tdrive := $(word 2,$(subst /, ,$(troot)))
root = $(subst /cygdrive/$(tdrive)/,$(tdrive):/,$(troot))
endif
endif
ifneq (,$(lib))
ifeq (,$(libname))
libname=$(lib)
endif
-include $(root)/sources/$(lib)/steal.me
endif
# use nix13 or nix20
ifeq (,$(lc))
CC = m68k-amigaos-gcc
AR = m68k-amigaos-ar
AS = m68k-amigaos-as
VARIANTS_TO_BUILD = info lib libb libm020 libm020bb libm020bb32 libm881 libm020bb881 libm020bb32881
LIBS_TO_BUILD ?= libnix libnix13 libnix20 libnixmain libnix_main libm libsocket libstub
STARTUPS ?= lib/devinit.o lib/libinit.o lib/libinitb.o lib/libinitr.o lib/ncrt0.o lib/nbcrt0.o lib/nlbcrt0.o lib/nrcrt0.o lib/nlrcrt0.o lib/init_shared.o
ifneq (,$(lib))
crt = -mcrt=nix13
ifeq (nix20,$(lib))
crt = -noixemul
endif
ifeq (socket,$(lib))
crt = -noixemul
endif
CFLAGS += $(crt)
endif
else
CC = m68k-elf-gcc
AR = m68k-elf-ar
AS = m68k-elf-as
TGT = --defsym __elf__=1
VARIANTS_TO_BUILD ?= info libm020
LIBS_TO_BUILD = libc libm
STARTUPS ?= lib/ncrt0.o
endif
# extend CFLAGS on first invokation
ifeq (,$(kind))
CFLAGS += -I$(root)/sources/headers -fno-builtin -ffast-math -D__libnix__
ifneq (,$(lc))
CFLAGS += -D__libnix__
endif
endif
.PHONY: all one rest clean install install_one
.PHONY: lib libb libm020 libm020bb libm020bb32 libm881 libm020bb881 libm020bb32881 lc
all: $(VARIANTS_TO_BUILD)
# the desired kinds to be build
lib: $(STARTUPS)
@mkdir -p $@
$(MAKE) one kind=$@
if [ -e lib/libstubs.a ] && [ "$$($(AR) t lib/libstubs.a | grep __initlib)" != "" ]; then rm -f lib/libstubs.a; fi
libb:
@mkdir -p $@
$(MAKE) one kind=$@ flags="-fbaserel"
libm020:
@mkdir -p $@
$(MAKE) one kind=$@ flags="-m68020"
libm020bb:
@mkdir -p $@
$(MAKE) one kind=$@ flags="-fbaserel -m68020"
libm020bb32:
@mkdir -p $@
$(MAKE) one kind=$@ flags="-fbaserel32 -m68020"
libm881:
@mkdir -p $@
$(MAKE) one kind=$@ flags="-m68020 -m68881 -mhard-float" LIBS_TO_BUILD=libm
libm020bb881:
@mkdir -p $@
$(MAKE) one kind=$@ flags="-fbaserel -m68020 -m68881 -mhard-float" LIBS_TO_BUILD=libm
libm020bb32881:
@mkdir -p $@
$(MAKE) one kind=$@ flags="-fbaserel32 -m68020 -m68881 -mhard-float" LIBS_TO_BUILD=libm
# the libs to build for each kind
one: $(LIBS_TO_BUILD)
# install all kinds into the prefix
.PHONY: install_lib install_libb install_libm020 install_libm020bb install_libm020bb32 install_libm881 install_libm020bb881 install_libm020bb32881
install: install_lib install_libb install_libm020 install_libm020bb install_libm020bb32 install_libm881 install_libm020bb881 install_libm020bb32881
cp $(root)/mkstub $(PREFIX)/bin
install_lib:
$(MAKE) install_one kind=lib to=""
mv $(PREFIX)/m68k-amigaos/libnix/lib/libstubs.a $(PREFIX)/m68k-amigaos/lib/
install_libb:
$(MAKE) install_one kind=libb to="libb/"
install_libm020:
$(MAKE) install_one kind=libm020 to="libm020/"
install_libm020bb:
$(MAKE) install_one kind=libm020bb to="libb/libm020/"
install_libm020bb32:
$(MAKE) install_one kind=libm020bb32 to="libb32/libm020/"
install_libm881:
$(MAKE) install_one kind=libm881 to="libm020/libm881/"
install_libm020bb881:
$(MAKE) install_one kind=libm020bb881 to="libb/libm020/libm881/"
install_libm020bb32881:
$(MAKE) install_one kind=libm020bb32881 to="libb32/libm020/libm881/"
install_libm060:
$(MAKE) install_one kind=libm060 to="libm060/"
install_libm060bb:
$(MAKE) install_one kind=libm060bb to="libb/libm060/"
install_libm060bb32:
$(MAKE) install_one kind=libm060bb32 to="libb32/libm060/"
# install the files for the given $(kind) into $(to)
install_one:
mkdir -p $(PREFIX)/m68k-amigaos/libnix/lib/$(to)
rsync $(kind)/*.a $(PREFIX)/m68k-amigaos/libnix/lib/$(to) --exclude=$(kind)/libstubs.a
find $(kind) -maxdepth 1 -name "*.o" -exec cp {} $(PREFIX)/m68k-amigaos/libnix/lib/$(to) \;
# startup stuff
.PHONY: libdir
libdir:
@mkdir -p lib
lib/devinit.o: $(root)/sources/startup/devinit.c libdir
$(CC) -c $(CFLAGS) $(flags) $< -o $@
lib/libinit.o: $(root)/sources/startup/libinit.c libdir
$(CC) -c $(CFLAGS) $(flags) $< -o $@
lib/libinitb.o: $(root)/sources/startup/libinit.c libdir
$(CC) -c $(CFLAGS) $(flags) -D__BASEREL__ $< -o $@
lib/libinitr.o: $(root)/sources/startup/libinitr.c libdir
$(CC) -c $(CFLAGS) $(flags) $< -o $@
lib/ncrt0.o: $(root)/sources/startup/ncrt0.S libdir
$(AS) $(TGT) -m68000 $< -o $@
lib/xcrt0.o: $(root)/sources/startup/xcrt0.S libdir
$(AS) $(TGT) -m68000 $< -o $@
lib/nbcrt0.o: $(root)/sources/startup/nbcrt0.S libdir
$(AS) -m68000 $< -o $@
lib/nlbcrt0.o: $(root)/sources/startup/nlbcrt0.S libdir
$(AS) -m68020 $< -o $@
lib/nrcrt0.o: $(root)/sources/startup/nrcrt0.S libdir
$(AS) -m68000 $< -o $@
lib/nlrcrt0.o: $(root)/sources/startup/nlrcrt0.S libdir
$(AS) -m68020 $< -o $@
lib/init_shared.o: $(root)/sources/startup/init_shared.c libdir
$(CC) $(CFLAGS) -fbaserel -m68000 -Os -c $< -o $@
.PHONY: libnix libnix13 libnix20 libnixmain libnix_main libm libsocket
libnix:
$(MAKE) -C $(kind) rest libnix.a lib=nix
libnix13:
$(MAKE) -C $(kind) rest libnix13.a lib=nix13
libnix20:
$(MAKE) -C $(kind) rest libnix20.a lib=nix20
libnixmain:
$(MAKE) -C $(kind) libnixmain.a lib=nixmain
libm:
$(MAKE) -C $(kind) libm.a lib=math libname=m flags="$(flags) -DFULL_SPECIFIERS"
libsocket:
$(MAKE) -C $(kind) libsocket.a lib=socket
libstub:
$(MAKE) -C $(kind) libstubs.a lib=stubs
libc: $(STARTUPS)
$(MAKE) -C lib kind=lib libstubs.a lib=stubs
$(MAKE) -C $(lc) kind=$(lc) rest libnix.a lib=nix
$(MAKE) -C $(lc) kind=$(lc) rest libnix20.a lib=nix20
$(MAKE) -C $(lc) kind=$(lc) rest libnixmain.a lib=nixmain
-rm lib/stubs/*_list__.o
if [ ! -e $(lc)/libc.a ]; then $(AR) rcs $(lc)/libc.a; touch -t 0001010000 $(lc)/libc.a; fi
$(AR) rcs $(lc)/libc.a \
$$(find ./$(lc)/nix/* -name '*.o' -newer $(lc)/libc.a) \
$$(find ./lib/stubs/* -name '*.o' -newer $(lc)/libc.a) \
$$(find ./$(lc)/nixmain/* -name '*.o' -newer $(lc)/libc.a) \
$$(find ./$(lc)/nix20/* -name '*.o' -newer $(lc)/libc.a)
rest: detach.o
detach.o: $(root)/sources/misc/detach.c
$(CC) -c -Os -fomit-frame-pointer $(flags) $^ -o $@
# build the lib base on $(lib), $(kind) and $(flags)
lib$(libname).a: $(shell find $(root)/sources/$(lib)/* -name '*.c') $(stolen) $(shell find $(root)/sources/headers/* -name '*.h') $(root)/Makefile.gcc6
@mkdir -p $(lib)
@echo compiling for $(kind)/$@ using $(CC) -c $(CFLAGS) $(flags)
@touch -t 0001010000 $(lib)/stamp && if [ -e $@ ]; then touch -r $@ $(lib)/stamp; fi
@if [ "$$(find $(root)/sources/headers/* -newer $(lib)/stamp)" != "" ]; then rm -f $(lib)/*.o $@; touch -t 0001010000 $(lib)/stamp; fi
@if [ "$$(find $(root)/Makefile.gcc6 -newer $(lib)/stamp)" != "" ]; then rm -f $(lib)/*.o $@; touch -t 0001010000 $(lib)/stamp; fi
@cd $(lib) && files="$$(find $^ -name '*.c' -newer stamp)" && echo "$(CC) -c $(CFLAGS) $(flags) $$files" && \
$(CC) -c $(CFLAGS) $(flags) $$files
@#echo archive $(kind)/$@
@$(AR) rcs $@ $$(find ./$(lib)/* -name '*.o' -newer $(lib)/stamp)
libb/libnix4.library:
cd libb && $(root)/preplib
cd libb && $(root)/mkstub libnix4 libnix.def $$(cat ofiles.txt | xargs)
cd libb && $(CC) -shared -noixemul $$(cat ofiles.txt | xargs) \
libnix4-support/export*.o \
-o libnix4.library \
-Wl,-ulibVersionMajor=$(MAJOR),-ulibVersionMinor=$(MINOR),-ulibName=libnix4 \
$(STRIP)
$(AR) rcs libb/libnix4.a lib/nix/__initlibraries.o lib/nix/__initcpp.o lib/nix20/__nocommandline.o lib/nixmain/__stdiowin.o
rsync libb/libnix4.a $(PREFIX)/m68k-amigaos/libnix/lib/
rsync libb/libnix4.library $(PREFIX)/m68k-amigaos/libnix/
# cleanup
clean:
find * -name '*.o' -delete
find * -name '*.a' -delete
find * -name stamp -delete
info:
@echo "$(uname)"
@echo "root=$(root)"