[CRIU] [PATCH 23/24] compel cli: add libs command, use it

Kir Kolyshkin kir at virtuozzo.com
Mon Dec 19 19:06:06 PST 2016


On 12/19/2016 02:34 AM, Pavel Emelyanov wrote:
> On 12/17/2016 02:22 PM, Kir Kolyshkin wrote:
>> Add "compel libs" that prints the list of libraries needed
>> to link the parasite loader.
> O_o  What else other than libcompel.(a|so) will we have?

It's just one, but
- almost universally everywhere these commands/options are in plural
(the biggest example being pkg-config)
- who knows, maybe in 10 years we'll have two :)
>
>> Make compel/test/ and criu/ to use it.
>>
>> Signed-off-by: Kir Kolyshkin <kir at openvz.org>
>> ---
>>   compel/Makefile             |  3 +++
>>   compel/src/main.c           | 30 +++++++++++++++++++++++++++++-
>>   compel/test/infect/Makefile |  3 +--
>>   compel/test/rsys/Makefile   |  3 +--
>>   criu/Makefile               |  3 ++-
>>   5 files changed, 36 insertions(+), 6 deletions(-)
>>
>> diff --git a/compel/Makefile b/compel/Makefile
>> index 8920281..204e19f 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 42aa8e0..fe91d1f 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 e9b96dd..fa966ac 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 3c5ef5b..3babda1 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 a9b1e61..01b1d98 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
>>   
>>   #
>> @@ -64,7 +65,7 @@ PROGRAM-BUILTINS	+= criu/pie/pie.lib.a
>>   PROGRAM-BUILTINS	+= images/built-in.o
>>   PROGRAM-BUILTINS	+= $(obj)/built-in.o
>>   PROGRAM-BUILTINS	+= $(ARCH-LIB)
>> -PROGRAM-BUILTINS	+= compel/libcompel.a
>> +PROGRAM-BUILTINS	+= $(COMPEL_LIBS)
>>   PROGRAM-BUILTINS	+= soccr/libsoccr.a
>>   
>>   $(obj)/built-in.o: pie
>>



More information about the CRIU mailing list