-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgen_makefile.py
executable file
·711 lines (595 loc) · 21.1 KB
/
gen_makefile.py
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
#!/usr/bin/env python3
'''
Generate a top-level makefile that builds the Osmocom 2G + 3G network components.
./gen_makefile.py [configure.opts [more.opts]] [-o Makefile.output]
Configured by text files:
all.deps: whitespace-separated listing of
project_name depends_on_project_1 depends_on_project_2 ...
*.opts: whitespace-separated listing of
project_name --config-opt-1 --config-opt-2 ...
Thus it is possible to choose between e.g.
- building each of those with or without mgcp transcoding support by adding or
removing "transcoding.opts" from the command line
From the Makefile nature, the dependencies extend, no need to repeat common deps.
When this script is done, a Makefile has been generated that allows you to
build all projects at once by issuing 'make', but also to refresh only parts of
it when some bits in the middle have changed. The makefile keeps local progress
marker files like .make.libosmocore.configure; if such progress marker is
removed or becomes outdated, that step and all dependent ones are re-run.
This is helpful in daily hacking across several repositories.
Note that by default, this includes 'sudo ldconfig' calls following each
installation. You may want to permit your user to run 'sudo ldconfig' without
needing a password, e.g. by
sudo sh -c "echo '$USER ALL= NOPASSWD: /sbin/ldconfig' > /etc/sudoers.d/${USER}_ldconfig"
You can skip the 'sudo ldconfig' by issuing the --no-ldconfig option.
You can run 'ldconfig' without sudo by issuing the --ldconfig-without-sudo option.
By default, it is assumed that your user has write permission to /usr/local. If you
need sudo to install there, you may issue the --sudo-make-install option.
EXAMPLE:
./gen_makefile.py default.opts iu.opts -I -m build
cd build
make
'''
import sys
import os
import argparse
import multiprocessing
import shlex
topdir = os.path.dirname(os.path.realpath(__file__))
all_deps_file = os.path.join(topdir, "all.deps")
all_urls_file = os.path.join(topdir, "all.urls")
all_buildsystems_file = os.path.join(topdir, "all.buildsystems")
parser = argparse.ArgumentParser(epilog=__doc__, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('configure_opts_files',
help='''Config file containing project name and
./configure options''',
nargs='*')
parser.add_argument('-m', '--make-dir', dest='make_dir',
help='''Place Makefile in this dir (default: create
a new dir named after opts files).''')
parser.add_argument('-s', '--src-dir', dest='src_dir', default='./src',
help='Parent dir for all git clones.')
parser.add_argument('-b', '--build-dir', dest='build_dir',
help='''Parent dir for all build trees (default:
directly in the make-dir).''')
parser.add_argument('-u', '--url', dest='url', default='https://gerrit.osmocom.org',
help='''git clone base URL. Default is 'https://gerrit.osmocom.org'.
e.g. with a config like this in your ~/.ssh/config:
host go
hostname gerrit.osmocom.org
port 29418
you may pass '-u ssh://go' to be able to submit to gerrit.''')
parser.add_argument('-p', '--push-url', dest='push_url', default='',
help='''git push-URL. Default is to not configure a separate push-URL.''')
parser.add_argument('-o', '--output', dest='output', default='Makefile',
help='''Makefile filename (default: 'Makefile').''')
parser.add_argument('-j', '--jobs', dest='jobs', type=int,
default=multiprocessing.cpu_count(), nargs='?',
const=multiprocessing.cpu_count(),
help='''-j option to pass to 'make'.''')
parser.add_argument('-I', '--sudo-make-install', dest='sudo_make_install',
action='store_true',
help='''run 'make install' step with 'sudo'.''')
parser.add_argument('-L', '--no-ldconfig', dest='no_ldconfig',
action='store_true',
help='''omit the 'sudo ldconfig' step.''')
parser.add_argument('--ldconfig-without-sudo', dest='ldconfig_without_sudo',
action='store_true',
help='''call just 'ldconfig', without sudo, which implies
root privileges (not recommended)''')
parser.add_argument('-c', '--no-make-check', dest='make_check',
default=True, action='store_false',
help='''do not 'make check', just 'make' to build.''')
parser.add_argument('--docker-cmd',
help='''prefix configure/make/make install calls with this command (used by ttcn3.sh)''')
parser.add_argument('-g', '--build-debug', dest='build_debug', default=False, action='store_true',
help='''set 'CFLAGS=-g' when calling src/configure''')
parser.add_argument('-a', '--auto-distclean', action='store_true',
help='''run "make distclean" automatically if source directory already configured''')
parser.add_argument('-i', '--install-prefix', default='/usr/local',
help='''install there instead of /usr/local''')
parser.add_argument('-A', '--autoreconf-in-src-copy', action='store_true',
help="run autoreconf in a copy of the source dir, avoids 'run make distclean' errors")
args = parser.parse_args()
class listdict(dict):
'a dict of lists { "a": [1, 2, 3], "b": [1, 2] }'
def add(self, name, item):
l = self.get(name)
if not l:
l = []
self[name] = l
l.append(item)
def extend(self, name, l):
for v in l:
self.add(name, v)
def add_dict(self, d):
for k,v in d.items():
self.add(k, v)
def extend_dict(self, d):
for k,v in d.items():
self.extend(k, v)
def read_projects_deps(path):
'Read deps config and return tuples of (project_name, which-other-to-build-first).'
l = []
for line in open(path):
line = line.strip()
if not line or line.startswith('#'):
continue
tokens = line.split()
l.append((tokens[0], tokens[1:]))
return l
def read_projects_dict(path):
'Read urls/buildsystems config and return dict {project_name: url, …}.'
ret = {}
for line in open(path):
line = line.strip()
if not line or line.startswith('#'):
continue
project, url = line.split()
assert project not in ret, f"project '{project} found twice in {path}"
ret[project] = url
return ret
def read_configure_opts(path):
'Read config opts file and return tuples of (project_name, config-opts).'
if not path:
return {}
return dict(read_projects_deps(path))
def gen_makefile_clone(proj, src, src_proj, url, push_url, update_src_copy_cmd):
if proj == "osmocom-bb_layer23":
return f'''
.make.{proj}.clone: .make.osmocom-bb.clone
@echo "\\n\\n\\n===== $@\\n"
test -L {src_proj} || ln -s osmocom-bb/src/host/layer23 {src_proj}
{update_src_copy_cmd}
touch $@
'''
if proj == "osmocom-bb_virtphy":
return f'''
.make.{proj}.clone: .make.osmocom-bb.clone
@echo "\\n\\n\\n===== $@\\n"
test -L {src_proj} || ln -s osmocom-bb/src/host/virt_phy {src_proj}
{update_src_copy_cmd}
touch $@
'''
if proj == "osmocom-bb_trxcon":
return f'''
.make.{proj}.clone: .make.osmocom-bb.clone
@echo "\\n\\n\\n===== $@\\n"
test -L {src_proj} || ln -s osmocom-bb/src/host/trxcon {src_proj}
{update_src_copy_cmd}
touch $@
'''
if proj == "simtrace2_host":
return f'''
.make.{proj}.clone: .make.simtrace2.clone
@echo "\\n\\n\\n===== $@\\n"
test -L {src_proj} || ln -s simtrace2/host {src_proj}
{update_src_copy_cmd}
touch $@
'''
if proj in projects_urls:
url = projects_urls[proj]
cmd_set_push_url = "true"
else:
url = f"{url}/{proj}"
push_url = f"{push_url}/{proj}"
cmd_set_push_url = f'git -C "{src}/{proj}" remote set-url --push origin "{push_url}"'
cmd_clone = f'git -C {src} clone --recurse-submodules "{url}" "{proj}"'
return f'''
.make.{proj}.clone:
@echo "\\n\\n\\n===== $@\\n"
@if ! [ -e {src}/ ]; then \\
if [ -L {src} ]; then \\
echo "ERROR: broken symlink: {src}"; \\
exit 1; \\
fi; \\
set -x; \\
mkdir -p {src}; \\
fi
@if ! [ -e {src_proj}/ ]; then \\
if [ -L {src_proj} ]; then \\
echo "ERROR: broken symlink: {src_proj}"; \\
exit 1; \\
fi; \\
set -x; \\
( {cmd_clone} && {cmd_set_push_url} ); \\
fi
{update_src_copy_cmd}
sync
touch $@
'''
def gen_makefile_autoconf(proj, src_proj, src_proj_copy, distclean_cond, update_src_copy_cmd):
buildsystem = projects_buildsystems.get(proj, "autotools")
if buildsystem == "autotools":
return f'''
.make.{proj}.autoconf: .make.{proj}.clone {src_proj}/configure.ac
if {distclean_cond}; then $(MAKE) {proj}-distclean; fi
@echo "\\n\\n\\n===== $@\\n"
{update_src_copy_cmd}
-rm -f {src_proj_copy}/.version
cd {src_proj_copy}; autoreconf -fi
sync
touch $@
'''
elif buildsystem in ["meson", "erlang"]:
return ""
else:
assert False, f"unknown buildsystem: {buildsystem}"
def gen_makefile_configure(proj, deps_installed, distclean_cond, build_proj,
cflags, docker_cmd, build_to_src, configure_opts,
update_src_copy_cmd):
buildsystem = projects_buildsystems.get(proj, "autotools")
if buildsystem == "autotools":
return f'''
.make.{proj}.configure: .make.{proj}.autoconf {deps_installed} $({proj}_configure_files)
if {distclean_cond}; then $(MAKE) {proj}-distclean .make.{proj}.autoconf; fi
@echo "\\n\\n\\n===== $@\\n"
{update_src_copy_cmd}
-chmod -R ug+w {build_proj}
-rm -rf {build_proj}
mkdir -p {build_proj}
cd {build_proj}; {cflags}{docker_cmd}{build_to_src}/configure \\
--prefix {shlex.quote(args.install_prefix)} \\
{configure_opts}
sync
touch $@
'''
elif buildsystem == "meson":
return f'''
.make.{proj}.configure: .make.{proj}.clone {deps_installed} $({proj}_configure_files)
@echo "\\n\\n\\n===== $@\\n"
-chmod -R ug+w {build_proj}
-rm -rf {build_proj}
mkdir -p {build_proj}
cd {build_proj}; {cflags}{docker_cmd}meson setup {build_to_src} . \\
--prefix {shlex.quote(args.install_prefix)}
sync
touch $@
'''
elif buildsystem == "erlang":
return ""
else:
assert False, f"unknown buildsystem: {buildsystem}"
def gen_makefile_build(proj, distclean_cond, build_proj, docker_cmd, jobs,
check, src_proj, update_src_copy_cmd):
buildsystem = projects_buildsystems.get(proj, "autotools")
if buildsystem == "autotools":
return f'''
.make.{proj}.build: .make.{proj}.configure $({proj}_files)
if {distclean_cond}; then $(MAKE) {proj}-distclean .make.{proj}.configure; fi
@echo "\\n\\n\\n===== $@\\n"
{update_src_copy_cmd}
{docker_cmd}$(MAKE) -C {build_proj} -j {jobs} {check}
sync
touch $@
'''
elif buildsystem == "meson":
test_line = ""
# TODO: currently tests don't pass in this env
# if check:
# test_line = f"{docker_cmd}meson test -C {build_proj} -v"
return f'''
.make.{proj}.build: .make.{proj}.configure $({proj}_files)
@echo "\\n\\n\\n===== $@\\n"
{docker_cmd}meson compile -C {build_proj} -j {jobs}
{test_line}
sync
touch $@
'''
elif buildsystem == "erlang":
return f'''
.make.{proj}.build: $({proj}_files)
@echo "\\n\\n\\n===== $@\\n"
set -x && \\
export REBAR_BASE_DIR="$$PWD/{build_proj}" && \\
mkdir -p "$$REBAR_BASE_DIR" && \\
$(MAKE) -C {src_proj} build {check}
sync
touch $@
'''
else:
assert False, f"unknown buildsystem: {buildsystem}"
def gen_makefile_install(proj, docker_cmd, sudo_make_install, build_proj,
no_ldconfig, sudo_ldconfig):
buildsystem = projects_buildsystems.get(proj, "autotools")
if buildsystem == "autotools":
return f'''
.make.{proj}.install: .make.{proj}.build
@echo "\\n\\n\\n===== $@\\n"
{docker_cmd}{sudo_make_install}$(MAKE) -C {build_proj} install
{no_ldconfig}{sudo_ldconfig}ldconfig
sync
touch $@
'''
elif buildsystem == "meson":
return f'''
.make.{proj}.install: .make.{proj}.build
@echo "\\n\\n\\n===== $@\\n"
{docker_cmd}{sudo_make_install}ninja -C {build_proj} install
{no_ldconfig}{sudo_ldconfig}ldconfig
sync
touch $@
'''
elif buildsystem == "erlang":
return f'''
.make.{proj}.install: .make.{proj}.build
@echo "\\n\\n\\n===== $@\\n"
for i in {build_proj}/default/bin/*; do \\
install -v -Dm755 "$$i" -t {shlex.quote(args.install_prefix)}/bin/; \\
done
sync
touch $@
'''
else:
assert False, f"unknown buildsystem: {buildsystem}"
def gen_makefile_reinstall(proj, deps_reinstall, sudo_make_install,
build_proj):
return f'''
.PHONY: {proj}-reinstall
{proj}-reinstall: {deps_reinstall}
{sudo_make_install}$(MAKE) -C {build_proj} install
'''
def gen_makefile_clean(proj, build_proj):
return f'''
.PHONY: {proj}-clean
{proj}-clean:
@echo "\\n\\n\\n===== $@\\n"
-chmod -R ug+w {build_proj}
-rm -rf {build_proj}
-rm -rf .make.{proj}.*
'''
def gen_makefile_distclean(proj, src_proj):
return f'''
.PHONY: {proj}-distclean
{proj}-distclean: {proj}-clean
@echo "\\n\\n\\n===== $@\\n"
$(MAKE) -C {src_proj} distclean
'''
def is_src_copy_needed(proj):
if not args.autoreconf_in_src_copy:
return False
# The rsync workaround to not write to the source dir during "autoreconf -fi"
# is only needed for autotools based projects
buildsystem = projects_buildsystems.get(proj, "autotools")
if buildsystem != "autotools":
return False
return True
def gen_update_src_copy_cmd(proj, src_dir, make_dir):
if not is_src_copy_needed(proj):
return ""
src_dir_script = os.path.join(topdir, "src")
src_dir_script = os.path.relpath(src_dir_script, make_dir)
ret = "@sh -e "
ret += os.path.join(src_dir_script, "_update_src_copy.sh")
ret += f" {shlex.quote(src_dir)}"
ret += f" {shlex.quote(proj)}"
ret += " $(TIME_START)"
return ret
def gen_src_proj_copy(src_proj, make_dir, proj):
if not is_src_copy_needed(proj):
return src_proj
return os.path.join(make_dir, "src_copy", proj)
def gen_make(proj, deps, configure_opts, jobs, make_dir, src_dir, build_dir, url, push_url, sudo_make_install, no_ldconfig, ldconfig_without_sudo, make_check):
src_proj = os.path.join(src_dir, proj)
if proj == 'openbsc':
src_proj = os.path.join(src_proj, 'openbsc')
src = os.path.relpath(src_dir, make_dir)
src_proj = os.path.relpath(src_proj, make_dir)
src_proj_copy = gen_src_proj_copy(src_proj, make_dir, proj)
build_proj = os.path.join(build_dir, proj)
build_to_src = os.path.relpath(src_proj_copy, build_proj)
build_proj = os.path.relpath(build_proj, make_dir)
push_url = push_url or url
if configure_opts:
configure_opts_str = ' '.join(configure_opts)
else:
configure_opts_str = ''
distclean_cond = f'[ -e {src_proj}/config.status ]' if args.auto_distclean else 'false'
deps_installed = ' '.join(['.make.%s.install' % d for d in deps])
deps_reinstall = ' '.join(['%s-reinstall' %d for d in deps])
cflags = 'CFLAGS=-g ' if args.build_debug else ''
docker_cmd = f'OSMODEV_PROJECT={proj} {args.docker_cmd} ' if args.docker_cmd else ''
check = 'check' if make_check else ''
no_ldconfig = '#' if no_ldconfig else ''
sudo_ldconfig = '' if ldconfig_without_sudo else 'sudo '
sudo_make_install = 'sudo ' if sudo_make_install else ''
update_src_copy_cmd = gen_update_src_copy_cmd(proj, src_dir, make_dir)
return f'''
### {proj} ###
{proj}_configure_files := $(shell find -L {src_proj} \\
-name "Makefile.am" \\
-or -name "*.in" \\
-and -not -name "Makefile.in" \\
-and -not -name "config.h.in" 2>/dev/null)
{proj}_files := $(shell find -L {src_proj} \\
\\( \\
-name "*.[hc]" \\
-or -name "*.py" \\
-or -name "*.cpp" \\
-or -name "*.tpl" \\
-or -name "*.map" \\
-or -name "*.erl" \\
\\) \\
-and -not -name "config.h" 2>/dev/null)
{gen_makefile_clone(proj,
src,
src_proj,
url,
push_url,
update_src_copy_cmd)}
{gen_makefile_autoconf(proj,
src_proj,
src_proj_copy,
distclean_cond,
update_src_copy_cmd)}
{gen_makefile_configure(proj,
deps_installed,
distclean_cond,
build_proj,
cflags,
docker_cmd,
build_to_src,
configure_opts_str,
update_src_copy_cmd)}
{gen_makefile_build(proj,
distclean_cond,
build_proj,
docker_cmd,
jobs,
check,
src_proj_copy,
update_src_copy_cmd)}
{gen_makefile_install(proj,
docker_cmd,
sudo_make_install,
build_proj,
no_ldconfig,
sudo_ldconfig)}
{gen_makefile_reinstall(proj,
deps_reinstall,
sudo_make_install,
build_proj)}
{gen_makefile_clean(proj, build_proj)}
{gen_makefile_distclean(proj, src_proj)}
.PHONY: {proj}
{proj}: .make.{proj}.install
'''
projects_deps = read_projects_deps(all_deps_file)
projects_urls = read_projects_dict(all_urls_file)
projects_buildsystems = read_projects_dict(all_buildsystems_file)
configure_opts = listdict()
configure_opts_files = sorted(args.configure_opts_files or [])
for configure_opts_file in configure_opts_files:
if configure_opts_file.endswith(".deps"):
print(f"WARNING: using {all_deps_file} instead of {configure_opts_file}")
continue
r = read_configure_opts(configure_opts_file)
configure_opts.extend_dict(read_configure_opts(configure_opts_file))
make_dir = args.make_dir
if not make_dir:
opts_names = '+'.join([f.replace('.opts', '') for f in configure_opts_files])
make_dir = 'make-%s' % opts_names
if not os.path.isdir(make_dir):
os.makedirs(make_dir)
build_dir = args.build_dir
if not build_dir:
build_dir = make_dir
content = '# This Makefile was generated by %s\n' % os.path.basename(sys.argv[0])
configure_opts_args = ""
for f in configure_opts_files:
if not f.endswith(".deps"):
configure_opts_args += f' \\\n\t\t{os.path.relpath(f, make_dir)}'
# convenience: add a regen target that updates the generated makefile itself
content += f'''
default: usrp
#
# Convenience targets for whole networks
#
.PHONY: cn
cn: \\
osmo-ggsn \\
osmo-hlr \\
osmo-iuh \\
osmo-mgw \\
osmo-msc \\
osmo-sgsn \\
osmo-sip-connector \\
osmo-smlc \\
$(NULL)
.PHONY: cn-bsc
cn-bsc: \\
cn \\
osmo-bsc \\
$(NULL)
.PHONY: cn-bsc-nat
cn-bsc-nat: \\
cn \\
mobile \\
osmo-bsc \\
osmo-bsc-nat \\
osmo-bts \\
virtphy \\
$(NULL)
.PHONY: usrp
usrp: \\
cn-bsc \\
osmo-bts \\
osmo-trx \\
$(NULL)
#
# Convenience targets for components in subdirs of repositories
#
.PHONY: mobile
mobile: osmocom-bb_layer23
.PHONY: virtphy
virtphy: osmocom-bb_virtphy
.PHONY: trxcon
trxcon: osmocom-bb_trxcon
#
# Other convenience targets
#
.PHONY: all_debug
all_debug:
$(MAKE) --dry-run -d all | grep "is newer than target"
$(MAKE) all
# regenerate this Makefile, in case the deps or opts changed
.PHONY: regen
regen:
{os.path.relpath(sys.argv[0], make_dir)} \\
{configure_opts_args} \\
--output {args.output} \\
--src-dir {os.path.relpath(args.src_dir, make_dir)} \\
--make-dir . \\
--build-dir {os.path.relpath(build_dir, make_dir)} \\
--jobs {args.jobs} \\
--url "{args.url}" \\
'''
if args.push_url:
content += f" --push-url {shlex.quote(args.push_url)} \\\n"
if args.sudo_make_install:
content += " --sudo-make-install \\\n"
if args.no_ldconfig:
content += " --no-ldconfig \\\n"
if args.ldconfig_without_sudo:
content += " --ldconfig-without-sudo \\\n"
if not args.make_check:
content += " --no-make-check \\\n"
if args.docker_cmd:
content += f" --push-url {shlex.quote(args.docker_cmd)} \\\n"
if args.build_debug:
content += " --build-debug \\\n"
if args.auto_distclean:
content += " --auto-distclean \\\n"
if args.autoreconf_in_src_copy:
content += " --autoreconf-in-src-copy \\\n"
content += " $(NULL)\n"
if args.autoreconf_in_src_copy:
content += """
# --autoreconf-in-src-copy: get current time to avoid running rsync more than
# once within this Makefile per project
TIME_START := $(shell date +%s%N)
"""
# convenience target: clone all repositories first
content += 'clone: \\\n\t' + ' \\\n\t'.join([ '.make.%s.clone' % p for p, d in projects_deps ]) + '\n\n'
# convenience target: clean all
content += 'clean: \\\n\t' + ' \\\n\t'.join([ '%s-clean' % p for p, d in projects_deps ]) + '\n\n'
# now the actual useful build rules
content += 'all: clone all-install\n\n'
content += 'all-install: \\\n\t' + ' \\\n\t'.join([ '.make.%s.install' % p for p, d in projects_deps ]) + '\n\n'
for proj, deps in projects_deps:
all_config_opts = []
all_config_opts.extend(configure_opts.get('ALL') or [])
all_config_opts.extend(configure_opts.get(proj) or [])
content += gen_make(proj, deps, all_config_opts, args.jobs,
make_dir, args.src_dir, build_dir, args.url, args.push_url,
args.sudo_make_install, args.no_ldconfig,
args.ldconfig_without_sudo, args.make_check)
# Replace spaces with tabs to avoid the common pitfall of inserting spaces
# instead of tabs by accident into the Makefile (as the python code is indented
# with spaces), which results in a broken Makefile.
content = content.replace(" ", " ")
output = os.path.join(make_dir, args.output)
print('Writing to %r' % output)
with open(output, 'w') as out:
out.write(content)
# vim: expandtab tabstop=2 shiftwidth=2