1 # Copyright (C) 2013 The Android Open Source Project 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 # 15 16 # The following variables can be over-ridden by the caller 17 CC := gcc 18 CXX := g++ 19 STRIP := strip 20 BUILD_DIR := /tmp/ndk-$(USER)/build/build-ndk-depends 21 PROGNAME := /tmp/ndk-$(USER)/ndk-depends 22 23 EXECUTABLE := $(PROGNAME) 24 25 all: $(EXECUTABLE) 26 27 # The rest should be left alone 28 EXTRA_CFLAGS := -Wall -Werror -fno-exceptions -fno-rtti 29 EXTRA_LDFLAGS := -lstdc++ 30 31 ifneq (,$(strip $(DEBUG))) 32 CFLAGS += -O0 -g 33 hide = @ 34 strip-cmd = 35 else 36 CFLAGS += -O2 -s 37 hide = 38 strip-cmd = $(STRIP) $1 39 endif 40 41 SOURCES := ndk-depends.cc 42 43 OBJECTS= 44 45 define build-c-object 46 OBJECTS += $1 47 $1: $2 48 mkdir -p $$(dir $1) 49 $$(CC) $$(CFLAGS) $$(EXTRA_CFLAGS) -c -o $1 $2 50 endef 51 52 define build-cxx-object 53 OBJECTS += $1 54 $1: $2 55 mkdir -p $$(dir $1) 56 $$(CXX) $$(CFLAGS) $$(EXTRA_CFLAGS) -c -o $1 $2 57 endef 58 59 $(foreach src,$(filter %.c,$(SOURCES)),\ 60 $(eval $(call build-c-object,$(BUILD_DIR)/$(src:%.c=%.o),$(src)))\ 61 ) 62 63 $(foreach src,$(filter %.cc,$(SOURCES)),\ 64 $(eval $(call build-cxx-object,$(BUILD_DIR)/$(src:%.cc=%.o),$(src)))\ 65 ) 66 67 clean: 68 rm -f $(EXECUTABLE) 69 70 $(EXECUTABLE): $(OBJECTS) 71 $(CXX) $(LDFLAGS) $(OBJECTS) -o $@ $(EXTRA_LDFLAGS) 72 $(call strip-cmd,$@) 73