blob: 319cb872009eaae0bc8c3f298d810aa785490e74 [file] [log] [blame]
Harald Welte0cdf0712019-06-19 18:15:38 +02001# Copyright 2017 Harald Welte
2# Copyright 2018 sysmocom - s.f.m.c. GmbH
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
Harald Welte08332302019-08-01 09:54:40 +020016SUBDIRS=bsc bsc-nat bts cbc ccid fr fr-net gbproxy ggsn_tests hlr mgw mme msc pcu pgw remsim \
Daniel Willmann423d8f42020-09-08 18:58:22 +020017 sccp selftest sgsn simtrace sip stp sysinfo smlc
Harald Welteadd12df2017-12-12 15:51:39 +010018
Stefan Sperlingb0ad3d82018-06-25 15:19:17 +020019NPROC=$(shell nproc 2>/dev/null)
20ifeq ($(NPROC),)
21NPROC=1
22endif
23PARALLEL_MAKE ?= -j$(NPROC)
Harald Welteadd12df2017-12-12 15:51:39 +010024
25# This master makefile allows you to do things like
26# make clean (remove all generated binary, c++ and symlinks)
27# make compile (compile ttcn3 into c++)
28# make all (compile c++ into executable)
29#
30# as well as per-subdirectory targets like
31#
32# make bsc/clean
33# make bsc/compile
34# make bsc/all
35# make bsc (equivalent to bsc/all)
36
Harald Welte68079822017-12-12 16:30:53 +010037default: deps all
38
39.PHONY: deps
40deps:
41 $(MAKE) -C deps
Harald Welteadd12df2017-12-12 15:51:39 +010042
Stefan Sperling61c11e92018-03-20 18:25:26 +010043# deps-update target for backwards compat; now does the same as 'make deps'
Harald Welte6bef5dd2018-02-15 18:31:22 +010044.PHONY: deps-update
45deps-update:
Stefan Sperling61c11e92018-03-20 18:25:26 +010046 $(MAKE) -C deps
Harald Welte6bef5dd2018-02-15 18:31:22 +010047
Harald Welteadd12df2017-12-12 15:51:39 +010048compile: $(foreach dir,$(SUBDIRS),$(dir)/compile)
49clean: $(foreach dir,$(SUBDIRS),$(dir)/clean)
50all: $(foreach dir,$(SUBDIRS),$(dir)/all)
51
52define DIR_Makefile_template
53$(1)/Makefile:
54 (cd $(1) && ./gen_links.sh && ./regen_makefile.sh)
55endef
56
57define DIR_compile_template
58.PHONY: $(1)/compile
Harald Weltef6f78462017-12-12 17:31:25 +010059$(1)/compile: deps $(1)/Makefile
Harald Welteadd12df2017-12-12 15:51:39 +010060 $(MAKE) -C $(1) compile
61endef
62
63define DIR_clean_template
64.PHONY: $(1)/clean
65$(1)/clean: $(1)/Makefile
66 $(MAKE) -C $(1) clean
67 (cd $(1) && ../rmlinks.sh && rm Makefile)
68endef
69
70define DIR_all_template
71$(1): $(1)/all
72.PHONY: $(1)/all
Harald Weltef6f78462017-12-12 17:31:25 +010073$(1)/all: deps $(1)/Makefile
Harald Welteadd12df2017-12-12 15:51:39 +010074 $(MAKE) -C $(1) compile
75 $(MAKE) $(PARALLEL_MAKE) -C $(1)
76endef
77
78$(foreach dir,$(SUBDIRS), \
79 $(eval $(call DIR_Makefile_template,$(dir))) \
80 $(eval $(call DIR_compile_template,$(dir))) \
81 $(eval $(call DIR_clean_template,$(dir))) \
82 $(eval $(call DIR_all_template,$(dir))) \
83 )