• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (C) 2011 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
17CC        := gcc
18CXX       := g++
19STRIP     := strip
20BUILD_DIR := /tmp/ndk-$(USER)/build/build-ndk-stack
21PROGNAME  := /tmp/ndk-$(USER)/ndk-stack
22
23EXECUTABLE := $(PROGNAME)
24
25all: $(EXECUTABLE)
26
27# The rest should be left alone
28EXTRA_CFLAGS := -Wall
29EXTRA_LDFLAGS := -lstdc++
30
31ifneq (,$(strip $(DEBUG)))
32  CFLAGS += -O0 -g
33  hide = @
34  strip-cmd =
35else
36  CFLAGS += -O2 -s
37  hide =
38  strip-cmd = $(STRIP) $1
39endif
40
41BINUTILS_SOURCES := binutils/addr2line.c
42
43REGEX_SOURCES := regex/regcomp.c \
44                 regex/regerror.c \
45                 regex/regexec.c \
46                 regex/regfree.c
47
48NDK_STACK_SOURCES := ndk-stack.c \
49                     ndk-stack-parser.c
50
51SOURCES := $(NDK_STACK_SOURCES) $(BINUTILS_SOURCES) $(REGEX_SOURCES)
52
53OBJECTS=
54
55define build-c-object
56OBJECTS += $1
57$1: $2
58	mkdir -p $$(dir $1)
59	$$(CC) $$(CFLAGS) $$(EXTRA_CFLAGS) -c -o $1 $2
60endef
61
62define build-cxx-object
63OBJECTS += $1
64$1: $2
65	mkdir -p $$(dir $1)
66	$$(CXX) $$(CFLAGS) $$(EXTRA_CFLAGS) -c -o $1 $2
67endef
68
69$(foreach src,$(filter %.c,$(SOURCES)),\
70    $(eval $(call build-c-object,$(BUILD_DIR)/$(src:%.c=%.o),$(src)))\
71)
72
73$(foreach src,$(filter %.cc,$(SOURCES)),\
74    $(eval $(call build-cxx-object,$(BUILD_DIR)/$(src:%.cc=%.o),$(src)))\
75)
76
77clean:
78	rm -f $(EXECUTABLE)
79
80$(EXECUTABLE): $(OBJECTS)
81	$(CXX) $(OBJECTS) $(LDFLAGS) -o $@ $(EXTRA_LDFLAGS)
82	$(call strip-cmd,$@)
83