Commit 51c4569c authored by Kir Kolyshkin's avatar Kir Kolyshkin Committed by Andrei Vagin

compel cli: show includes

1. Add "compel includes" command, to be used for parasite *loading*
   code compilation.

2. Add includes to output of "compel cflags", which is used for parasite
   code compilation.

Now, this patch looks big and complex, this is mostly because we want
compel cli to work for both uninstalled (right from the source tree)
and installed cases. The paths to be printed are quite different for
these two cases, so I had to introduce a wrapper for a non-installed
case. The wrapper sets an environment variable, which compel binary
uses as a path to non-installed file. If this env var is not set,
it means compel is installed so no tricks are needed.

Note the wrapper is only provided for the compel-host binary, as compel
(which differs from compel-host in case of cross-compiling) is not
executed from within the source tree.

Because of the wrapper, the original binary had to be renamed, thus the
changes to Makefiles and .gitignore.

travis-ci: success for More polishing for compel cli
Signed-off-by: 's avatarKir Kolyshkin <kir@openvz.org>
Acked-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent f53189c5
......@@ -17,7 +17,7 @@ tags
TAGS
Makefile.local
compel/compel
compel/compel-host
compel/compel-host-bin
images/*.c
images/*.h
images/google/protobuf/*.c
......
......@@ -222,9 +222,9 @@ $(SOCCR_A): |soccr/built-in.o
#
# But note that we're already included
# the nmk so we can reuse it there.
criu/%: images/built-in.o compel/plugins/std.built-in.o compel/libcompel.a compel/compel-host $(VERSION_HEADER) .FORCE
criu/%: images/built-in.o compel/plugins/std.built-in.o compel/libcompel.a compel/compel-host-bin $(VERSION_HEADER) .FORCE
$(Q) $(MAKE) $(build)=criu $@
criu: images/built-in.o compel/plugins/std.built-in.o compel/libcompel.a compel/compel-host $(SOCCR_A) $(VERSION_HEADER)
criu: images/built-in.o compel/plugins/std.built-in.o compel/libcompel.a compel/compel-host-bin $(SOCCR_A) $(VERSION_HEADER)
$(Q) $(MAKE) $(build)=criu all
.PHONY: criu
......
......@@ -2,6 +2,7 @@ include $(SRC_DIR)/Makefile.versions
COMPEL_SO_VERSION := $(COMPEL_SO_VERSION_MAJOR)$(if $(COMPEL_SO_VERSION_MINOR),.$(COMPEL_SO_VERSION_MINOR))$(if $(COMPEL_SO_VERSION_SUBLEVEL),.$(COMPEL_SO_VERSION_SUBLEVEL))
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 += -iquote compel/arch/$(ARCH)/src/lib/include
ccflags-y += -iquote compel/include
ccflags-y += -iquote compel/plugins/include
......@@ -45,8 +46,8 @@ endif
host-ccflags-y += $(ccflags-y)
hostprogs-y += compel-host
compel-host-objs := $(patsubst %.o,%-host.o,$(obj-y) $(host-lib-y))
hostprogs-y += compel-host-bin
compel-host-bin-objs := $(patsubst %.o,%-host.o,$(obj-y) $(host-lib-y))
ifeq ($(ARCH),x86)
HOSTCFLAGS_handle-elf-32-host.o += -UCONFIG_X86_64 -DCONFIG_X86_32
......@@ -54,7 +55,7 @@ HOSTCFLAGS_handle-elf-32-host.d += -UCONFIG_X86_64 -DCONFIG_X86_32
endif
cleanup-y += compel/compel
cleanup-y += compel/compel-host
cleanup-y += compel/compel-host-bin
cleanup-y += compel/libcompel.so
install: compel/compel compel/$(LIBCOMPEL_SO) compel/$(LIBCOMPEL_A)
......
#!/bin/sh
#
# A wrapper to use compel-host right from the source dir
# (i.e. when it is not yet installed).
COMPEL_UNINSTALLED_ROOTDIR=$(dirname "$0")
export COMPEL_UNINSTALLED_ROOTDIR
exec "${COMPEL_UNINSTALLED_ROOTDIR}/compel-host-bin" "$@"
......@@ -48,6 +48,7 @@ static const flags_t flags = {
};
piegen_opt_t opts = {};
const char *uninst_root;
static int piegen(void)
{
......@@ -114,7 +115,7 @@ static int usage(int rc) {
fprintf(out,
"Usage:\n"
" compel [--compat] cflags | ldflags\n"
" compel [--compat] includes | cflags | ldflags\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"
......@@ -128,9 +129,35 @@ static int usage(int rc) {
return rc;
}
static void print_includes(void)
{
int i;
/* list of standard include dirs (built into C preprocessor) */
const char *standard_includes[] = {
"/usr/include",
"/usr/local/include",
};
/* I am not installed, called via a wrapper */
if (uninst_root) {
printf("-I %s/include/uapi\n", uninst_root);
return;
}
/* I am installed
* Make sure to not print banalities */
for (i = 0; i < ARRAY_SIZE(standard_includes); i++)
if (strcmp(INCLUDEDIR, standard_includes[i]) == 0)
return;
/* Finally, print our non-standard include path */
printf("%s\n", "-I " INCLUDEDIR);
}
static void print_cflags(bool compat)
{
printf("%s\n", compat ? flags.cflags_compat : flags.cflags);
print_includes();
}
int main(int argc, char *argv[])
......@@ -152,6 +179,8 @@ int main(int argc, char *argv[])
{ },
};
uninst_root = getenv("COMPEL_UNINSTALLED_ROOTDIR");
while (1) {
idx = -1;
opt = getopt_long(argc, argv, short_opts, long_opts, &idx);
......@@ -195,6 +224,10 @@ int main(int argc, char *argv[])
}
action = argv[optind++];
if (!strcmp(action, "includes")) {
print_includes();
return 0;
}
if (!strcmp(action, "cflags")) {
print_cflags(compat);
return 0;
......
......@@ -3,7 +3,6 @@ CFLAGS ?= -O2 -g -Wall -Werror
ARCH ?= x86
COMPEL := ../../../compel/compel-host
COMPEL_IDIR := ../../../compel/include/uapi
COMPEL_PACK_LDS := ../../../compel/arch/$(ARCH)/scripts/compel-pack.lds.S
COMPEL_PLUGINS := ../../../compel/plugins
COMPEL_LIBRARY := ../../../compel/libcompel.a
......@@ -21,7 +20,7 @@ victim: victim.c
$(CC) $(CFLAGS) -o $@ $^
spy: spy.c | parasite.h
$(CC) $(CFLAGS) -I$(COMPEL_IDIR) -o $@ $^ $(COMPEL_LIBRARY)
$(CC) $(CFLAGS) $(shell $(COMPEL) includes) -o $@ $^ $(COMPEL_LIBRARY)
parasite.h: parasite.po
$(COMPEL) hgen -f $^ -l 4 \
......@@ -32,4 +31,4 @@ parasite.po: parasite.o $(COMPEL_PLUGINS)/std.built-in.o
ld -r -T $(COMPEL_PACK_LDS) -o $@ $^
parasite.o: parasite.c
$(CC) $(CFLAGS) -c $(shell $(COMPEL) cflags) -I$(COMPEL_IDIR) -o $@ $^
$(CC) $(CFLAGS) -c $(shell $(COMPEL) cflags) -o $@ $^
CC := gcc
CFLAGS ?= -O2 -g -Wall -Werror
COMPEL_IDIR := ../../../compel/include/uapi
COMPEL := ../../../compel/compel-host
COMPEL_LIBRARY := ../../../compel/libcompel.a
all: victim spy
......@@ -14,4 +14,4 @@ victim: victim.c
$(CC) $(CFLAGS) -o $@ $^
spy: spy.c
$(CC) $(CFLAGS) -I$(COMPEL_IDIR) -o $@ $^ $(COMPEL_LIBRARY)
$(CC) $(CFLAGS) $(shell $(COMPEL) includes) -o $@ $^ $(COMPEL_LIBRARY)
......@@ -62,7 +62,7 @@ $(obj)/%.built-in.bin.o: $(obj)/%.built-in.o $(obj)/pie.lib.a $(compel_lds)
$(call msg-gen, $@)
$(Q) $(LD) -r -T $(compel_lds) -o $@ $< $(obj)/pie.lib.a
$(obj)/%-blob.h: $(obj)/%.built-in.bin.o $(SRC_DIR)/compel/compel-host
$(obj)/%-blob.h: $(obj)/%.built-in.bin.o $(SRC_DIR)/compel/compel-host-bin
$(call msg-gen, $@)
$(Q) $(SRC_DIR)/compel/compel-host hgen -f $< \
-l 4 \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment