4
4
{
5
5
local _lib = lib ;
6
6
local _bin = bin ;
7
+ local _sbin = sbin ;
7
8
local _inc = include ;
8
9
9
10
# SYSTEM_ROOT is set by the build-system
18
19
# . is set by the build system
19
20
LIBDIR ?= $(_lib:P=$(PERSONAL_ROOT:E=$(.:P))) ;
20
21
BINDIR ?= $(_bin:P=$(PERSONAL_ROOT:E=$(.:P))) ;
22
+ SBINDIR ?= $(_sbin:P=$(PERSONAL_ROOT:E=$(.:P))) ;
21
23
HDRS ?= $(SYSTEM_INCDIR) ;
22
24
}
23
25
@@ -53,6 +55,7 @@ STRIP ?= strip ;
53
55
CCFLAGS += -fPIC ;
54
56
55
57
LINK ?= $(CC) ;
58
+ UNIFYLINK ?= $(CC) -Bstatic ;
56
59
LINKFLAGS ?= $(CCFLAGS) ;
57
60
58
61
#
@@ -122,26 +125,30 @@ rule DylanLibrary image : version {
122
125
# Link a Dylan library as a shared library or executable image.
123
126
124
127
local _dll = [ FDLLName $(image) ] ;
125
- local _lib = [ FLIBName $(image) ] ;
128
+ local _ulib = [ FULIBName $(image) ] ;
129
+ local _lflag = [ FLIBFlag $(image) ] ;
126
130
local _exe = [ FEXEName $(image) ] ;
131
+ local _uexe = $(_exe:G=unify) ;
127
132
128
133
# Here we save the name and search directory of the DLL for this library.
129
134
130
135
_dll_$(image[1]:L) = $(_dll) ;
131
- _lib_$(image[1]:L) = $(_lib) ;
136
+ _ulib_$(image[1]:L) = $(_ulib) ;
137
+ _lflag_$(image[1]:L) = $(_lflag) ;
132
138
if ! $(SYSTEM) && ! $(PERSONAL_ROOT) {
133
139
_dir_$(image[1]:L) = $(LIBDIR) ;
134
140
}
135
141
136
142
# Shared libraries and executable images
137
143
138
- MakeLocate $(_dll) : $(LIBDIR) ;
144
+ MakeLocate $(_dll) $(_ulib) : $(LIBDIR) ;
139
145
MakeLocate $(_exe) : $(BINDIR) ;
146
+ MakeLocate $(_uexe) : $(SBINDIR) ;
140
147
141
148
# Initial library search path
142
149
143
150
LIBPATH on $(_dll) = $(PERSONAL_LIBDIR) ;
144
- LIBPATH on $(_exe) = $(PERSONAL_LIBDIR:E=$(LIBDIR)) ;
151
+ LIBPATH on $(_exe) $(_uexe) = $(PERSONAL_LIBDIR:E=$(LIBDIR)) ;
145
152
146
153
# Install needed runtime libraries locally
147
154
if $(image[1]:L) = dylan {
@@ -182,10 +189,16 @@ rule DylanLibrary image : version {
182
189
SEARCH on $(_obj) $(_asm) = $(SEARCH_SOURCE) ;
183
190
184
191
Depends $(_exe) : $(_dll) ;
185
- LINKLIBS on $(_exe) += $(_lib ) ;
186
- LINKFLAGS on $(_exe) = $(LINKFLAGS) $(LINKFLAGSEXE) ;
192
+ LINKLIBS on $(_exe) += $(_lflag ) ;
193
+ LINKFLAGS on $(_exe) $(_uexe) = $(LINKFLAGS) $(LINKFLAGSEXE) ;
187
194
LinkEXE $(_exe) : $(_obj) ;
188
195
196
+ # Dylan glue must appear first in the statically-linked executable
197
+ # so that the system initializations are performed in the right
198
+ # order
199
+ local _glue = _glue$(SUFOUT) ;
200
+ UnifyEXE $(_uexe) : $(_glue:G=dylan) $(_obj) $(_ulib) ;
201
+
189
202
if $(COMPILER_BACK_END) = c {
190
203
LINKFLAGS on $(_exe) += [ on $(_exe) FIncludes $(HDRS) ] ;
191
204
}
@@ -196,10 +209,11 @@ rule DylanLibrary image : version {
196
209
if ! $(PARENT) {
197
210
Depends dll : $(_dll) ;
198
211
Depends exe : $(_exe) ;
212
+ Depends unify-exe : $(_uexe) ;
199
213
200
- Clean clean : $(_dll) $(_exe) $(_mkf) $(_obj) $(_asm) ;
214
+ Clean clean : $(_dll) $(_exe) $(_uexe) $( _mkf) $(_obj) $(_asm) ;
201
215
}
202
- Clean clean-all : $(_dll) $(_exe) $(_mkf) $(_obj) $(_asm) ;
216
+ Clean clean-all : $(_dll) $(_exe) $(_uexe) $( _mkf) $(_obj) $(_asm) ;
203
217
204
218
# Mark the library version
205
219
@@ -214,6 +228,7 @@ rule DylanLibraryFiles image : files {
214
228
# Link Dylan-derived object files into the resulting shared library.
215
229
if ! $(SYSTEM) {
216
230
local _dll = [ FDLLName $(image) ] ;
231
+ local _ulib = [ FULIBName $(image) ] ;
217
232
218
233
local _out = [ FGristFiles _glue$(SUFOUT) $(files:S=$(SUFOUT)) ] ;
219
234
local _asm = [ FGristFiles _glue$(SUFASM) $(files:S=$(SUFASM)) ] ;
@@ -234,6 +249,7 @@ rule DylanLibraryFiles image : files {
234
249
Cc $(_mobj) : $(_i) ;
235
250
}
236
251
LinkDLL $(_dll) : $(_mobj) ;
252
+ UnifyArchive $(_ulib) : $(_mobj) ;
237
253
}
238
254
} else {
239
255
LinkDLL $(_dll) : $(_out) ;
@@ -254,9 +270,10 @@ rule DylanLibraryLinkerOptions image : options {
254
270
255
271
local _dll = [ FDLLName $(image) ] ;
256
272
local _exe = [ FEXEName $(image) ] ;
273
+ local _uexe = $(_exe:G=unify) ;
257
274
258
- LINKLIBS on $(_dll) += $(options) ;
259
- LINKLIBS on $(_exe ) += $(options) ;
275
+ LINKLIBS on $(_dll) $(_exe) $(_uexe) += $(options) ;
276
+ _uopt_$(image[1]:L ) += $(options) ;
260
277
}
261
278
262
279
rule DylanLibraryBaseAddress image : address {
@@ -305,8 +322,10 @@ rule DylanLibraryCObjects image : objects {
305
322
# Link C (or other externally-derived) object files into the shared library.
306
323
if ! $(SYSTEM) {
307
324
local _dll = [ FDLLName $(image) ] ;
325
+ local _ulib = [ FULIBName $(image) ] ;
308
326
SEARCH on $(objects) = $(SEARCH_SOURCE) ;
309
327
LinkDLL $(_dll) : $(objects) ;
328
+ UnifyArchive $(_ulib) : $(objects) ;
310
329
}
311
330
}
312
331
@@ -317,6 +336,7 @@ rule DylanLibraryCSources image : sources {
317
336
# Link C source files into the shared library.
318
337
if ! $(SYSTEM) {
319
338
local _dll = [ FDLLName $(image) ] ;
339
+ local _ulib = [ FULIBName $(image) ] ;
320
340
local _exe = [ FEXEName $(image) ] ;
321
341
322
342
local _i ;
@@ -328,6 +348,7 @@ rule DylanLibraryCSources image : sources {
328
348
Cc $(_obj) : $(_i) ;
329
349
330
350
LinkDLL $(_dll) : $(_obj) ;
351
+ UnifyArchive $(_ulib) : $(_obj) ;
331
352
}
332
353
}
333
354
}
@@ -426,18 +447,28 @@ rule DylanLibraryUses image : library : dir {
426
447
}
427
448
428
449
DylanLibraryClosure $(image) : $(library:L) ;
450
+
451
+ local _exe = [ FEXEName $(image) ] ;
452
+ local _uexe = $(_exe:G=unify) ;
453
+ for _i in $(_use_$(image[1]:L)) {
454
+ Depends $(_uexe) : $(_ulib_$(_i)) ;
455
+ NEEDLIBS on $(_uexe) += $(_ulib_$(_i)) ;
456
+ LINKLIBS on $(_uexe) += $(_clib_$(_i)) $(_uopt_$(_i)) ;
457
+ }
429
458
}
430
459
431
460
rule DylanLibraryClosure image : libraries {
461
+ #Echo DylanLibraryClosure $(image) ":" $(libraries) ;
432
462
local _dll = [ FDLLName $(image) ] ;
433
463
local _exe = [ FEXEName $(image) ] ;
434
464
435
465
local _i ;
436
466
for _i in $(libraries) {
437
467
if ! $(_i) in $(_use_$(image[1]:L)) {
438
468
_use_$(image[1]:L) += $(_i) ;
469
+
439
470
Depends $(_dll) $(_exe) : $(_dll_$(_i)) ;
440
- LINKLIBS on $(_dll) $(_exe) += $(_lib_ $(_i)) $(_clib_$(_i)) ;
471
+ LINKLIBS on $(_dll) $(_exe) += $(_lflag_ $(_i)) $(_clib_$(_i)) ;
441
472
LIBPATH on $(_dll) $(_exe) += $(_dir_$(_i)) ;
442
473
443
474
DylanLibraryClosure $(image) : $(_use_$(_i)) ;
@@ -460,6 +491,15 @@ actions together LinkDLL bind NEEDLIBS {
460
491
$(STRIP) -s $(<:Q)
461
492
}
462
493
494
+ rule UnifyArchive {
495
+ #Echo UnifyArchive $(<) ":" $(>) ;
496
+ Depends $(<) : $(>) ;
497
+ }
498
+
499
+ actions together UnifyArchive {
500
+ $(AR) $(<:Q) $(>:Q)
501
+ }
502
+
463
503
rule LinkEXE {
464
504
#Echo LinkEXE $(<) ":" $(>) ;
465
505
Depends $(<) : $(>) ;
@@ -472,6 +512,18 @@ actions LinkEXE bind NEEDLIBS {
472
512
$(STRIP) -s $(<:Q)
473
513
}
474
514
515
+ rule UnifyEXE {
516
+ #Echo UnifyEXE $(<) ":" $(>) ;
517
+ Depends $(<) : $(>) ;
518
+ }
519
+
520
+ actions UnifyEXE bind NEEDLIBS {
521
+ $(UNIFYLINK) -o $(<:Q) $(LINKFLAGS) $(>:Q) -L"$(LIBPATH)" -Wl,--start-group $(NEEDLIBS:Q) $(LINKLIBS) -Wl,--end-group
522
+ $(OBJCOPY) $(<:Q) $(<:Q).dbg
523
+ $(OBJCOPY) --add-gnu-debuglink=$(<:Q).dbg $(<:Q)
524
+ $(STRIP) -s $(<:Q)
525
+ }
526
+
475
527
#
476
528
# Utility rules
477
529
#
@@ -485,6 +537,18 @@ rule FDLLName {
485
537
}
486
538
487
539
rule FLIBName {
540
+ if $(<[2]) {
541
+ return lib$(<[2]:LS=$(SUFLIB)) ;
542
+ } else {
543
+ return lib$(<[1]:LS=$(SUFLIB)) ;
544
+ }
545
+ }
546
+
547
+ rule FULIBName {
548
+ return [ FLIBName $(<),unify ] ;
549
+ }
550
+
551
+ rule FLIBFlag {
488
552
if $(<[2]) {
489
553
return -l$(<[2]:L) ;
490
554
} else {
0 commit comments