<commit_before>#
#   nsjail - Makefile
#   -----------------------------------------
#
#   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.
#

CC ?= gcc

EXTRA_CFLAGS := $(CFLAGS)

CFLAGS += -O2 -c -std=gnu11 \
	-D_GNU_SOURCE \
	-Wformat -Wformat=2 -Wformat-security -fPIE \
	-Wno-format-nonliteral \
	-Wall -Wextra -Werror \
	-Ikafel/include \
	-Iprotobuf-c-text/protobuf-c-text 

LDFLAGS += -Wl,-z,now -Wl,-z,relro -pie -Wl,-z,noexecstack

BIN = nsjail
LIBS = kafel/libkafel.a
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
OBJS = $(SRCS:.c=.o)

ifdef DEBUG
	CFLAGS += -g -ggdb -gdwarf-4
endif

USE_NL3 ?= yes
ifeq ($(USE_NL3), yes)
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

USE_PROTOBUF ?= yes
ifeq ($(USE_PROTOBUF), yes)
PROTOBUF_EXISTS := $(shell pkg-config --exists libprotobuf-c && echo yes)
ifeq ($(PROTOBUF_EXISTS), yes)
	PROTO_DEPS = config.pb-c.h config.pb-c.c
	SRCS += config.pb-c.c
	CFLAGS += -DNSJAIL_WITH_PROTOBUF $(shell pkg-config --cflags libprotobuf-c)
	LIBS += protobuf-c-text/protobuf-c-text/.libs/libprotobuf-c-text.a
	LDFLAGS += $(shell pkg-config --libs libprotobuf-c)
endif
endif


.PHONY: all clear depend indent

.c.o: %.c
	$(CC) $(CFLAGS) $< -o $@

all: $(PROTO_DEPS) $(BIN)
ifneq ($(PROTOBUF_EXISTS), yes)
	$(info *********************************************************)
	$(info * Code compiled without libprotobuf-c/libprotobuf-c-dev *)
	$(info *  The --config commandline option will be unavailable  *)
	$(info *********************************************************)
endif

$(BIN): $(LIBS) $(OBJS)
	$(CC) -o $(BIN) $(OBJS) $(LIBS) $(LDFLAGS)

kafel/libkafel.a:
ifeq ("$(wildcard kafel/Makefile)","")
	git submodule update --init
endif
	$(MAKE) -C kafel

protobuf-c-text/protobuf-c-text/.libs/libprotobuf-c-text.a:
ifeq ("$(wildcard protobuf-c-text/configure)","")
	git submodule update --init
	sh -c "cd protobuf-c-text; CFLAGS=\"-fPIC $(EXTRA_CFLAGS)\" ./autogen.sh --enable-shared=no --disable-doxygen-doc;"
endif
	$(MAKE) -C protobuf-c-text

$(PROTO_DEPS): config.proto
	protoc-c --c_out=. config.proto

clean:
	$(RM) core Makefile.bak $(OBJS) $(BIN)
ifneq ("$(wildcard kafel/Makefile)","")
	$(MAKE) -C kafel clean
endif
ifneq ("$(wildcard protobuf-c-text/Makefile)","")
	$(MAKE) -C protobuf-c-text clean
endif

depend:
	makedepend -Y -Ykafel/include -- -- $(SRCS)
<commit_msg>Better compilation rules for protobuf-c-text<commit_after>#
#   nsjail - Makefile
#   -----------------------------------------
#
#   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.
#

CC ?= gcc

EXTRA_CFLAGS := $(CFLAGS)

CFLAGS += -O2 -c -std=gnu11 \
	-D_GNU_SOURCE \
	-Wformat -Wformat=2 -Wformat-security -fPIE \
	-Wno-format-nonliteral \
	-Wall -Wextra -Werror \
	-Ikafel/include \
	-I/usr/include/google \
	-Iprotobuf-c-text/protobuf-c-text

LDFLAGS += -Wl,-z,now -Wl,-z,relro -pie -Wl,-z,noexecstack

BIN = nsjail
LIBS = kafel/libkafel.a
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
OBJS = $(SRCS:.c=.o)

ifdef DEBUG
	CFLAGS += -g -ggdb -gdwarf-4
endif

USE_NL3 ?= yes
ifeq ($(USE_NL3), yes)
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

USE_PROTOBUF ?= yes
ifeq ($(USE_PROTOBUF), yes)
PROTOBUF_EXISTS ?= $(shell pkg-config --exists libprotobuf-c && echo yes)
ifeq ($(PROTOBUF_EXISTS), yes)
	PROTO_DEPS = config.pb-c.h config.pb-c.c
	SRCS += config.pb-c.c
	CFLAGS += -DNSJAIL_WITH_PROTOBUF $(shell pkg-config --cflags libprotobuf-c)
	LIBS += protobuf-c-text/protobuf-c-text/.libs/libprotobuf-c-text.a
	LDFLAGS += $(shell pkg-config --libs libprotobuf-c)
endif
endif


.PHONY: all clear depend indent

.c.o: %.c
	$(CC) $(CFLAGS) $< -o $@

all: $(PROTO_DEPS) $(BIN)
ifneq ($(PROTOBUF_EXISTS), yes)
	$(info *********************************************************)
	$(info * Code compiled without libprotobuf-c/libprotobuf-c-dev *)
	$(info *  The --config commandline option will be unavailable  *)
	$(info *********************************************************)
endif

$(BIN): $(LIBS) $(OBJS)
	$(CC) -o $(BIN) $(OBJS) $(LIBS) $(LDFLAGS)

kafel/libkafel.a:
ifeq ("$(wildcard kafel/Makefile)","")
	git submodule update --init
endif
	$(MAKE) -C kafel

protobuf-c-text/protobuf-c-text/.libs/libprotobuf-c-text.a:
ifeq ("$(wildcard protobuf-c-text/configure)","")
	git submodule update --init
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;"
endif
	$(MAKE) -C protobuf-c-text

$(PROTO_DEPS): config.proto
	protoc-c --c_out=. config.proto

clean:
	$(RM) core Makefile.bak $(OBJS) $(BIN)
ifneq ("$(wildcard kafel/Makefile)","")
	$(MAKE) -C kafel clean
endif
ifneq ("$(wildcard protobuf-c-text/Makefile)","")
	$(MAKE) -C protobuf-c-text clean
endif

depend:
	makedepend -Y -Ykafel/include -- -- $(SRCS)

{'fraction_non_alphanumeric': 0.20117975783918038, 'fraction_numerical': 0.007451102142191866, 'mean_word_length': 3.6219512195121952, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '149603', 'n_tokens_mistral': 2462, 'n_tokens_neox': 2366, 'n_words': 628}