blob: 0e0df1003efddbaa4dfc586c76f07a112b680201 [file] [log] [blame]
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +02001#!/usr/bin/env python3
2'''
3Generate a top-level makefile that builds the Osmocom 2G + 3G network components.
4
Oliver Smith0a4d8ea2021-07-29 14:32:29 +02005 ./gen_makefile.py [configure.opts [more.opts]] [-o Makefile.output]
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +02006
7Configured by text files:
8
Oliver Smith0a4d8ea2021-07-29 14:32:29 +02009 all.deps: whitespace-separated listing of
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +020010 project_name depends_on_project_1 depends_on_project_2 ...
11
12 *.opts: whitespace-separated listing of
13 project_name --config-opt-1 --config-opt-2 ...
14
15Thus it is possible to choose between e.g.
Oliver Smith0a4d8ea2021-07-29 14:32:29 +020016- building each of those with or without mgcp transcoding support by adding or
17 removing "transcoding.opts" from the command line
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +020018
19From the Makefile nature, the dependencies extend, no need to repeat common deps.
20
21When this script is done, a Makefile has been generated that allows you to
22build all projects at once by issuing 'make', but also to refresh only parts of
23it when some bits in the middle have changed. The makefile keeps local progress
24marker files like .make.libosmocore.configure; if such progress marker is
25removed or becomes outdated, that step and all dependent ones are re-run.
26This is helpful in daily hacking across several repositories.
Neels Hofmeyr461c3bd2017-12-06 00:32:15 +010027
28Note that by default, this includes 'sudo ldconfig' calls following each
29installation. You may want to permit your user to run 'sudo ldconfig' without
30needing a password, e.g. by
31
32 sudo sh -c "echo '$USER ALL= NOPASSWD: /sbin/ldconfig' > /etc/sudoers.d/${USER}_ldconfig"
33
34You can skip the 'sudo ldconfig' by issuing the --no-ldconfig option.
35
36You can run 'ldconfig' without sudo by issuing the --ldconfig-without-sudo option.
37
38By default, it is assumed that your user has write permission to /usr/local. If you
39need sudo to install there, you may issue the --sudo-make-install option.
Neels Hofmeyr2535a262018-01-16 16:34:32 +010040
41EXAMPLE:
42
Oliver Smith0a4d8ea2021-07-29 14:32:29 +020043 ./gen_makefile.py default.opts iu.opts -I -m build
Neels Hofmeyr2535a262018-01-16 16:34:32 +010044 cd build
45 make
46
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +020047'''
48
49import sys
50import os
51import argparse
52
Oliver Smith0a4d8ea2021-07-29 14:32:29 +020053topdir = os.path.dirname(os.path.realpath(__file__))
54all_deps_file = os.path.join(topdir, "all.deps")
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +020055parser = argparse.ArgumentParser(epilog=__doc__, formatter_class=argparse.RawTextHelpFormatter)
56
Neels Hofmeyr450dac72017-08-22 19:27:08 +020057parser.add_argument('configure_opts_files',
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +020058 help='''Config file containing project name and
59./configure options''',
Neels Hofmeyr450dac72017-08-22 19:27:08 +020060 nargs='*')
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +020061
62parser.add_argument('-m', '--make-dir', dest='make_dir',
63 help='''Place Makefile in this dir (default: create
Oliver Smith0a4d8ea2021-07-29 14:32:29 +020064a new dir named after opts files).''')
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +020065
66parser.add_argument('-s', '--src-dir', dest='src_dir', default='./src',
67 help='Parent dir for all git clones.')
68
69parser.add_argument('-b', '--build-dir', dest='build_dir',
70 help='''Parent dir for all build trees (default:
71directly in the make-dir).''')
72
Neels Hofmeyrbffdc302017-12-06 00:31:49 +010073parser.add_argument('-u', '--url', dest='url', default='git://git.osmocom.org',
74 help='''git clone base URL. Default is 'git://git.osmocom.org'.
75e.g. with a config like this in your ~/.ssh/config:
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +020076 host go
77 hostname gerrit.osmocom.org
78 port 29418
Neels Hofmeyrbffdc302017-12-06 00:31:49 +010079you may pass '-u ssh://go' to be able to submit to gerrit.''')
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +020080
Neels Hofmeyr972c2942018-03-16 03:49:58 +010081parser.add_argument('-p', '--push-url', dest='push_url', default='',
Neels Hofmeyr28d4be52018-03-16 03:44:07 +010082 help='''git push-URL. Default is to not configure a separate push-URL.''')
83
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +020084parser.add_argument('-o', '--output', dest='output', default='Makefile',
85 help='''Makefile filename (default: 'Makefile').''')
86
Vadim Yanitskiy722ca6d2022-04-19 20:34:53 +030087parser.add_argument('-j', '--jobs', dest='jobs', default='$(nproc)',
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +020088 help='''-j option to pass to 'make'.''')
89
Neels Hofmeyr461c3bd2017-12-06 00:32:15 +010090parser.add_argument('-I', '--sudo-make-install', dest='sudo_make_install',
91 action='store_true',
92 help='''run 'make install' step with 'sudo'.''')
93
94parser.add_argument('-L', '--no-ldconfig', dest='no_ldconfig',
95 action='store_true',
96 help='''omit the 'sudo ldconfig' step.''')
97
98parser.add_argument('--ldconfig-without-sudo', dest='ldconfig_without_sudo',
99 action='store_true',
100 help='''call just 'ldconfig', without sudo, which implies
101root privileges (not recommended)''')
102
Neels Hofmeyrf6078c42018-09-04 14:34:33 +0200103parser.add_argument('-c', '--no-make-check', dest='make_check',
104 default=True, action='store_false',
105 help='''do not 'make check', just 'make' to build.''')
106
Oliver Smithc47eafb2021-08-12 12:45:36 +0200107parser.add_argument('--docker-cmd',
108 help='''prefix configure/make/make install calls with this command (used by ttcn3.sh)''')
109
Neels Hofmeyr2325e2e2021-10-23 20:42:44 +0200110parser.add_argument('-g', '--build-debug', dest='build_debug', default=False, action='store_true',
111 help='''set 'CFLAGS=-g' when calling src/configure''')
112
Oliver Smithadfa0c02021-10-04 11:34:36 +0200113parser.add_argument('-a', '--auto-distclean', action='store_true',
114 help='''run "make distclean" automatically if source directory already configured''')
115
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200116args = parser.parse_args()
117
Neels Hofmeyr450dac72017-08-22 19:27:08 +0200118class listdict(dict):
119 'a dict of lists { "a": [1, 2, 3], "b": [1, 2] }'
120
121 def add(self, name, item):
122 l = self.get(name)
123 if not l:
124 l = []
125 self[name] = l
126 l.append(item)
127
128 def extend(self, name, l):
129 for v in l:
130 self.add(name, v)
131
132 def add_dict(self, d):
133 for k,v in d.items():
134 self.add(k, v)
135
136 def extend_dict(self, d):
137 for k,v in d.items():
138 l = self.extend(k, v)
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200139
140def read_projects_deps(path):
141 'Read deps config and return tuples of (project_name, which-other-to-build-first).'
142 l = []
143 for line in open(path):
144 line = line.strip()
145 if not line or line.startswith('#'):
146 continue
147 tokens = line.split()
148 l.append((tokens[0], tokens[1:]))
149 return l
150
151def read_configure_opts(path):
152 'Read config opts file and return tuples of (project_name, config-opts).'
153 if not path:
154 return {}
155 return dict(read_projects_deps(path))
156
Oliver Smith93bd5232022-02-22 17:36:11 +0100157def gen_makefile_clone(proj, src, src_proj, url, push_url):
158 if proj == "osmocom-bb_layer23":
159 return f'''
160.make.{proj}.clone: .make.osmocom-bb.clone
161 @echo -e "\\n\\n\\n===== $@\\n"
162 test -L {src_proj} || ln -s osmocom-bb/src/host/layer23 {src_proj}
163 touch $@
164 '''
165
Oliver Smith5705a692022-02-23 10:40:54 +0100166 if proj == "osmocom-bb_virtphy":
167 return f'''
168.make.{proj}.clone: .make.osmocom-bb.clone
169 @echo -e "\\n\\n\\n===== $@\\n"
170 test -L {src_proj} || ln -s osmocom-bb/src/host/virt_phy {src_proj}
171 touch $@
172 '''
173
Neels Hofmeyr179d9512022-06-17 16:57:08 +0200174 if proj in ("libgtpnl", "libnftnl", "nftables"):
Neels Hofmeyrfbd4b5b2022-02-24 16:36:21 +0100175 url = "git://git.netfilter.org"
176
Oliver Smith93bd5232022-02-22 17:36:11 +0100177 return f'''
178.make.{proj}.clone:
179 @echo -e "\\n\\n\\n===== $@\\n"
180 test -d {src} || mkdir -p {src}
181 test -d {src_proj} || ( git -C {src} clone "{url}/{proj}" "{proj}" && git -C "{src}/{proj}" remote set-url --push origin "{push_url}/{proj}" )
182 sync
183 touch $@
184 '''
185
Neels Hofmeyrf6078c42018-09-04 14:34:33 +0200186def 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):
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200187 src_proj = os.path.join(src_dir, proj)
Neels Hofmeyr29fde6f2018-04-01 15:57:02 +0200188 if proj == 'openbsc':
189 src_proj = os.path.join(src_proj, 'openbsc')
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200190 build_proj = os.path.join(build_dir, proj)
191
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200192 make_to_build_proj = os.path.relpath(build_proj, make_dir)
193 build_to_src = os.path.relpath(src_proj, build_proj)
Xilokara1cf1cd2022-03-22 09:59:25 +0100194 src = os.path.relpath(src_dir, make_dir)
195 src_proj = os.path.relpath(src_proj, make_dir)
Oliver Smith93bd5232022-02-22 17:36:11 +0100196 push_url = push_url or url
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200197
198 if configure_opts:
199 configure_opts_str = ' '.join(configure_opts)
200 else:
201 configure_opts_str = ''
202
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200203 return r'''
204### {proj} ###
205
Oliver Smith107f35d2022-02-23 17:45:46 +0100206{proj}_configure_files := $(shell find -L {src_proj} \
Oliver Smith505f60d2021-10-04 12:55:44 +0200207 -name "Makefile.am" \
208 -or -name "*.in" \
209 -and -not -name "Makefile.in" \
Oliver Smith84df01a2021-12-10 17:22:58 +0100210 -and -not -name "config.h.in" 2>/dev/null)
Oliver Smith107f35d2022-02-23 17:45:46 +0100211{proj}_files := $(shell find -L {src_proj} \
Oliver Smithf7f8c962021-10-04 12:57:26 +0200212 \( \
213 -name "*.[hc]" \
214 -or -name "*.py" \
215 -or -name "*.cpp" \
216 -or -name "*.tpl" \
217 -or -name "*.map" \
218 \) \
Oliver Smith84df01a2021-12-10 17:22:58 +0100219 -and -not -name "config.h" 2>/dev/null)
Neels Hofmeyr1c1e4d22017-09-11 01:32:50 +0200220
Oliver Smith93bd5232022-02-22 17:36:11 +0100221{clone_rule}
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200222
223.make.{proj}.autoconf: .make.{proj}.clone {src_proj}/configure.ac
Oliver Smithadfa0c02021-10-04 11:34:36 +0200224 if {distclean_cond}; then $(MAKE) {proj}-distclean; fi
Vadim Yanitskiyd9cdec62020-06-01 00:52:12 +0700225 @echo -e "\n\n\n===== $@\n"
Neels Hofmeyr1fa9b292018-04-23 17:04:25 +0200226 -rm -f {src_proj}/.version
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200227 cd {src_proj}; autoreconf -fi
Neels Hofmeyr7bd5c312018-07-26 16:43:01 +0200228 sync
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200229 touch $@
230
Neels Hofmeyr367cb972017-12-15 04:01:13 +0100231.make.{proj}.configure: .make.{proj}.autoconf {deps_installed} $({proj}_configure_files)
Oliver Smithadfa0c02021-10-04 11:34:36 +0200232 if {distclean_cond}; then $(MAKE) {proj}-distclean .make.{proj}.autoconf; fi
Vadim Yanitskiyd9cdec62020-06-01 00:52:12 +0700233 @echo -e "\n\n\n===== $@\n"
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200234 -chmod -R ug+w {build_proj}
235 -rm -rf {build_proj}
236 mkdir -p {build_proj}
Neels Hofmeyr2325e2e2021-10-23 20:42:44 +0200237 cd {build_proj}; {cflags}{docker_cmd}{build_to_src}/configure {configure_opts}
Neels Hofmeyr7bd5c312018-07-26 16:43:01 +0200238 sync
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200239 touch $@
240
Neels Hofmeyr367cb972017-12-15 04:01:13 +0100241.make.{proj}.build: .make.{proj}.configure $({proj}_files)
Oliver Smithadfa0c02021-10-04 11:34:36 +0200242 if {distclean_cond}; then $(MAKE) {proj}-distclean .make.{proj}.configure; fi
Vadim Yanitskiyd9cdec62020-06-01 00:52:12 +0700243 @echo -e "\n\n\n===== $@\n"
Oliver Smithc47eafb2021-08-12 12:45:36 +0200244 {docker_cmd}$(MAKE) -C {build_proj} -j {jobs} {check}
Neels Hofmeyr7bd5c312018-07-26 16:43:01 +0200245 sync
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200246 touch $@
247
248.make.{proj}.install: .make.{proj}.build
Vadim Yanitskiyd9cdec62020-06-01 00:52:12 +0700249 @echo -e "\n\n\n===== $@\n"
Oliver Smithc47eafb2021-08-12 12:45:36 +0200250 {docker_cmd}{sudo_make_install}$(MAKE) -C {build_proj} install
Neels Hofmeyr461c3bd2017-12-06 00:32:15 +0100251 {no_ldconfig}{sudo_ldconfig}ldconfig
Neels Hofmeyr7bd5c312018-07-26 16:43:01 +0200252 sync
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200253 touch $@
Neels Hofmeyr277f4792017-08-29 12:30:32 +0200254
Neels Hofmeyr6d16ae92018-09-04 14:36:15 +0200255.PHONY: {proj}
Neels Hofmeyr3f934122017-08-29 12:31:59 +0200256{proj}: .make.{proj}.install
257
Neels Hofmeyr4d38c1e2018-04-23 17:04:15 +0200258.PHONY: {proj}-reinstall
259{proj}-reinstall: {deps_reinstall}
260 {sudo_make_install}$(MAKE) -C {build_proj} install
261
Neels Hofmeyr277f4792017-08-29 12:30:32 +0200262.PHONY: {proj}-clean
263{proj}-clean:
Vadim Yanitskiyd9cdec62020-06-01 00:52:12 +0700264 @echo -e "\n\n\n===== $@\n"
Neels Hofmeyr277f4792017-08-29 12:30:32 +0200265 -chmod -R ug+w {build_proj}
266 -rm -rf {build_proj}
267 -rm -rf .make.{proj}.*
Oliver Smithadfa0c02021-10-04 11:34:36 +0200268
269.PHONY: {proj}-distclean
270{proj}-distclean: {proj}-clean
271 @echo -e "\n\n\n===== $@\n"
272 $(MAKE) -C {src_proj} distclean
273
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200274'''.format(
275 url=url,
Oliver Smith93bd5232022-02-22 17:36:11 +0100276 push_url=push_url,
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200277 proj=proj,
278 jobs=jobs,
Oliver Smith93bd5232022-02-22 17:36:11 +0100279 src=src,
280 src_proj=src_proj,
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200281 build_proj=make_to_build_proj,
282 build_to_src=build_to_src,
Oliver Smith93bd5232022-02-22 17:36:11 +0100283 clone_rule=gen_makefile_clone(proj, src, src_proj, url, push_url),
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200284 deps_installed=' '.join(['.make.%s.install' % d for d in deps]),
Neels Hofmeyr4d38c1e2018-04-23 17:04:15 +0200285 deps_reinstall=' '.join(['%s-reinstall' %d for d in deps]),
Neels Hofmeyr461c3bd2017-12-06 00:32:15 +0100286 configure_opts=configure_opts_str,
287 sudo_make_install='sudo ' if sudo_make_install else '',
288 no_ldconfig='#' if no_ldconfig else '',
Neels Hofmeyrf6078c42018-09-04 14:34:33 +0200289 sudo_ldconfig='' if ldconfig_without_sudo else 'sudo ',
290 check='check' if make_check else '',
Oliver Smithc47eafb2021-08-12 12:45:36 +0200291 docker_cmd=f'{args.docker_cmd} ' if args.docker_cmd else '',
Neels Hofmeyr2325e2e2021-10-23 20:42:44 +0200292 cflags='CFLAGS=-g ' if args.build_debug else '',
Oliver Smith93bd5232022-02-22 17:36:11 +0100293 distclean_cond=f'[ -e {src_proj}/config.status ]' if args.auto_distclean else 'false'
Neels Hofmeyr461c3bd2017-12-06 00:32:15 +0100294 )
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200295
296
Oliver Smith0a4d8ea2021-07-29 14:32:29 +0200297projects_deps = read_projects_deps(all_deps_file)
Neels Hofmeyr450dac72017-08-22 19:27:08 +0200298configure_opts = listdict()
299configure_opts_files = sorted(args.configure_opts_files or [])
300for configure_opts_file in configure_opts_files:
Oliver Smith0a4d8ea2021-07-29 14:32:29 +0200301 if configure_opts_file.endswith(".deps"):
302 print(f"WARNING: using {all_deps_file} instead of {configure_opts_file}")
303 continue
Neels Hofmeyr450dac72017-08-22 19:27:08 +0200304 r = read_configure_opts(configure_opts_file)
305 configure_opts.extend_dict(read_configure_opts(configure_opts_file))
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200306
307make_dir = args.make_dir
308if not make_dir:
Neels Hofmeyr450dac72017-08-22 19:27:08 +0200309 opts_names = '+'.join([f.replace('.opts', '') for f in configure_opts_files])
Oliver Smith0a4d8ea2021-07-29 14:32:29 +0200310 make_dir = 'make-%s' % opts_names
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200311
312if not os.path.isdir(make_dir):
313 os.makedirs(make_dir)
314
315build_dir = args.build_dir
316if not build_dir:
317 build_dir = make_dir
318
319output = os.path.join(make_dir, args.output)
320print('Writing to %r' % output)
321
322with open(output, 'w') as out:
323 out.write('# This Makefile was generated by %s\n' % os.path.basename(sys.argv[0]))
324
Oliver Smith0a4d8ea2021-07-29 14:32:29 +0200325 configure_opts_args = ""
326 for f in configure_opts_files:
327 if not f.endswith(".deps"):
328 configure_opts_args += f' \\\n\t\t{os.path.relpath(f, make_dir)}'
329
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200330 # convenience: add a regen target that updates the generated makefile itself
331 out.write(r'''
Oliver Smith0a4d8ea2021-07-29 14:32:29 +0200332default: usrp
333
Oliver Smith93bd5232022-02-22 17:36:11 +0100334#
335# Convenience targets for whole networks
336#
Oliver Smithca0d2902022-02-23 12:55:10 +0100337.PHONY: cn
Oliver Smith0a4d8ea2021-07-29 14:32:29 +0200338cn: \
339 osmo-ggsn \
340 osmo-hlr \
341 osmo-iuh \
342 osmo-mgw \
343 osmo-msc \
344 osmo-sgsn \
345 osmo-sip-connector \
346 osmo-smlc \
347 $(NULL)
348
Oliver Smithca0d2902022-02-23 12:55:10 +0100349.PHONY: cn-bsc
Oliver Smith0a4d8ea2021-07-29 14:32:29 +0200350cn-bsc: \
351 cn \
352 osmo-bsc \
353 $(NULL)
354
Oliver Smith5452c6e2022-02-23 13:06:26 +0100355.PHONY: cn-bsc-nat
356cn-bsc-nat: \
357 cn \
358 mobile \
359 osmo-bsc \
360 osmo-bsc-nat \
361 osmo-bts \
362 virtphy \
363 $(NULL)
364
Oliver Smithca0d2902022-02-23 12:55:10 +0100365.PHONY: usrp
Oliver Smith0a4d8ea2021-07-29 14:32:29 +0200366usrp: \
367 cn-bsc \
368 osmo-bts \
369 osmo-trx \
370 $(NULL)
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200371
Oliver Smith93bd5232022-02-22 17:36:11 +0100372#
373# Convenience targets for components in subdirs of repositories
374#
375.PHONY: mobile
376mobile: osmocom-bb_layer23
377
Oliver Smith5705a692022-02-23 10:40:54 +0100378.PHONY: virtphy
379virtphy: osmocom-bb_virtphy
380
Oliver Smith93bd5232022-02-22 17:36:11 +0100381#
382# Other convenience targets
383#
Neels Hofmeyr1b0d34f2018-03-16 03:46:08 +0100384.PHONY: all_debug
385all_debug:
386 $(MAKE) --dry-run -d all | grep "is newer than target"
387 $(MAKE) all
388
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200389# regenerate this Makefile, in case the deps or opts changed
390.PHONY: regen
391regen:
Oliver Smithb3ae4b62021-01-28 11:20:04 +0100392 {script} \
Oliver Smithb3ae4b62021-01-28 11:20:04 +0100393 {configure_opts} \
394 -m {make_dir} \
395 -o {makefile} \
396 -s {src_dir} \
397 -b {build_dir} \
Oliver Smithadfa0c02021-10-04 11:34:36 +0200398 -u "{url}"{push_url}{sudo_make_install}{no_ldconfig}{ldconfig_without_sudo}{make_check}{docker_cmd}{build_debug}{auto_distclean}
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200399
400'''.format(
401 script=os.path.relpath(sys.argv[0], make_dir),
Oliver Smith0a4d8ea2021-07-29 14:32:29 +0200402 configure_opts=configure_opts_args,
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200403 make_dir='.',
404 makefile=args.output,
405 src_dir=os.path.relpath(args.src_dir, make_dir),
406 build_dir=os.path.relpath(build_dir, make_dir),
Neels Hofmeyr461c3bd2017-12-06 00:32:15 +0100407 url=args.url,
Oliver Smithb3ae4b62021-01-28 11:20:04 +0100408 push_url=(" \\\n\t\t-p '%s'"%args.push_url) if args.push_url else '',
409 sudo_make_install=' \\\n\t\t-I' if args.sudo_make_install else '',
410 no_ldconfig=' \\\n\t\t-L' if args.no_ldconfig else '',
411 ldconfig_without_sudo=' \\\n\t\t--ldconfig-without-sudo' if args.ldconfig_without_sudo else '',
412 make_check='' if args.make_check else " \\\n\t\t--no-make-check",
Neels Hofmeyr2325e2e2021-10-23 20:42:44 +0200413 docker_cmd=f' \\\n\t\t--docker-cmd "{args.docker_cmd}"' if args.docker_cmd else '',
414 build_debug=f' \\\n\t\t--build-debug' if args.build_debug else '',
Oliver Smithadfa0c02021-10-04 11:34:36 +0200415 auto_distclean=' \\\n\t\t--auto-distclean' if args.auto_distclean else '',
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200416 ))
417
Neels Hofmeyre274d352017-08-22 17:31:03 +0200418 # convenience target: clone all repositories first
419 out.write('clone: \\\n\t' + ' \\\n\t'.join([ '.make.%s.clone' % p for p, d in projects_deps ]) + '\n\n')
420
Neels Hofmeyr277f4792017-08-29 12:30:32 +0200421 # convenience target: clean all
422 out.write('clean: \\\n\t' + ' \\\n\t'.join([ '%s-clean' % p for p, d in projects_deps ]) + '\n\n')
423
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200424 # now the actual useful build rules
Neels Hofmeyr1c1e4d22017-09-11 01:32:50 +0200425 out.write('all: clone all-install\n\n')
426
427 out.write('all-install: \\\n\t' + ' \\\n\t'.join([ '.make.%s.install' % p for p, d in projects_deps ]) + '\n\n')
Neels Hofmeyr0a1bdff2017-08-13 03:22:42 +0200428
429 for proj, deps in projects_deps:
Neels Hofmeyra007eaa2018-09-04 14:37:13 +0200430 all_config_opts = []
431 all_config_opts.extend(configure_opts.get('ALL') or [])
432 all_config_opts.extend(configure_opts.get(proj) or [])
433 out.write(gen_make(proj, deps, all_config_opts, args.jobs,
Neels Hofmeyr28d4be52018-03-16 03:44:07 +0100434 make_dir, args.src_dir, build_dir, args.url, args.push_url,
Neels Hofmeyr461c3bd2017-12-06 00:32:15 +0100435 args.sudo_make_install, args.no_ldconfig,
Neels Hofmeyrf6078c42018-09-04 14:34:33 +0200436 args.ldconfig_without_sudo, args.make_check))
Neels Hofmeyrd4d88482017-08-22 19:27:28 +0200437
438# vim: expandtab tabstop=2 shiftwidth=2