diff --git a/.gitignore b/.gitignore index c3f82939d..f54248c6a 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/Makefile b/Makefile index e06731eec..630b650af 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/compel/Makefile b/compel/Makefile index b2000386e..ef932fe46 100644 --- a/compel/Makefile +++ b/compel/Makefile @@ -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) diff --git a/compel/compel-host b/compel/compel-host new file mode 100755 index 000000000..bf78862bb --- /dev/null +++ b/compel/compel-host @@ -0,0 +1,8 @@ +#!/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" "$@" diff --git a/compel/src/main.c b/compel/src/main.c index c943febd1..f91fe2729 100644 --- a/compel/src/main.c +++ b/compel/src/main.c @@ -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; diff --git a/compel/test/infect/Makefile b/compel/test/infect/Makefile index ede9a474d..8d35c2967 100644 --- a/compel/test/infect/Makefile +++ b/compel/test/infect/Makefile @@ -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 $@ $^ diff --git a/compel/test/rsys/Makefile b/compel/test/rsys/Makefile index a4fda54fa..3c5ef5bba 100644 --- a/compel/test/rsys/Makefile +++ b/compel/test/rsys/Makefile @@ -1,7 +1,7 @@ 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) diff --git a/criu/pie/Makefile b/criu/pie/Makefile index 9ae488c89..1649a2987 100644 --- a/criu/pie/Makefile +++ b/criu/pie/Makefile @@ -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 \