Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | ''' |
| 3 | Generate a top-level makefile that builds the Osmocom 2G + 3G network components. |
| 4 | |
Oliver Smith | 0a4d8ea | 2021-07-29 14:32:29 +0200 | [diff] [blame] | 5 | ./gen_makefile.py [configure.opts [more.opts]] [-o Makefile.output] |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 6 | |
| 7 | Configured by text files: |
| 8 | |
Oliver Smith | 0a4d8ea | 2021-07-29 14:32:29 +0200 | [diff] [blame] | 9 | all.deps: whitespace-separated listing of |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 10 | 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 | |
| 15 | Thus it is possible to choose between e.g. |
Oliver Smith | 0a4d8ea | 2021-07-29 14:32:29 +0200 | [diff] [blame] | 16 | - building each of those with or without mgcp transcoding support by adding or |
| 17 | removing "transcoding.opts" from the command line |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 18 | |
| 19 | From the Makefile nature, the dependencies extend, no need to repeat common deps. |
| 20 | |
| 21 | When this script is done, a Makefile has been generated that allows you to |
| 22 | build all projects at once by issuing 'make', but also to refresh only parts of |
| 23 | it when some bits in the middle have changed. The makefile keeps local progress |
| 24 | marker files like .make.libosmocore.configure; if such progress marker is |
| 25 | removed or becomes outdated, that step and all dependent ones are re-run. |
| 26 | This is helpful in daily hacking across several repositories. |
Neels Hofmeyr | 461c3bd | 2017-12-06 00:32:15 +0100 | [diff] [blame] | 27 | |
| 28 | Note that by default, this includes 'sudo ldconfig' calls following each |
| 29 | installation. You may want to permit your user to run 'sudo ldconfig' without |
| 30 | needing a password, e.g. by |
| 31 | |
| 32 | sudo sh -c "echo '$USER ALL= NOPASSWD: /sbin/ldconfig' > /etc/sudoers.d/${USER}_ldconfig" |
| 33 | |
| 34 | You can skip the 'sudo ldconfig' by issuing the --no-ldconfig option. |
| 35 | |
| 36 | You can run 'ldconfig' without sudo by issuing the --ldconfig-without-sudo option. |
| 37 | |
| 38 | By default, it is assumed that your user has write permission to /usr/local. If you |
| 39 | need sudo to install there, you may issue the --sudo-make-install option. |
Neels Hofmeyr | 2535a26 | 2018-01-16 16:34:32 +0100 | [diff] [blame] | 40 | |
| 41 | EXAMPLE: |
| 42 | |
Oliver Smith | 0a4d8ea | 2021-07-29 14:32:29 +0200 | [diff] [blame] | 43 | ./gen_makefile.py default.opts iu.opts -I -m build |
Neels Hofmeyr | 2535a26 | 2018-01-16 16:34:32 +0100 | [diff] [blame] | 44 | cd build |
| 45 | make |
| 46 | |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 47 | ''' |
| 48 | |
| 49 | import sys |
| 50 | import os |
| 51 | import argparse |
| 52 | |
Oliver Smith | 0a4d8ea | 2021-07-29 14:32:29 +0200 | [diff] [blame] | 53 | topdir = os.path.dirname(os.path.realpath(__file__)) |
| 54 | all_deps_file = os.path.join(topdir, "all.deps") |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 55 | parser = argparse.ArgumentParser(epilog=__doc__, formatter_class=argparse.RawTextHelpFormatter) |
| 56 | |
Neels Hofmeyr | 450dac7 | 2017-08-22 19:27:08 +0200 | [diff] [blame] | 57 | parser.add_argument('configure_opts_files', |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 58 | help='''Config file containing project name and |
| 59 | ./configure options''', |
Neels Hofmeyr | 450dac7 | 2017-08-22 19:27:08 +0200 | [diff] [blame] | 60 | nargs='*') |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 61 | |
| 62 | parser.add_argument('-m', '--make-dir', dest='make_dir', |
| 63 | help='''Place Makefile in this dir (default: create |
Oliver Smith | 0a4d8ea | 2021-07-29 14:32:29 +0200 | [diff] [blame] | 64 | a new dir named after opts files).''') |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 65 | |
| 66 | parser.add_argument('-s', '--src-dir', dest='src_dir', default='./src', |
| 67 | help='Parent dir for all git clones.') |
| 68 | |
| 69 | parser.add_argument('-b', '--build-dir', dest='build_dir', |
| 70 | help='''Parent dir for all build trees (default: |
| 71 | directly in the make-dir).''') |
| 72 | |
Neels Hofmeyr | bffdc30 | 2017-12-06 00:31:49 +0100 | [diff] [blame] | 73 | parser.add_argument('-u', '--url', dest='url', default='git://git.osmocom.org', |
| 74 | help='''git clone base URL. Default is 'git://git.osmocom.org'. |
| 75 | e.g. with a config like this in your ~/.ssh/config: |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 76 | host go |
| 77 | hostname gerrit.osmocom.org |
| 78 | port 29418 |
Neels Hofmeyr | bffdc30 | 2017-12-06 00:31:49 +0100 | [diff] [blame] | 79 | you may pass '-u ssh://go' to be able to submit to gerrit.''') |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 80 | |
Neels Hofmeyr | 972c294 | 2018-03-16 03:49:58 +0100 | [diff] [blame] | 81 | parser.add_argument('-p', '--push-url', dest='push_url', default='', |
Neels Hofmeyr | 28d4be5 | 2018-03-16 03:44:07 +0100 | [diff] [blame] | 82 | help='''git push-URL. Default is to not configure a separate push-URL.''') |
| 83 | |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 84 | parser.add_argument('-o', '--output', dest='output', default='Makefile', |
| 85 | help='''Makefile filename (default: 'Makefile').''') |
| 86 | |
| 87 | parser.add_argument('-j', '--jobs', dest='jobs', default='9', |
| 88 | help='''-j option to pass to 'make'.''') |
| 89 | |
Neels Hofmeyr | 461c3bd | 2017-12-06 00:32:15 +0100 | [diff] [blame] | 90 | parser.add_argument('-I', '--sudo-make-install', dest='sudo_make_install', |
| 91 | action='store_true', |
| 92 | help='''run 'make install' step with 'sudo'.''') |
| 93 | |
| 94 | parser.add_argument('-L', '--no-ldconfig', dest='no_ldconfig', |
| 95 | action='store_true', |
| 96 | help='''omit the 'sudo ldconfig' step.''') |
| 97 | |
| 98 | parser.add_argument('--ldconfig-without-sudo', dest='ldconfig_without_sudo', |
| 99 | action='store_true', |
| 100 | help='''call just 'ldconfig', without sudo, which implies |
| 101 | root privileges (not recommended)''') |
| 102 | |
Neels Hofmeyr | f6078c4 | 2018-09-04 14:34:33 +0200 | [diff] [blame] | 103 | parser.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 Smith | c47eafb | 2021-08-12 12:45:36 +0200 | [diff] [blame] | 107 | parser.add_argument('--docker-cmd', |
| 108 | help='''prefix configure/make/make install calls with this command (used by ttcn3.sh)''') |
| 109 | |
Neels Hofmeyr | 2325e2e | 2021-10-23 20:42:44 +0200 | [diff] [blame] | 110 | parser.add_argument('-g', '--build-debug', dest='build_debug', default=False, action='store_true', |
| 111 | help='''set 'CFLAGS=-g' when calling src/configure''') |
| 112 | |
Oliver Smith | adfa0c0 | 2021-10-04 11:34:36 +0200 | [diff] [blame] | 113 | parser.add_argument('-a', '--auto-distclean', action='store_true', |
| 114 | help='''run "make distclean" automatically if source directory already configured''') |
| 115 | |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 116 | args = parser.parse_args() |
| 117 | |
Neels Hofmeyr | 450dac7 | 2017-08-22 19:27:08 +0200 | [diff] [blame] | 118 | class 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 Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 139 | |
| 140 | def 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 | |
| 151 | def 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 Smith | 93bd523 | 2022-02-22 17:36:11 +0100 | [diff] [blame] | 157 | def 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 Smith | 5705a69 | 2022-02-23 10:40:54 +0100 | [diff] [blame] | 166 | 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 | |
Oliver Smith | 93bd523 | 2022-02-22 17:36:11 +0100 | [diff] [blame] | 174 | return f''' |
| 175 | .make.{proj}.clone: |
| 176 | @echo -e "\\n\\n\\n===== $@\\n" |
| 177 | test -d {src} || mkdir -p {src} |
| 178 | test -d {src_proj} || ( git -C {src} clone "{url}/{proj}" "{proj}" && git -C "{src}/{proj}" remote set-url --push origin "{push_url}/{proj}" ) |
| 179 | sync |
| 180 | touch $@ |
| 181 | ''' |
| 182 | |
Neels Hofmeyr | f6078c4 | 2018-09-04 14:34:33 +0200 | [diff] [blame] | 183 | 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): |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 184 | src_proj = os.path.join(src_dir, proj) |
Neels Hofmeyr | 29fde6f | 2018-04-01 15:57:02 +0200 | [diff] [blame] | 185 | if proj == 'openbsc': |
| 186 | src_proj = os.path.join(src_proj, 'openbsc') |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 187 | build_proj = os.path.join(build_dir, proj) |
| 188 | |
Oliver Smith | 93bd523 | 2022-02-22 17:36:11 +0100 | [diff] [blame] | 189 | src = os.path.relpath(src_dir, make_dir) |
| 190 | src_proj = os.path.relpath(src_proj, make_dir) |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 191 | make_to_build_proj = os.path.relpath(build_proj, make_dir) |
| 192 | build_to_src = os.path.relpath(src_proj, build_proj) |
Oliver Smith | 93bd523 | 2022-02-22 17:36:11 +0100 | [diff] [blame] | 193 | push_url = push_url or url |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 194 | |
| 195 | if configure_opts: |
| 196 | configure_opts_str = ' '.join(configure_opts) |
| 197 | else: |
| 198 | configure_opts_str = '' |
| 199 | |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 200 | return r''' |
| 201 | ### {proj} ### |
| 202 | |
Oliver Smith | 107f35d | 2022-02-23 17:45:46 +0100 | [diff] [blame] | 203 | {proj}_configure_files := $(shell find -L {src_proj} \ |
Oliver Smith | 505f60d | 2021-10-04 12:55:44 +0200 | [diff] [blame] | 204 | -name "Makefile.am" \ |
| 205 | -or -name "*.in" \ |
| 206 | -and -not -name "Makefile.in" \ |
Oliver Smith | 84df01a | 2021-12-10 17:22:58 +0100 | [diff] [blame] | 207 | -and -not -name "config.h.in" 2>/dev/null) |
Oliver Smith | 107f35d | 2022-02-23 17:45:46 +0100 | [diff] [blame] | 208 | {proj}_files := $(shell find -L {src_proj} \ |
Oliver Smith | f7f8c96 | 2021-10-04 12:57:26 +0200 | [diff] [blame] | 209 | \( \ |
| 210 | -name "*.[hc]" \ |
| 211 | -or -name "*.py" \ |
| 212 | -or -name "*.cpp" \ |
| 213 | -or -name "*.tpl" \ |
| 214 | -or -name "*.map" \ |
| 215 | \) \ |
Oliver Smith | 84df01a | 2021-12-10 17:22:58 +0100 | [diff] [blame] | 216 | -and -not -name "config.h" 2>/dev/null) |
Neels Hofmeyr | 1c1e4d2 | 2017-09-11 01:32:50 +0200 | [diff] [blame] | 217 | |
Oliver Smith | 93bd523 | 2022-02-22 17:36:11 +0100 | [diff] [blame] | 218 | {clone_rule} |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 219 | |
| 220 | .make.{proj}.autoconf: .make.{proj}.clone {src_proj}/configure.ac |
Oliver Smith | adfa0c0 | 2021-10-04 11:34:36 +0200 | [diff] [blame] | 221 | if {distclean_cond}; then $(MAKE) {proj}-distclean; fi |
Vadim Yanitskiy | d9cdec6 | 2020-06-01 00:52:12 +0700 | [diff] [blame] | 222 | @echo -e "\n\n\n===== $@\n" |
Neels Hofmeyr | 1fa9b29 | 2018-04-23 17:04:25 +0200 | [diff] [blame] | 223 | -rm -f {src_proj}/.version |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 224 | cd {src_proj}; autoreconf -fi |
Neels Hofmeyr | 7bd5c31 | 2018-07-26 16:43:01 +0200 | [diff] [blame] | 225 | sync |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 226 | touch $@ |
| 227 | |
Neels Hofmeyr | 367cb97 | 2017-12-15 04:01:13 +0100 | [diff] [blame] | 228 | .make.{proj}.configure: .make.{proj}.autoconf {deps_installed} $({proj}_configure_files) |
Oliver Smith | adfa0c0 | 2021-10-04 11:34:36 +0200 | [diff] [blame] | 229 | if {distclean_cond}; then $(MAKE) {proj}-distclean .make.{proj}.autoconf; fi |
Vadim Yanitskiy | d9cdec6 | 2020-06-01 00:52:12 +0700 | [diff] [blame] | 230 | @echo -e "\n\n\n===== $@\n" |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 231 | -chmod -R ug+w {build_proj} |
| 232 | -rm -rf {build_proj} |
| 233 | mkdir -p {build_proj} |
Neels Hofmeyr | 2325e2e | 2021-10-23 20:42:44 +0200 | [diff] [blame] | 234 | cd {build_proj}; {cflags}{docker_cmd}{build_to_src}/configure {configure_opts} |
Neels Hofmeyr | 7bd5c31 | 2018-07-26 16:43:01 +0200 | [diff] [blame] | 235 | sync |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 236 | touch $@ |
| 237 | |
Neels Hofmeyr | 367cb97 | 2017-12-15 04:01:13 +0100 | [diff] [blame] | 238 | .make.{proj}.build: .make.{proj}.configure $({proj}_files) |
Oliver Smith | adfa0c0 | 2021-10-04 11:34:36 +0200 | [diff] [blame] | 239 | if {distclean_cond}; then $(MAKE) {proj}-distclean .make.{proj}.configure; fi |
Vadim Yanitskiy | d9cdec6 | 2020-06-01 00:52:12 +0700 | [diff] [blame] | 240 | @echo -e "\n\n\n===== $@\n" |
Oliver Smith | c47eafb | 2021-08-12 12:45:36 +0200 | [diff] [blame] | 241 | {docker_cmd}$(MAKE) -C {build_proj} -j {jobs} {check} |
Neels Hofmeyr | 7bd5c31 | 2018-07-26 16:43:01 +0200 | [diff] [blame] | 242 | sync |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 243 | touch $@ |
| 244 | |
| 245 | .make.{proj}.install: .make.{proj}.build |
Vadim Yanitskiy | d9cdec6 | 2020-06-01 00:52:12 +0700 | [diff] [blame] | 246 | @echo -e "\n\n\n===== $@\n" |
Oliver Smith | c47eafb | 2021-08-12 12:45:36 +0200 | [diff] [blame] | 247 | {docker_cmd}{sudo_make_install}$(MAKE) -C {build_proj} install |
Neels Hofmeyr | 461c3bd | 2017-12-06 00:32:15 +0100 | [diff] [blame] | 248 | {no_ldconfig}{sudo_ldconfig}ldconfig |
Neels Hofmeyr | 7bd5c31 | 2018-07-26 16:43:01 +0200 | [diff] [blame] | 249 | sync |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 250 | touch $@ |
Neels Hofmeyr | 277f479 | 2017-08-29 12:30:32 +0200 | [diff] [blame] | 251 | |
Neels Hofmeyr | 6d16ae9 | 2018-09-04 14:36:15 +0200 | [diff] [blame] | 252 | .PHONY: {proj} |
Neels Hofmeyr | 3f93412 | 2017-08-29 12:31:59 +0200 | [diff] [blame] | 253 | {proj}: .make.{proj}.install |
| 254 | |
Neels Hofmeyr | 4d38c1e | 2018-04-23 17:04:15 +0200 | [diff] [blame] | 255 | .PHONY: {proj}-reinstall |
| 256 | {proj}-reinstall: {deps_reinstall} |
| 257 | {sudo_make_install}$(MAKE) -C {build_proj} install |
| 258 | |
Neels Hofmeyr | 277f479 | 2017-08-29 12:30:32 +0200 | [diff] [blame] | 259 | .PHONY: {proj}-clean |
| 260 | {proj}-clean: |
Vadim Yanitskiy | d9cdec6 | 2020-06-01 00:52:12 +0700 | [diff] [blame] | 261 | @echo -e "\n\n\n===== $@\n" |
Neels Hofmeyr | 277f479 | 2017-08-29 12:30:32 +0200 | [diff] [blame] | 262 | -chmod -R ug+w {build_proj} |
| 263 | -rm -rf {build_proj} |
| 264 | -rm -rf .make.{proj}.* |
Oliver Smith | adfa0c0 | 2021-10-04 11:34:36 +0200 | [diff] [blame] | 265 | |
| 266 | .PHONY: {proj}-distclean |
| 267 | {proj}-distclean: {proj}-clean |
| 268 | @echo -e "\n\n\n===== $@\n" |
| 269 | $(MAKE) -C {src_proj} distclean |
| 270 | |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 271 | '''.format( |
| 272 | url=url, |
Oliver Smith | 93bd523 | 2022-02-22 17:36:11 +0100 | [diff] [blame] | 273 | push_url=push_url, |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 274 | proj=proj, |
| 275 | jobs=jobs, |
Oliver Smith | 93bd523 | 2022-02-22 17:36:11 +0100 | [diff] [blame] | 276 | src=src, |
| 277 | src_proj=src_proj, |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 278 | build_proj=make_to_build_proj, |
| 279 | build_to_src=build_to_src, |
Oliver Smith | 93bd523 | 2022-02-22 17:36:11 +0100 | [diff] [blame] | 280 | clone_rule=gen_makefile_clone(proj, src, src_proj, url, push_url), |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 281 | deps_installed=' '.join(['.make.%s.install' % d for d in deps]), |
Neels Hofmeyr | 4d38c1e | 2018-04-23 17:04:15 +0200 | [diff] [blame] | 282 | deps_reinstall=' '.join(['%s-reinstall' %d for d in deps]), |
Neels Hofmeyr | 461c3bd | 2017-12-06 00:32:15 +0100 | [diff] [blame] | 283 | configure_opts=configure_opts_str, |
| 284 | sudo_make_install='sudo ' if sudo_make_install else '', |
| 285 | no_ldconfig='#' if no_ldconfig else '', |
Neels Hofmeyr | f6078c4 | 2018-09-04 14:34:33 +0200 | [diff] [blame] | 286 | sudo_ldconfig='' if ldconfig_without_sudo else 'sudo ', |
| 287 | check='check' if make_check else '', |
Oliver Smith | c47eafb | 2021-08-12 12:45:36 +0200 | [diff] [blame] | 288 | docker_cmd=f'{args.docker_cmd} ' if args.docker_cmd else '', |
Neels Hofmeyr | 2325e2e | 2021-10-23 20:42:44 +0200 | [diff] [blame] | 289 | cflags='CFLAGS=-g ' if args.build_debug else '', |
Oliver Smith | 93bd523 | 2022-02-22 17:36:11 +0100 | [diff] [blame] | 290 | distclean_cond=f'[ -e {src_proj}/config.status ]' if args.auto_distclean else 'false' |
Neels Hofmeyr | 461c3bd | 2017-12-06 00:32:15 +0100 | [diff] [blame] | 291 | ) |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 292 | |
| 293 | |
Oliver Smith | 0a4d8ea | 2021-07-29 14:32:29 +0200 | [diff] [blame] | 294 | projects_deps = read_projects_deps(all_deps_file) |
Neels Hofmeyr | 450dac7 | 2017-08-22 19:27:08 +0200 | [diff] [blame] | 295 | configure_opts = listdict() |
| 296 | configure_opts_files = sorted(args.configure_opts_files or []) |
| 297 | for configure_opts_file in configure_opts_files: |
Oliver Smith | 0a4d8ea | 2021-07-29 14:32:29 +0200 | [diff] [blame] | 298 | if configure_opts_file.endswith(".deps"): |
| 299 | print(f"WARNING: using {all_deps_file} instead of {configure_opts_file}") |
| 300 | continue |
Neels Hofmeyr | 450dac7 | 2017-08-22 19:27:08 +0200 | [diff] [blame] | 301 | r = read_configure_opts(configure_opts_file) |
| 302 | configure_opts.extend_dict(read_configure_opts(configure_opts_file)) |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 303 | |
| 304 | make_dir = args.make_dir |
| 305 | if not make_dir: |
Neels Hofmeyr | 450dac7 | 2017-08-22 19:27:08 +0200 | [diff] [blame] | 306 | opts_names = '+'.join([f.replace('.opts', '') for f in configure_opts_files]) |
Oliver Smith | 0a4d8ea | 2021-07-29 14:32:29 +0200 | [diff] [blame] | 307 | make_dir = 'make-%s' % opts_names |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 308 | |
| 309 | if not os.path.isdir(make_dir): |
| 310 | os.makedirs(make_dir) |
| 311 | |
| 312 | build_dir = args.build_dir |
| 313 | if not build_dir: |
| 314 | build_dir = make_dir |
| 315 | |
| 316 | output = os.path.join(make_dir, args.output) |
| 317 | print('Writing to %r' % output) |
| 318 | |
| 319 | with open(output, 'w') as out: |
| 320 | out.write('# This Makefile was generated by %s\n' % os.path.basename(sys.argv[0])) |
| 321 | |
Oliver Smith | 0a4d8ea | 2021-07-29 14:32:29 +0200 | [diff] [blame] | 322 | configure_opts_args = "" |
| 323 | for f in configure_opts_files: |
| 324 | if not f.endswith(".deps"): |
| 325 | configure_opts_args += f' \\\n\t\t{os.path.relpath(f, make_dir)}' |
| 326 | |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 327 | # convenience: add a regen target that updates the generated makefile itself |
| 328 | out.write(r''' |
Oliver Smith | 0a4d8ea | 2021-07-29 14:32:29 +0200 | [diff] [blame] | 329 | default: usrp |
| 330 | |
Oliver Smith | 93bd523 | 2022-02-22 17:36:11 +0100 | [diff] [blame] | 331 | # |
| 332 | # Convenience targets for whole networks |
| 333 | # |
Oliver Smith | ca0d290 | 2022-02-23 12:55:10 +0100 | [diff] [blame] | 334 | .PHONY: cn |
Oliver Smith | 0a4d8ea | 2021-07-29 14:32:29 +0200 | [diff] [blame] | 335 | cn: \ |
| 336 | osmo-ggsn \ |
| 337 | osmo-hlr \ |
| 338 | osmo-iuh \ |
| 339 | osmo-mgw \ |
| 340 | osmo-msc \ |
| 341 | osmo-sgsn \ |
| 342 | osmo-sip-connector \ |
| 343 | osmo-smlc \ |
| 344 | $(NULL) |
| 345 | |
Oliver Smith | ca0d290 | 2022-02-23 12:55:10 +0100 | [diff] [blame] | 346 | .PHONY: cn-bsc |
Oliver Smith | 0a4d8ea | 2021-07-29 14:32:29 +0200 | [diff] [blame] | 347 | cn-bsc: \ |
| 348 | cn \ |
| 349 | osmo-bsc \ |
| 350 | $(NULL) |
| 351 | |
Oliver Smith | 5452c6e | 2022-02-23 13:06:26 +0100 | [diff] [blame] | 352 | .PHONY: cn-bsc-nat |
| 353 | cn-bsc-nat: \ |
| 354 | cn \ |
| 355 | mobile \ |
| 356 | osmo-bsc \ |
| 357 | osmo-bsc-nat \ |
| 358 | osmo-bts \ |
| 359 | virtphy \ |
| 360 | $(NULL) |
| 361 | |
Oliver Smith | ca0d290 | 2022-02-23 12:55:10 +0100 | [diff] [blame] | 362 | .PHONY: usrp |
Oliver Smith | 0a4d8ea | 2021-07-29 14:32:29 +0200 | [diff] [blame] | 363 | usrp: \ |
| 364 | cn-bsc \ |
| 365 | osmo-bts \ |
| 366 | osmo-trx \ |
| 367 | $(NULL) |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 368 | |
Oliver Smith | 93bd523 | 2022-02-22 17:36:11 +0100 | [diff] [blame] | 369 | # |
| 370 | # Convenience targets for components in subdirs of repositories |
| 371 | # |
| 372 | .PHONY: mobile |
| 373 | mobile: osmocom-bb_layer23 |
| 374 | |
Oliver Smith | 5705a69 | 2022-02-23 10:40:54 +0100 | [diff] [blame] | 375 | .PHONY: virtphy |
| 376 | virtphy: osmocom-bb_virtphy |
| 377 | |
Oliver Smith | 93bd523 | 2022-02-22 17:36:11 +0100 | [diff] [blame] | 378 | # |
| 379 | # Other convenience targets |
| 380 | # |
Neels Hofmeyr | 1b0d34f | 2018-03-16 03:46:08 +0100 | [diff] [blame] | 381 | .PHONY: all_debug |
| 382 | all_debug: |
| 383 | $(MAKE) --dry-run -d all | grep "is newer than target" |
| 384 | $(MAKE) all |
| 385 | |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 386 | # regenerate this Makefile, in case the deps or opts changed |
| 387 | .PHONY: regen |
| 388 | regen: |
Oliver Smith | b3ae4b6 | 2021-01-28 11:20:04 +0100 | [diff] [blame] | 389 | {script} \ |
Oliver Smith | b3ae4b6 | 2021-01-28 11:20:04 +0100 | [diff] [blame] | 390 | {configure_opts} \ |
| 391 | -m {make_dir} \ |
| 392 | -o {makefile} \ |
| 393 | -s {src_dir} \ |
| 394 | -b {build_dir} \ |
Oliver Smith | adfa0c0 | 2021-10-04 11:34:36 +0200 | [diff] [blame] | 395 | -u "{url}"{push_url}{sudo_make_install}{no_ldconfig}{ldconfig_without_sudo}{make_check}{docker_cmd}{build_debug}{auto_distclean} |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 396 | |
| 397 | '''.format( |
| 398 | script=os.path.relpath(sys.argv[0], make_dir), |
Oliver Smith | 0a4d8ea | 2021-07-29 14:32:29 +0200 | [diff] [blame] | 399 | configure_opts=configure_opts_args, |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 400 | make_dir='.', |
| 401 | makefile=args.output, |
| 402 | src_dir=os.path.relpath(args.src_dir, make_dir), |
| 403 | build_dir=os.path.relpath(build_dir, make_dir), |
Neels Hofmeyr | 461c3bd | 2017-12-06 00:32:15 +0100 | [diff] [blame] | 404 | url=args.url, |
Oliver Smith | b3ae4b6 | 2021-01-28 11:20:04 +0100 | [diff] [blame] | 405 | push_url=(" \\\n\t\t-p '%s'"%args.push_url) if args.push_url else '', |
| 406 | sudo_make_install=' \\\n\t\t-I' if args.sudo_make_install else '', |
| 407 | no_ldconfig=' \\\n\t\t-L' if args.no_ldconfig else '', |
| 408 | ldconfig_without_sudo=' \\\n\t\t--ldconfig-without-sudo' if args.ldconfig_without_sudo else '', |
| 409 | make_check='' if args.make_check else " \\\n\t\t--no-make-check", |
Neels Hofmeyr | 2325e2e | 2021-10-23 20:42:44 +0200 | [diff] [blame] | 410 | docker_cmd=f' \\\n\t\t--docker-cmd "{args.docker_cmd}"' if args.docker_cmd else '', |
| 411 | build_debug=f' \\\n\t\t--build-debug' if args.build_debug else '', |
Oliver Smith | adfa0c0 | 2021-10-04 11:34:36 +0200 | [diff] [blame] | 412 | auto_distclean=' \\\n\t\t--auto-distclean' if args.auto_distclean else '', |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 413 | )) |
| 414 | |
Neels Hofmeyr | e274d35 | 2017-08-22 17:31:03 +0200 | [diff] [blame] | 415 | # convenience target: clone all repositories first |
| 416 | out.write('clone: \\\n\t' + ' \\\n\t'.join([ '.make.%s.clone' % p for p, d in projects_deps ]) + '\n\n') |
| 417 | |
Neels Hofmeyr | 277f479 | 2017-08-29 12:30:32 +0200 | [diff] [blame] | 418 | # convenience target: clean all |
| 419 | out.write('clean: \\\n\t' + ' \\\n\t'.join([ '%s-clean' % p for p, d in projects_deps ]) + '\n\n') |
| 420 | |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 421 | # now the actual useful build rules |
Neels Hofmeyr | 1c1e4d2 | 2017-09-11 01:32:50 +0200 | [diff] [blame] | 422 | out.write('all: clone all-install\n\n') |
| 423 | |
| 424 | out.write('all-install: \\\n\t' + ' \\\n\t'.join([ '.make.%s.install' % p for p, d in projects_deps ]) + '\n\n') |
Neels Hofmeyr | 0a1bdff | 2017-08-13 03:22:42 +0200 | [diff] [blame] | 425 | |
| 426 | for proj, deps in projects_deps: |
Neels Hofmeyr | a007eaa | 2018-09-04 14:37:13 +0200 | [diff] [blame] | 427 | all_config_opts = [] |
| 428 | all_config_opts.extend(configure_opts.get('ALL') or []) |
| 429 | all_config_opts.extend(configure_opts.get(proj) or []) |
| 430 | out.write(gen_make(proj, deps, all_config_opts, args.jobs, |
Neels Hofmeyr | 28d4be5 | 2018-03-16 03:44:07 +0100 | [diff] [blame] | 431 | make_dir, args.src_dir, build_dir, args.url, args.push_url, |
Neels Hofmeyr | 461c3bd | 2017-12-06 00:32:15 +0100 | [diff] [blame] | 432 | args.sudo_make_install, args.no_ldconfig, |
Neels Hofmeyr | f6078c4 | 2018-09-04 14:34:33 +0200 | [diff] [blame] | 433 | args.ldconfig_without_sudo, args.make_check)) |
Neels Hofmeyr | d4d8848 | 2017-08-22 19:27:28 +0200 | [diff] [blame] | 434 | |
| 435 | # vim: expandtab tabstop=2 shiftwidth=2 |