| 1 |
# Makefile - requires GNU make |
| 2 |
# |
| 3 |
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
# See https://llvm.org/LICENSE.txt for license information. |
| 5 |
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
|
| 7 |
srcdir = . |
| 8 |
prefix = /usr |
| 9 |
bindir = $(prefix)/bin |
| 10 |
libdir = $(prefix)/lib |
| 11 |
includedir = $(prefix)/include |
| 12 |
|
| 13 |
# Configure these in config.mk, do not make changes in this file. |
| 14 |
SUBS = math string networking |
| 15 |
HOST_CC = cc |
| 16 |
HOST_CFLAGS = -std=c99 -O2 |
| 17 |
HOST_LDFLAGS = |
| 18 |
HOST_LDLIBS = |
| 19 |
EMULATOR = |
| 20 |
CPPFLAGS = |
| 21 |
CFLAGS = -std=c99 -O2 |
| 22 |
CFLAGS_SHARED = -fPIC |
| 23 |
CFLAGS_ALL = -Ibuild/include $(CPPFLAGS) $(CFLAGS) |
| 24 |
LDFLAGS = |
| 25 |
LDLIBS = |
| 26 |
AR = $(CROSS_COMPILE)ar |
| 27 |
RANLIB = $(CROSS_COMPILE)ranlib |
| 28 |
INSTALL = install |
| 29 |
|
| 30 |
all: |
| 31 |
|
| 32 |
-include config.mk |
| 33 |
|
| 34 |
$(foreach sub,$(SUBS),$(eval include $(srcdir)/$(sub)/Dir.mk)) |
| 35 |
|
| 36 |
# Required targets of subproject foo: |
| 37 |
# all-foo |
| 38 |
# check-foo |
| 39 |
# clean-foo |
| 40 |
# install-foo |
| 41 |
# Required make variables of subproject foo: |
| 42 |
# foo-files: Built files (all in build/). |
| 43 |
# Make variables used by subproject foo: |
| 44 |
# foo-...: Variables defined in foo/Dir.mk or by config.mk. |
| 45 |
|
| 46 |
all: $(SUBS:%=all-%) |
| 47 |
|
| 48 |
ALL_FILES = $(foreach sub,$(SUBS),$($(sub)-files)) |
| 49 |
DIRS = $(sort $(patsubst %/,%,$(dir $(ALL_FILES)))) |
| 50 |
$(ALL_FILES): | $(DIRS) |
| 51 |
$(DIRS): |
| 52 |
mkdir -p $@ |
| 53 |
|
| 54 |
$(filter %.os,$(ALL_FILES)): CFLAGS_ALL += $(CFLAGS_SHARED) |
| 55 |
|
| 56 |
build/%.o: $(srcdir)/%.S |
| 57 |
$(CC) $(CFLAGS_ALL) -c -o $@ $< |
| 58 |
|
| 59 |
build/%.o: $(srcdir)/%.c |
| 60 |
$(CC) $(CFLAGS_ALL) -c -o $@ $< |
| 61 |
|
| 62 |
build/%.os: $(srcdir)/%.S |
| 63 |
$(CC) $(CFLAGS_ALL) -c -o $@ $< |
| 64 |
|
| 65 |
build/%.os: $(srcdir)/%.c |
| 66 |
$(CC) $(CFLAGS_ALL) -c -o $@ $< |
| 67 |
|
| 68 |
clean: $(SUBS:%=clean-%) |
| 69 |
rm -rf build |
| 70 |
|
| 71 |
distclean: clean |
| 72 |
rm -f config.mk |
| 73 |
|
| 74 |
$(DESTDIR)$(bindir)/%: build/bin/% |
| 75 |
$(INSTALL) -D $< $@ |
| 76 |
|
| 77 |
$(DESTDIR)$(libdir)/%.so: build/lib/%.so |
| 78 |
$(INSTALL) -D $< $@ |
| 79 |
|
| 80 |
$(DESTDIR)$(libdir)/%: build/lib/% |
| 81 |
$(INSTALL) -m 644 -D $< $@ |
| 82 |
|
| 83 |
$(DESTDIR)$(includedir)/%: build/include/% |
| 84 |
$(INSTALL) -m 644 -D $< $@ |
| 85 |
|
| 86 |
install: $(SUBS:%=install-%) |
| 87 |
|
| 88 |
check: $(SUBS:%=check-%) |
| 89 |
|
| 90 |
.PHONY: all clean distclean install check |