2015-05-15 05:44:48 +08:00
|
|
|
#
|
|
|
|
# nsjail - Makefile
|
2016-03-09 07:56:20 +08:00
|
|
|
# -----------------------------------------
|
2015-05-15 05:44:48 +08:00
|
|
|
#
|
|
|
|
# Copyright 2014 Google Inc. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
|
2016-03-01 02:09:39 +08:00
|
|
|
CC ?= gcc
|
2016-03-09 01:22:50 +08:00
|
|
|
|
2017-05-29 00:46:38 +08:00
|
|
|
EXTRA_CFLAGS := $(CFLAGS)
|
|
|
|
|
2016-03-10 06:51:13 +08:00
|
|
|
CFLAGS += -O2 -c -std=gnu11 \
|
2015-05-15 05:44:48 +08:00
|
|
|
-D_GNU_SOURCE \
|
2017-05-29 00:37:50 +08:00
|
|
|
-Wformat -Wformat=2 -Wformat-security -fPIE \
|
2017-02-08 07:36:32 +08:00
|
|
|
-Wno-format-nonliteral \
|
2017-05-08 21:50:29 +08:00
|
|
|
-Wall -Wextra -Werror \
|
2017-05-29 22:22:31 +08:00
|
|
|
-Ikafel/include
|
2015-05-15 05:44:48 +08:00
|
|
|
|
2017-07-05 19:03:14 +08:00
|
|
|
LDFLAGS += -Wl,-z,now -Wl,-z,relro -pie -Wl,-z,noexecstack -lpthread -lcap
|
2016-03-09 01:22:50 +08:00
|
|
|
|
2017-05-26 10:15:45 +08:00
|
|
|
BIN = nsjail
|
2017-05-26 10:25:55 +08:00
|
|
|
LIBS = kafel/libkafel.a
|
2017-07-05 19:03:14 +08:00
|
|
|
SRCS = nsjail.c caps.c cmdline.c config.c contain.c log.c cgroup.c mount.c net.c pid.c sandbox.c subproc.c user.c util.c uts.c cpu.c
|
2016-03-10 06:51:13 +08:00
|
|
|
OBJS = $(SRCS:.c=.o)
|
|
|
|
|
|
|
|
ifdef DEBUG
|
|
|
|
CFLAGS += -g -ggdb -gdwarf-4
|
|
|
|
endif
|
2016-03-09 01:49:06 +08:00
|
|
|
|
2017-02-14 05:59:24 +08:00
|
|
|
USE_NL3 ?= yes
|
2016-11-21 06:37:38 +08:00
|
|
|
ifeq ($(USE_NL3), yes)
|
2017-05-26 07:22:29 +08:00
|
|
|
NL3_EXISTS := $(shell pkg-config --exists libnl-route-3.0 && echo yes)
|
|
|
|
ifeq ($(NL3_EXISTS), yes)
|
|
|
|
CFLAGS += -DNSJAIL_NL3_WITH_MACVLAN $(shell pkg-config --cflags libnl-route-3.0)
|
|
|
|
LDFLAGS += $(shell pkg-config --libs libnl-route-3.0)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2017-05-26 10:15:45 +08:00
|
|
|
USE_PROTOBUF ?= yes
|
|
|
|
ifeq ($(USE_PROTOBUF), yes)
|
2017-05-29 22:22:31 +08:00
|
|
|
ifeq ("$(shell which protoc-c)", "")
|
|
|
|
USE_PROTOBUF := no
|
|
|
|
PROTOC_WARNING := yes
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(USE_PROTOBUF), no)
|
|
|
|
else ifeq ($(shell pkg-config --exists libprotobuf-c && echo yes), yes)
|
2017-05-26 07:55:02 +08:00
|
|
|
PROTO_DEPS = config.pb-c.h config.pb-c.c
|
|
|
|
SRCS += config.pb-c.c
|
2017-05-29 22:22:31 +08:00
|
|
|
CFLAGS += -DNSJAIL_WITH_PROTOBUF -Iprotobuf-c-text/protobuf-c-text $(shell pkg-config --cflags libprotobuf-c)
|
2017-05-26 10:25:55 +08:00
|
|
|
LIBS += protobuf-c-text/protobuf-c-text/.libs/libprotobuf-c-text.a
|
2017-05-26 07:22:29 +08:00
|
|
|
LDFLAGS += $(shell pkg-config --libs libprotobuf-c)
|
2017-05-29 22:22:31 +08:00
|
|
|
else ifneq ("$(wildcard /usr/include/google/protobuf-c/protobuf-c.h)", "")
|
|
|
|
PROTO_DEPS = config.pb-c.h config.pb-c.c
|
|
|
|
SRCS += config.pb-c.c
|
|
|
|
CFLAGS += -DNSJAIL_WITH_PROTOBUF -Iprotobuf-c-text/protobuf-c-text -I/usr/include/google
|
|
|
|
LIBS += protobuf-c-text/protobuf-c-text/.libs/libprotobuf-c-text.a
|
|
|
|
LDFLAGS += -Wl,-lprotobuf-c
|
|
|
|
else ifneq ("$(wildcard /usr/local/include/google/protobuf-c/protobuf-c.h)", "")
|
|
|
|
PROTO_DEPS = config.pb-c.h config.pb-c.c
|
|
|
|
SRCS += config.pb-c.c
|
|
|
|
CFLAGS += -DNSJAIL_WITH_PROTOBUF -Iprotobuf-c-text/protobuf-c-text -I/usr/local/include/google
|
|
|
|
LIBS += protobuf-c-text/protobuf-c-text/.libs/libprotobuf-c-text.a
|
|
|
|
LDFLAGS += -Wl,--library-path=/usr/local/lib -Wl,-lprotobuf-c
|
|
|
|
else
|
|
|
|
USE_PROTOBUF := no
|
2016-03-01 05:12:01 +08:00
|
|
|
endif
|
2017-05-27 08:31:11 +08:00
|
|
|
|
2017-05-29 06:29:52 +08:00
|
|
|
.PHONY: all clear depend indent
|
2017-05-16 01:39:12 +08:00
|
|
|
|
2015-05-15 05:44:48 +08:00
|
|
|
.c.o: %.c
|
|
|
|
$(CC) $(CFLAGS) $< -o $@
|
|
|
|
|
2017-05-29 06:29:52 +08:00
|
|
|
all: $(PROTO_DEPS) $(BIN)
|
2017-05-29 22:22:31 +08:00
|
|
|
ifeq ($(PROTOC_WARNING), yes)
|
|
|
|
$(info *********************************************************)
|
|
|
|
$(info * 'protoc-c' is missing on your system *)
|
|
|
|
$(info * Install 'protobuf-c-compiler' or a similar package *)
|
|
|
|
$(info *********************************************************)
|
|
|
|
endif
|
|
|
|
ifeq ($(USE_PROTOBUF), no)
|
2017-05-27 08:31:11 +08:00
|
|
|
$(info *********************************************************)
|
|
|
|
$(info * Code compiled without libprotobuf-c/libprotobuf-c-dev *)
|
|
|
|
$(info * The --config commandline option will be unavailable *)
|
|
|
|
$(info *********************************************************)
|
|
|
|
endif
|
2015-05-15 05:44:48 +08:00
|
|
|
|
2017-05-29 06:29:52 +08:00
|
|
|
$(BIN): $(LIBS) $(OBJS)
|
2016-09-13 18:10:15 +08:00
|
|
|
$(CC) -o $(BIN) $(OBJS) $(LIBS) $(LDFLAGS)
|
|
|
|
|
2017-05-29 06:29:52 +08:00
|
|
|
kafel/libkafel.a:
|
2017-05-16 01:39:12 +08:00
|
|
|
ifeq ("$(wildcard kafel/Makefile)","")
|
|
|
|
git submodule update --init
|
|
|
|
endif
|
2017-05-29 06:29:52 +08:00
|
|
|
$(MAKE) -C kafel
|
2017-05-16 01:39:12 +08:00
|
|
|
|
2017-05-29 06:29:52 +08:00
|
|
|
protobuf-c-text/protobuf-c-text/.libs/libprotobuf-c-text.a:
|
2017-05-26 10:15:45 +08:00
|
|
|
ifeq ("$(wildcard protobuf-c-text/configure)","")
|
|
|
|
git submodule update --init
|
2017-05-29 21:29:21 +08:00
|
|
|
endif
|
|
|
|
ifeq ("$(wildcard protobuf-c-text/Makefile)","")
|
|
|
|
sh -c "cd protobuf-c-text; CFLAGS=\"-fPIC -I/usr/include/google $(EXTRA_CFLAGS)\" ./autogen.sh --enable-shared=no --disable-doxygen-doc;"
|
2017-05-26 10:15:45 +08:00
|
|
|
endif
|
|
|
|
$(MAKE) -C protobuf-c-text
|
|
|
|
|
2017-05-26 07:55:02 +08:00
|
|
|
$(PROTO_DEPS): config.proto
|
|
|
|
protoc-c --c_out=. config.proto
|
|
|
|
|
2015-05-15 05:44:48 +08:00
|
|
|
clean:
|
2017-05-29 23:00:19 +08:00
|
|
|
$(RM) core Makefile.bak $(OBJS) $(BIN) $(PROTO_DEPS)
|
2017-05-27 08:32:39 +08:00
|
|
|
ifneq ("$(wildcard kafel/Makefile)","")
|
2016-09-13 18:10:15 +08:00
|
|
|
$(MAKE) -C kafel clean
|
2017-05-27 08:32:39 +08:00
|
|
|
endif
|
2017-05-29 00:58:47 +08:00
|
|
|
ifneq ("$(wildcard protobuf-c-text/Makefile)","")
|
|
|
|
$(MAKE) -C protobuf-c-text clean
|
|
|
|
endif
|
2015-05-15 05:44:48 +08:00
|
|
|
|
|
|
|
depend:
|
2017-05-08 21:50:29 +08:00
|
|
|
makedepend -Y -Ykafel/include -- -- $(SRCS)
|
2015-05-15 05:44:48 +08:00
|
|
|
|
|
|
|
indent:
|
2017-01-09 19:49:30 +08:00
|
|
|
indent -linux -l100 -lc100 *.c *.h; rm -f *~
|
2015-05-15 05:44:48 +08:00
|
|
|
|
|
|
|
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
|
|
|
|
2017-07-05 19:03:14 +08:00
|
|
|
nsjail.o: nsjail.h common.h caps.h cmdline.h log.h net.h subproc.h util.h
|
2017-07-06 17:37:41 +08:00
|
|
|
caps.o: caps.h common.h log.h util.h
|
2017-07-05 19:03:14 +08:00
|
|
|
cmdline.o: cmdline.h common.h caps.h config.h log.h mount.h util.h user.h
|
2017-07-06 07:12:13 +08:00
|
|
|
config.o: common.h caps.h config.h log.h mount.h user.h util.h
|
2017-07-05 19:03:14 +08:00
|
|
|
contain.o: contain.h common.h caps.h cgroup.h cpu.h log.h mount.h net.h pid.h
|
|
|
|
contain.o: user.h util.h uts.h
|
2015-05-15 05:44:48 +08:00
|
|
|
log.o: log.h common.h
|
2016-06-19 19:54:36 +08:00
|
|
|
cgroup.o: cgroup.h common.h log.h util.h
|
2016-11-03 10:53:52 +08:00
|
|
|
mount.o: mount.h common.h log.h subproc.h util.h
|
2016-10-18 04:53:31 +08:00
|
|
|
net.o: net.h common.h log.h subproc.h
|
|
|
|
pid.o: pid.h common.h log.h subproc.h
|
2017-05-09 00:40:21 +08:00
|
|
|
sandbox.o: sandbox.h common.h kafel/include/kafel.h log.h
|
2016-06-19 21:50:25 +08:00
|
|
|
subproc.o: subproc.h common.h cgroup.h contain.h log.h net.h sandbox.h user.h
|
|
|
|
subproc.o: util.h
|
2016-10-18 04:53:31 +08:00
|
|
|
user.o: user.h common.h log.h subproc.h util.h
|
2016-03-03 22:37:04 +08:00
|
|
|
util.o: util.h common.h log.h
|
2016-03-03 23:09:25 +08:00
|
|
|
uts.o: uts.h common.h log.h
|
2017-06-19 23:01:50 +08:00
|
|
|
cpu.o: cpu.h common.h log.h util.h
|