diff --git a/compel/Makefile b/compel/Makefile index 8920281fb..204e19f0c 100644 --- a/compel/Makefile +++ b/compel/Makefile @@ -4,6 +4,9 @@ COMPEL_SO_VERSION := $(COMPEL_SO_VERSION_MAJOR)$(if $(COMPEL_SO_VERSION_MINOR),. COMPEL_SO_VERSION_CODE := $(shell expr $(COMPEL_SO_VERSION_MAJOR) \* 65536 \+ $(COMPEL_SO_VERSION_MINOR) \* 256 \+ $(COMPEL_SO_VERSION_SUBLEVEL)) ccflags-y += -DINCLUDEDIR=\"$(INCLUDEDIR)\" ccflags-y += -DLIBEXECDIR=\"$(LIBEXECDIR)\" +ccflags-y += -DLIBDIR=\"$(LIBDIR)\" +ccflags-y += -DSTATIC_LIB=\"$(LIBCOMPEL_A)\" +ccflags-y += -DDYN_LIB=\"$(LIBCOMPEL_SO).$(COMPEL_SO_VERSION_MAJOR)\" ccflags-y += -iquote compel/arch/$(ARCH)/src/lib/include ccflags-y += -iquote compel/include ccflags-y += -fno-strict-aliasing diff --git a/compel/src/main.c b/compel/src/main.c index 2d2351753..2bfb37f8c 100644 --- a/compel/src/main.c +++ b/compel/src/main.c @@ -121,6 +121,7 @@ static int usage(int rc) { fprintf(out, "Usage:\n" " compel [--compat] includes | cflags | ldflags | plugins\n" +" compel [--compat] [--static] libs\n" " compel -f FILE -o FILE -p NAME [-l N] hgen\n" " -f, --file FILE input (parasite object) file name\n" " -o, --output FILE output (header) file name\n" @@ -194,17 +195,37 @@ static void print_plugins(const char *list[]) } } +static int print_libs(bool is_static) +{ + if (uninst_root) { + if (!is_static) { + fprintf(stderr, "Compel is not installed, can " + "only link with static libraries " + "(use --static)\n"); + return 1; + } + printf("%s/%s\n", uninst_root, STATIC_LIB); + } + else { + printf("%s/%s\n", LIBDIR, (is_static) ? STATIC_LIB : DYN_LIB); + } + + return 0; +} + int main(int argc, char *argv[]) { int log_level = DEFAULT_LOGLEVEL; bool compat = false; + bool is_static = false; int opt, idx; char *action; const char *plugins_list[] = { "std", NULL }; - static const char short_opts[] = "cf:o:p:hVl:"; + static const char short_opts[] = "csf:o:p:hVl:"; static struct option long_opts[] = { { "compat", no_argument, 0, 'c' }, + { "static", no_argument, 0, 's' }, { "file", required_argument, 0, 'f' }, { "output", required_argument, 0, 'o' }, { "prefix", required_argument, 0, 'p' }, @@ -225,6 +246,9 @@ int main(int argc, char *argv[]) case 'c': compat = true; break; + case 's': + is_static = true; + break; case 'f': opts.input_filename = optarg; break; @@ -280,6 +304,10 @@ int main(int argc, char *argv[]) return 0; } + if (!strcmp(action, "libs")) { + return print_libs(is_static); + } + if (!strcmp(action, "hgen")) { if (!opts.input_filename) { fprintf(stderr, "Error: option --file required\n"); diff --git a/compel/test/infect/Makefile b/compel/test/infect/Makefile index e9b96ddfd..fa966ac75 100644 --- a/compel/test/infect/Makefile +++ b/compel/test/infect/Makefile @@ -2,7 +2,6 @@ CC := gcc CFLAGS ?= -O2 -g -Wall -Werror COMPEL := ../../../compel/compel-host -COMPEL_LIBRARY := ../../../compel/libcompel.a all: victim spy @@ -17,7 +16,7 @@ victim: victim.c $(CC) $(CFLAGS) -o $@ $^ spy: spy.c parasite.h - $(CC) $(CFLAGS) $(shell $(COMPEL) includes) -o $@ $< $(COMPEL_LIBRARY) + $(CC) $(CFLAGS) $(shell $(COMPEL) includes) -o $@ $< $(shell $(COMPEL) --static libs) parasite.h: parasite.po $(COMPEL) hgen -f $^ -l 4 \ diff --git a/compel/test/rsys/Makefile b/compel/test/rsys/Makefile index 3c5ef5bba..3babda18f 100644 --- a/compel/test/rsys/Makefile +++ b/compel/test/rsys/Makefile @@ -2,7 +2,6 @@ CC := gcc CFLAGS ?= -O2 -g -Wall -Werror COMPEL := ../../../compel/compel-host -COMPEL_LIBRARY := ../../../compel/libcompel.a all: victim spy @@ -14,4 +13,4 @@ victim: victim.c $(CC) $(CFLAGS) -o $@ $^ spy: spy.c - $(CC) $(CFLAGS) $(shell $(COMPEL) includes) -o $@ $^ $(COMPEL_LIBRARY) + $(CC) $(CFLAGS) $(shell $(COMPEL) includes) -o $@ $^ $(shell $(COMPEL) --static libs) diff --git a/criu/Makefile b/criu/Makefile index c44d3b0a2..969716803 100644 --- a/criu/Makefile +++ b/criu/Makefile @@ -9,6 +9,7 @@ export ARCH_DIR PIE_DIR ifeq ($(filter clean mrproper,$(MAKECMDGOALS)),) COMPEL_UAPI_INCLUDES := $(shell $(COMPEL_BIN) includes) export COMPEL_UAPI_INCLUDES + COMPEL_LIBS := $(shell $(COMPEL_BIN) --static libs) endif # @@ -65,7 +66,7 @@ PROGRAM-BUILTINS += images/built-in.o PROGRAM-BUILTINS += $(obj)/built-in.o PROGRAM-BUILTINS += $(ARCH-LIB) PROGRAM-BUILTINS += soccr/libsoccr.a -PROGRAM-BUILTINS += compel/libcompel.a +PROGRAM-BUILTINS += $(COMPEL_LIBS) $(obj)/built-in.o: pie $(Q) $(MAKE) $(call build-as,Makefile.crtools,criu) all