blob: 99243d6e8ae8f8e4c5db4787d121d5b66eb6cb46 [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 Weltefaa42922019-03-04 18:31:11 +010016SUBDIRS=bsc bsc-nat bts ggsn_tests hlr mgw msc pcu remsim sccp selftest sgsn sip sysinfo
Harald Welteadd12df2017-12-12 15:51:39 +010017
Stefan Sperlingb0ad3d82018-06-25 15:19:17 +020018NPROC=$(shell nproc 2>/dev/null)
19ifeq ($(NPROC),)
20NPROC=1
21endif
22PARALLEL_MAKE ?= -j$(NPROC)
Harald Welteadd12df2017-12-12 15:51:39 +010023
24# This master makefile allows you to do things like
25# make clean (remove all generated binary, c++ and symlinks)
26# make compile (compile ttcn3 into c++)
27# make all (compile c++ into executable)
28#
29# as well as per-subdirectory targets like
30#
31# make bsc/clean
32# make bsc/compile
33# make bsc/all
34# make bsc (equivalent to bsc/all)
35
Harald Welte68079822017-12-12 16:30:53 +010036default: deps all
37
38.PHONY: deps
39deps:
40 $(MAKE) -C deps
Harald Welteadd12df2017-12-12 15:51:39 +010041
Stefan Sperling61c11e92018-03-20 18:25:26 +010042# deps-update target for backwards compat; now does the same as 'make deps'
Harald Welte6bef5dd2018-02-15 18:31:22 +010043.PHONY: deps-update
44deps-update:
Stefan Sperling61c11e92018-03-20 18:25:26 +010045 $(MAKE) -C deps
Harald Welte6bef5dd2018-02-15 18:31:22 +010046
Harald Welteadd12df2017-12-12 15:51:39 +010047compile: $(foreach dir,$(SUBDIRS),$(dir)/compile)
48clean: $(foreach dir,$(SUBDIRS),$(dir)/clean)
49all: $(foreach dir,$(SUBDIRS),$(dir)/all)
50
51define DIR_Makefile_template
52$(1)/Makefile:
53 (cd $(1) && ./gen_links.sh && ./regen_makefile.sh)
54endef
55
56define DIR_compile_template
57.PHONY: $(1)/compile
Harald Weltef6f78462017-12-12 17:31:25 +010058$(1)/compile: deps $(1)/Makefile
Harald Welteadd12df2017-12-12 15:51:39 +010059 $(MAKE) -C $(1) compile
60endef
61
62define DIR_clean_template
63.PHONY: $(1)/clean
64$(1)/clean: $(1)/Makefile
65 $(MAKE) -C $(1) clean
66 (cd $(1) && ../rmlinks.sh && rm Makefile)
67endef
68
69define DIR_all_template
70$(1): $(1)/all
71.PHONY: $(1)/all
Harald Weltef6f78462017-12-12 17:31:25 +010072$(1)/all: deps $(1)/Makefile
Harald Welteadd12df2017-12-12 15:51:39 +010073 $(MAKE) -C $(1) compile
74 $(MAKE) $(PARALLEL_MAKE) -C $(1)
75endef
76
77$(foreach dir,$(SUBDIRS), \
78 $(eval $(call DIR_Makefile_template,$(dir))) \
79 $(eval $(call DIR_compile_template,$(dir))) \
80 $(eval $(call DIR_clean_template,$(dir))) \
81 $(eval $(call DIR_all_template,$(dir))) \
82 )