Update TestLoadUnload to use base Makefile.

Summary:
The current Makefile scheme only allows one dylib to be specified in each make
invocation, so TestLoadUnload had a custom Makefile that's unrelated to the
base Makefile.rules. This change uses recursive make invocations to bypass the
single dylib restriction. See D11202 for more context.

Reviewers: clayborg

Subscribers: chaoren, lldb-commits

Differential Revision: http://reviews.llvm.org/D11367

llvm-svn: 242813
This commit is contained in:
Chaoren Lin 2015-07-21 17:50:16 +00:00
parent fe5399fe88
commit 29449150e5
10 changed files with 91 additions and 82 deletions

View File

@ -1,84 +1,24 @@
CC ?= clang
ifeq "$(ARCH)" ""
ARCH = x86_64
endif
LEVEL := ../../make
ifeq "$(OS)" ""
OS = $(shell uname -s)
endif
LIB_PREFIX := loadunload_
CFLAGS ?= -g -O0
CWD := $(shell pwd)
LD_EXTRAS := -L. -l$(LIB_PREFIX)d -ldl
C_SOURCES := main.c
LIB_PREFIX := libloadunload_
include $(LEVEL)/Makefile.rules
ifeq "$(OS)" "Darwin"
CFLAGS += -arch $(ARCH)
DS := dsymutil
LD_FLAGS := -dynamiclib
LIB_A := $(LIB_PREFIX)a.dylib
LIB_B := $(LIB_PREFIX)b.dylib
LIB_C := $(LIB_PREFIX)c.dylib
LIB_D := $(LIB_PREFIX)d.dylib
EXEC_PATH := "@executable_path"
EXEC_PATH_A := -install_name $(EXEC_PATH)/$(LIB_A)
EXEC_PATH_B := -install_name $(EXEC_PATH)/$(LIB_B)
EXEC_PATH_C := -install_name $(EXEC_PATH)/$(LIB_C)
EXEC_PATH_D := -install_name $(CWD)/$(LIB_D)
.PHONY:
a.out: lib_a lib_b lib_c lib_d hidden_lib_d
DS_IF_DARWIN = $(DS) -o $@.dSYM $@
else
CFLAGS += -fPIC
LD_FLAGS := -shared
LIB_DL := -ldl
LIB_A := $(LIB_PREFIX)a.so
LIB_B := $(LIB_PREFIX)b.so
LIB_C := $(LIB_PREFIX)c.so
LIB_D := $(LIB_PREFIX)d.so
endif
lib_%:
$(MAKE) -f $*.mk
all: a.out $(LIB_A) $(LIB_B) $(LIB_C) $(LIB_D) hidden/$(LIB_D)
hidden_lib_d:
$(MAKE) -C hidden
a.out: main.o $(LIB_D)
$(CC) $(CFLAGS) -o a.out main.o -L. -pie -lloadunload_d $(LIB_DL)
main.o: main.c
$(CC) $(CFLAGS) -c main.c
hidden/$(LIB_D): dh.o
$(CC) $(CFLAGS) $(LD_FLAGS) -o hidden/$(LIB_D) dh.o
$(DS_IF_DARWIN)
$(LIB_A): a.o $(LIB_B)
$(CC) $(CFLAGS) $(LD_FLAGS) $(EXEC_PATH_A) -o $(LIB_A) a.o -L. -lloadunload_b
$(DS_IF_DARWIN)
a.o: a.c
$(CC) $(CFLAGS) -c a.c
$(LIB_B): b.o
$(CC) $(CFLAGS) $(LD_FLAGS) $(EXEC_PATH_B) -o $(LIB_B) b.o
$(DS_IF_DARWIN)
b.o: b.c
$(CC) $(CFLAGS) -c b.c
$(LIB_C): c.o
$(CC) $(CFLAGS) $(LD_FLAGS) $(EXEC_PATH_C) -o $(LIB_C) c.o
$(DS_IF_DARWIN)
c.o: c.c
$(CC) $(CFLAGS) -c c.c
$(LIB_D): d.o
$(CC) $(CFLAGS) $(LD_FLAGS) $(EXEC_PATH_D) -o $(LIB_D) d.o
$(DS_IF_DARWIN)
d.o: d.c
$(CC) $(CFLAGS) -c d.c
dh.o: d.c
$(CC) $(CFLAGS) -DHIDDEN -c d.c -o dh.o
clean:
rm -rf $(wildcard *.o *~ *.dylib *.so a.out *.dSYM hidden/*)
clean::
$(MAKE) -f a.mk clean
$(MAKE) -f b.mk clean
$(MAKE) -f c.mk clean
$(MAKE) -f d.mk clean
$(MAKE) -C hidden clean

View File

@ -0,0 +1,21 @@
LEVEL := ../../make
LIB_PREFIX := loadunload_
CFLAGS_EXTRAS := -fPIC
LD_EXTRAS := -L. -l$(LIB_PREFIX)b
DYLIB_NAME := $(LIB_PREFIX)a
DYLIB_C_SOURCES := a.c
DYLIB_ONLY := YES
include $(LEVEL)/Makefile.rules
.PHONY:
$(DYLIB_FILENAME): lib_b
lib_b:
$(MAKE) -f b.mk
clean::
$(MAKE) -f b.mk clean

View File

@ -0,0 +1,9 @@
LEVEL := ../../make
LIB_PREFIX := loadunload_
DYLIB_NAME := $(LIB_PREFIX)b
DYLIB_C_SOURCES := b.c
DYLIB_ONLY := YES
include $(LEVEL)/Makefile.rules

View File

@ -0,0 +1,9 @@
LEVEL := ../../make
LIB_PREFIX := loadunload_
DYLIB_NAME := $(LIB_PREFIX)c
DYLIB_C_SOURCES := c.c
DYLIB_ONLY := YES
include $(LEVEL)/Makefile.rules

View File

@ -9,9 +9,5 @@
int
d_function ()
{ // Find this line number within d_dunction().
#ifdef HIDDEN
return 12345;
#else
return 700;
#endif
}

View File

@ -0,0 +1,11 @@
LEVEL := ../../make
LIB_PREFIX := loadunload_
DYLIB_EXECUTABLE_PATH := $(CURDIR)
DYLIB_NAME := $(LIB_PREFIX)d
DYLIB_C_SOURCES := d.c
DYLIB_ONLY := YES
include $(LEVEL)/Makefile.rules

View File

@ -0,0 +1,9 @@
LEVEL := ../../../make
LIB_PREFIX := loadunload_
DYLIB_NAME := $(LIB_PREFIX)d
DYLIB_C_SOURCES := d.c
DYLIB_ONLY := YES
include $(LEVEL)/Makefile.rules

View File

@ -0,0 +1,13 @@
//===-- c.c -----------------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int
d_function ()
{ // Find this line number within d_dunction().
return 12345;
}

View File

@ -200,6 +200,7 @@ EXE ?= a.out
ifneq "$(DYLIB_NAME)" ""
ifeq "$(OS)" "Darwin"
DYLIB_FILENAME = lib$(DYLIB_NAME).dylib
DYLIB_EXECUTABLE_PATH ?= @executable_path
else ifeq "$(OS)" "Windows_NT"
DYLIB_FILENAME = $(DYLIB_NAME).dll
else
@ -452,7 +453,7 @@ $(DYLIB_OBJECTS) : CFLAGS += -DCOMPILING_LLDB_TEST_DLL
$(DYLIB_FILENAME) : $(DYLIB_OBJECTS)
ifeq "$(OS)" "Darwin"
$(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -install_name "@executable_path/$(DYLIB_FILENAME)" -dynamiclib -o "$(DYLIB_FILENAME)"
$(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -install_name "$(DYLIB_EXECUTABLE_PATH)/$(DYLIB_FILENAME)" -dynamiclib -o "$(DYLIB_FILENAME)"
ifneq "$(MAKE_DSYM)" "NO"
ifneq "$(DS)" ""
"$(DS)" $(DSFLAGS) "$(DYLIB_FILENAME)"