llvm-project/lldb/test/make/Makefile.rules

161 lines
5.3 KiB
Makefile
Raw Normal View History

#----------------------------------------------------------------------
# Clients fill in the source files to build
#----------------------------------------------------------------------
# C_SOURCES := main.c
# CXX_SOURCES :=
# OBJC_SOURCES :=
# OBJCXX_SOURCES :=
# DYLIB_C_SOURCES :=
# Uncomment line below for debugging shell commands
# SHELL = /bin/sh -x
#----------------------------------------------------------------------
# If ARCH is not defined, default to x86_64.
#----------------------------------------------------------------------
ifeq "$(ARCH)" ""
ARCH = x86_64
endif
#----------------------------------------------------------------------
# Change any build/tool options needed
#----------------------------------------------------------------------
DS := /usr/bin/dsymutil
DSFLAGS =
CC = gcc
CFLAGS ?=-arch $(ARCH) -gdwarf-2 -O0
CPLUSPLUSFLAGS +=$(CFLAGS)
CPPFLAGS +=$(CFLAGS)
Extend the build mechanism to allow for specifying the compiler used to build the binaries. If the build* function is passed the compiler argument, for example, 'llvm-gcc', it is passed as a make variable to the make command. Otherwise, we check the LLDB_CC environment variable; if it is defined, it is passed as a make variable to the make command. If neither the compiler keyword argument nor the LLDB_CC environment variable is specified, no CC make variable is passed to the make command. The Makefile gets to define the default CC being used. -------------------------------------------------------------------------------- Example usage follows: o Via the keyword argument: class ArrayTypesTestCase(TestBase): mydir = "array_types" @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") def test_with_dsym_and_run_command(self): """Test 'frame variable var_name' on some variables with array types.""" self.buildDsym(compiler='llvm-gcc') self.array_types() ... o Via LLDB_CC environment variable: $ LLDB_CC=llvm-gcc ./dotest.py -v -t array_types ---------------------------------------------------------------------- Collected 4 tests test_with_dsym_and_python_api (TestArrayTypes.ArrayTypesTestCase) Use Python APIs to inspect variables with array types. ... os command: [['/bin/sh', '-c', 'make clean; make MAKE_DSYM=YES CC=llvm-gcc']] output: rm -rf "a.out" "a.out.dSYM" main.o main.d llvm-gcc -arch x86_64 -gdwarf-2 -O0 -arch x86_64 -gdwarf-2 -O0 -c -o main.o main.c llvm-gcc -arch x86_64 -gdwarf-2 -O0 main.o -o "a.out" /usr/bin/dsymutil -o "a.out.dSYM" "a.out" ... llvm-svn: 113781
2010-09-14 04:54:30 +08:00
LD = $(CC)
LDFLAGS ?= $(CFLAGS)
OBJECTS =
EXE = a.out
DSYM = $(EXE).dSYM
#----------------------------------------------------------------------
# dylib settings
#----------------------------------------------------------------------
ifneq "$(strip $(DYLIB_C_SOURCES))" ""
DYLIB_OBJECTS +=$(strip $(DYLIB_C_SOURCES:.c=.o))
endif
#----------------------------------------------------------------------
# Check if we have any C source files
#----------------------------------------------------------------------
ifneq "$(strip $(C_SOURCES))" ""
OBJECTS +=$(strip $(C_SOURCES:.c=.o))
endif
#----------------------------------------------------------------------
# Check if we have any C++ source files
#----------------------------------------------------------------------
ifneq "$(strip $(CXX_SOURCES))" ""
OBJECTS +=$(strip $(CXX_SOURCES:.cpp=.o))
LD = g++
endif
#----------------------------------------------------------------------
# Check if we have any ObjC source files
#----------------------------------------------------------------------
ifneq "$(strip $(OBJC_SOURCES))" ""
OBJECTS +=$(strip $(OBJC_SOURCES:.m=.o))
LDFLAGS +=-lobjc
endif
#----------------------------------------------------------------------
# Check if we have any ObjC++ source files
#----------------------------------------------------------------------
ifneq "$(strip $(OBJCXX_SOURCES))" ""
OBJECTS +=$(strip $(OBJCXX_SOURCES:.mm=.o))
LD = g++
ifeq $(findstring lobjc,$(LDFLAGS)) ""
LDFLAGS +=-lobjc
endif
endif
#----------------------------------------------------------------------
# Make the dSYM file from the executable if $(MAKE_DSYM) != "NO"
#----------------------------------------------------------------------
ifneq "$(MAKE_DSYM)" "NO"
$(DSYM) : $(EXE)
$(DS) $(DSFLAGS) -o "$(DSYM)" "$(EXE)"
endif
#----------------------------------------------------------------------
# Compile the executable from all the objects.
#----------------------------------------------------------------------
ifeq "$(DYLIB_NAME)" ""
$(EXE) : $(OBJECTS)
$(LD) $(LDFLAGS) $(OBJECTS) -o "$(EXE)"
else
$(EXE) : $(OBJECTS) $(DYLIB_NAME)
$(LD) $(LDFLAGS) $(OBJECTS) -L. -l$(subst lib,,$(basename $(DYLIB_NAME))) -o "$(EXE)"
endif
#----------------------------------------------------------------------
# Make the dylib
#----------------------------------------------------------------------
$(DYLIB_NAME) : $(DYLIB_OBJECTS)
$(LD) $(LDFLAGS) $(DYLIB_OBJECTS) -install_name "@executable_path/$(DYLIB_NAME)" -dynamiclib -o "$(DYLIB_NAME)"
#----------------------------------------------------------------------
# Automatic variables based on items already entered. Below we create
# an objects lists from the list of sources by replacing all entries
# that end with .c with .o, and we also create a list of prerequisite
# files by replacing all .c files with .d.
#----------------------------------------------------------------------
PREREQS := $(OBJECTS:.o=.d)
ifneq "$(DYLIB_NAME)" ""
DYLIB_PREREQS := $(DYLIB_OBJECTS:.o=.d)
endif
#----------------------------------------------------------------------
# Rule for Generating Prerequisites Automatically using .d files and
# the compiler -MM option. The -M option will list all system headers,
# and the -MM option will list all non-system dependencies.
#----------------------------------------------------------------------
%.d: %.c
@set -e; rm -f $@; \
$(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
%.d: %.cpp
@set -e; rm -f $@; \
$(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
%.d: %.m
@set -e; rm -f $@; \
$(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
%.d: %.mm
@set -e; rm -f $@; \
$(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
#----------------------------------------------------------------------
# Include all of the makefiles for each source file so we don't have
# to manually track all of the prerequisites for each source file.
#----------------------------------------------------------------------
sinclude $(PREREQS)
ifneq "$(DYLIB_NAME)" ""
sinclude $(DYLIB_PREREQS)
endif
.PHONY: clean
dsym: $(DSYM)
all: $(EXE) $(DSYM)
clean::
ifeq "$(DYLIB_NAME)" ""
rm -rf "$(EXE)" "$(DSYM)" $(OBJECTS) $(PREREQS)
else
rm -rf "$(EXE)" "$(DSYM)" $(OBJECTS) $(PREREQS) $(DYLIB_OBJECTS) $(DYLIB_NAME) $(DYLIB_NAME).dSYM
endif