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 7srcdir = . 8prefix = /usr 9bindir = $(prefix)/bin 10libdir = $(prefix)/lib 11includedir = $(prefix)/include 12 13# Configure these in config.mk, do not make changes in this file. 14SUBS = math string networking 15HOST_CC = cc 16HOST_CFLAGS = -std=c99 -O2 17HOST_LDFLAGS = 18HOST_LDLIBS = 19EMULATOR = 20CPPFLAGS = 21CFLAGS = -std=c99 -O2 22CFLAGS_SHARED = -fPIC 23CFLAGS_ALL = -Ibuild/include $(CPPFLAGS) $(CFLAGS) 24LDFLAGS = 25LDLIBS = 26AR = $(CROSS_COMPILE)ar 27RANLIB = $(CROSS_COMPILE)ranlib 28INSTALL = install 29 30all: 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 46all: $(SUBS:%=all-%) 47 48ALL_FILES = $(foreach sub,$(SUBS),$($(sub)-files)) 49DIRS = $(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 56build/%.o: $(srcdir)/%.S 57 $(CC) $(CFLAGS_ALL) -c -o $@ $< 58 59build/%.o: $(srcdir)/%.c 60 $(CC) $(CFLAGS_ALL) -c -o $@ $< 61 62build/%.os: $(srcdir)/%.S 63 $(CC) $(CFLAGS_ALL) -c -o $@ $< 64 65build/%.os: $(srcdir)/%.c 66 $(CC) $(CFLAGS_ALL) -c -o $@ $< 67 68clean: $(SUBS:%=clean-%) 69 rm -rf build 70 71distclean: 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 86install: $(SUBS:%=install-%) 87 88check: $(SUBS:%=check-%) 89 90.PHONY: all clean distclean install check 91