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
|
|
|
|
2016-03-10 06:51:13 +08:00
|
|
|
CFLAGS += -O2 -c -std=gnu11 \
|
2015-05-15 05:44:48 +08:00
|
|
|
-D_GNU_SOURCE \
|
2016-03-09 01:22:50 +08:00
|
|
|
-fstack-protector-all -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-26 10:15:45 +08:00
|
|
|
-Ikafel/include \
|
|
|
|
-Iprotobuf-c-text/protobuf-c-text
|
2015-05-15 05:44:48 +08:00
|
|
|
|
2016-03-09 08:11:05 +08:00
|
|
|
LDFLAGS += -Wl,-z,now -Wl,-z,relro -pie -Wl,-z,noexecstack
|
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-05-26 07:44:16 +08:00
|
|
|
SRCS = nsjail.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
|
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)
|
|
|
|
PROTOBUF_EXISTS := $(shell pkg-config --exists protobuf && echo yes)
|
|
|
|
ifeq ($(PROTOBUF_EXISTS), 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-26 10:15:45 +08:00
|
|
|
CFLAGS += -DNSJAIL_WITH_PROTOBUF $(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)
|
2016-03-01 05:12:01 +08:00
|
|
|
endif
|
2016-11-21 06:37:38 +08:00
|
|
|
endif
|
2016-03-01 05:12:01 +08:00
|
|
|
|
2017-05-26 10:15:45 +08:00
|
|
|
.PHONY: all clear depend indent kafel protobuf-c-text
|
2017-05-16 01:39:12 +08:00
|
|
|
|
2015-05-15 05:44:48 +08:00
|
|
|
.c.o: %.c
|
|
|
|
$(CC) $(CFLAGS) $< -o $@
|
|
|
|
|
2017-05-26 10:15:45 +08:00
|
|
|
all: $(PROTO_DEPS) protobuf-c-text kafel $(BIN)
|
2015-05-15 05:44:48 +08:00
|
|
|
|
2016-09-13 18:10:15 +08:00
|
|
|
$(BIN): $(OBJS) $(LIBS)
|
|
|
|
$(CC) -o $(BIN) $(OBJS) $(LIBS) $(LDFLAGS)
|
|
|
|
|
2017-05-16 01:39:12 +08:00
|
|
|
kafel:
|
|
|
|
ifeq ("$(wildcard kafel/Makefile)","")
|
|
|
|
git submodule update --init
|
|
|
|
endif
|
|
|
|
|
2017-05-26 10:15:45 +08:00
|
|
|
protobuf-c-text:
|
|
|
|
ifeq ("$(wildcard protobuf-c-text/configure)","")
|
|
|
|
git submodule update --init
|
|
|
|
endif
|
|
|
|
|
2016-09-13 18:10:15 +08:00
|
|
|
kafel/libkafel.a:
|
|
|
|
$(MAKE) -C kafel
|
2015-05-15 05:44:48 +08:00
|
|
|
|
2017-05-26 10:15:45 +08:00
|
|
|
protobuf-c-text/protobuf-c-text/.libs/libprotobuf-c-text.a:
|
|
|
|
sh -c "cd protobuf-c-text; ./autogen.sh;"
|
|
|
|
$(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:
|
|
|
|
$(RM) core Makefile.bak $(OBJS) $(BIN)
|
2016-09-13 18:10:15 +08:00
|
|
|
$(MAKE) -C kafel clean
|
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.
|
|
|
|
|
2016-03-03 22:37:04 +08:00
|
|
|
nsjail.o: nsjail.h common.h cmdline.h log.h net.h subproc.h
|
2017-05-27 05:07:47 +08:00
|
|
|
cmdline.o: cmdline.h common.h config.h log.h mount.h util.h user.h
|
2017-05-26 08:25:37 +08:00
|
|
|
config.o: common.h config.h log.h util.h
|
2017-02-08 01:31:50 +08:00
|
|
|
contain.o: contain.h common.h cgroup.h log.h mount.h net.h pid.h user.h
|
|
|
|
contain.o: 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-05-26 10:25:55 +08:00
|
|
|
config.pb-c.o: config.pb-c.h
|