youtubeUnblock/uspace.mk

136 lines
4.2 KiB
Makefile
Raw Permalink Normal View History

#Check for using system libs
USE_SYS_LIBS := no
2024-07-30 23:12:59 +00:00
#Userspace app makes here
BUILD_DIR := $(CURDIR)/build
DEPSDIR := $(BUILD_DIR)/deps
2024-09-21 19:13:32 +00:00
INCLUDE_DIR := $(CURDIR)/src
SRC_DIR := $(CURDIR)/src
2024-07-30 23:12:59 +00:00
2024-08-05 19:53:44 +00:00
CC:=gcc
CCLD:=$(CC)
LD:=ld
ifeq ($(USE_SYS_LIBS), no)
2024-12-01 15:24:30 +00:00
override CFLAGS += -I$(DEPSDIR)/include
override LDFLAGS += -L$(DEPSDIR)/lib
REQ = $(LIBNETFILTER_QUEUE) $(LIBMNL) $(LIBCRYPTO)
endif
2024-07-30 23:12:59 +00:00
2024-09-21 19:13:32 +00:00
override CFLAGS += -DPKG_VERSION=\"$(PKG_FULLVERSION)\" -I$(INCLUDE_DIR) -Wall -Wpedantic -Wno-unused-variable -std=gnu99 -Ideps/cyclone/include
2024-10-28 22:09:23 +00:00
2024-08-03 23:20:09 +00:00
LIBNFNETLINK_CFLAGS := -I$(DEPSDIR)/include
LIBNFNETLINK_LIBS := -L$(DEPSDIR)/lib
LIBMNL_CFLAGS := -I$(DEPSDIR)/include
LIBMNL_LIBS := -L$(DEPSDIR)/lib
2024-07-30 23:12:59 +00:00
# PREFIX is environment variable, if not set default to /usr/local
ifeq ($(PREFIX),)
PREFIX := /usr/local
endif
2024-08-03 23:20:09 +00:00
export CC CCLD LD CFLAGS LDFLAGS LIBNFNETLINK_CFLAGS LIBNFNETLINK_LIBS LIBMNL_CFLAGS LIBMNL_LIBS
2024-07-30 23:12:59 +00:00
APP:=$(BUILD_DIR)/youtubeUnblock
2025-01-02 13:44:12 +00:00
TEST_APP:=$(BUILD_DIR)/testYoutubeUnblock
2024-07-30 23:12:59 +00:00
2025-01-07 20:28:01 +00:00
SRCS := mangle.c args.c utils.c quic.c tls.c getopt.c quic_crypto.c inet_ntop.c
2024-07-30 23:12:59 +00:00
OBJS := $(SRCS:%.c=$(BUILD_DIR)/%.o)
2025-01-02 13:44:12 +00:00
APP_EXEC := youtubeUnblock.c
APP_OBJ := $(APP_EXEC:%.c=$(BUILD_DIR)/%.o)
TEST_SRCS := $(shell find test -name "*.c")
TEST_OBJS := $(TEST_SRCS:%.c=$(BUILD_DIR)/%.o)
TEST_CFLAGS := -Itest/unity -Itest
2024-07-30 23:12:59 +00:00
LIBNFNETLINK := $(DEPSDIR)/lib/libnfnetlink.la
LIBMNL := $(DEPSDIR)/lib/libmnl.la
LIBNETFILTER_QUEUE := $(DEPSDIR)/lib/libnetfilter_queue.la
2024-09-21 19:13:32 +00:00
LIBCYCLONE := $(DEPSDIR)/lib/libcyclone.a
2024-07-30 23:12:59 +00:00
2025-01-02 13:44:12 +00:00
.PHONY: default all test build_test dev dev_attrs prepare_dirs
2024-07-30 23:12:59 +00:00
default: all
run_dev: dev
bash -c "sudo $(APP)"
2024-07-30 23:12:59 +00:00
dev: dev_attrs all
dev_attrs:
$(eval CFLAGS := $(CFLAGS) -DDEBUG -ggdb -g3)
all: prepare_dirs $(APP)
2025-01-02 13:44:12 +00:00
build_test: prepare_dirs $(TEST_APP)
test: build_test
$(TEST_APP)
2024-07-30 23:12:59 +00:00
prepare_dirs:
mkdir -p $(BUILD_DIR)
2024-09-21 19:13:32 +00:00
mkdir -p $(BUILD_DIR)/crypto
2025-01-02 13:44:12 +00:00
mkdir -p $(BUILD_DIR)/test
mkdir -p $(BUILD_DIR)/test/unity
2024-07-30 23:12:59 +00:00
mkdir -p $(DEPSDIR)
2024-09-21 19:13:32 +00:00
$(LIBCYCLONE):
2025-01-04 11:01:10 +00:00
$(MAKE) -C deps/cyclone CFLAGS="$(CFLAGS)"
2024-09-21 19:13:32 +00:00
mkdir -p $(DEPSDIR)/lib
cp deps/cyclone/libcyclone.a $(DEPSDIR)/lib/libcyclone.a
2024-07-30 23:12:59 +00:00
$(LIBNFNETLINK):
2024-08-03 23:20:09 +00:00
cd deps/libnfnetlink && ./autogen.sh && ./configure --prefix=$(DEPSDIR) $(if $(CROSS_COMPILE_PLATFORM),--host=$(CROSS_COMPILE_PLATFORM),) --enable-static --disable-shared
2024-07-30 23:12:59 +00:00
$(MAKE) -C deps/libnfnetlink
$(MAKE) install -C deps/libnfnetlink
$(LIBMNL):
2024-08-03 23:20:09 +00:00
cd deps/libmnl && ./autogen.sh && ./configure --prefix=$(DEPSDIR) $(if $(CROSS_COMPILE_PLATFORM),--host=$(CROSS_COMPILE_PLATFORM),) --enable-static --disable-shared
2024-07-30 23:12:59 +00:00
$(MAKE) -C deps/libmnl
$(MAKE) install -C deps/libmnl
$(LIBNETFILTER_QUEUE): $(LIBNFNETLINK) $(LIBMNL)
2024-08-03 23:20:09 +00:00
cd deps/libnetfilter_queue && ./autogen.sh && ./configure --prefix=$(DEPSDIR) $(if $(CROSS_COMPILE_PLATFORM),--host=$(CROSS_COMPILE_PLATFORM),) --enable-static --disable-shared
2024-07-30 23:12:59 +00:00
$(MAKE) -C deps/libnetfilter_queue
$(MAKE) install -C deps/libnetfilter_queue
2025-01-02 13:44:12 +00:00
$(APP): $(OBJS) $(APP_OBJ) $(REQ) $(LIBCYCLONE)
2024-08-03 23:20:09 +00:00
@echo 'CCLD $(APP)'
2025-01-02 13:44:12 +00:00
$(CCLD) $(OBJS) $(APP_OBJ) -o $(APP) $(LDFLAGS) -lmnl -lnetfilter_queue -lpthread -lcyclone
$(TEST_APP): $(APP) $(TEST_OBJS) $(REQ) $(LIBCYCLONE)
@echo 'CCLD $(TEST_APP)'
$(CCLD) $(OBJS) $(TEST_OBJS) -o $(TEST_APP) $(LDFLAGS) -lmnl -lnetfilter_queue -lpthread -lcyclone
2024-07-30 23:12:59 +00:00
2024-09-21 19:13:32 +00:00
$(BUILD_DIR)/%.o: src/%.c $(REQ) $(INCLUDE_DIR)/config.h
2024-07-30 23:12:59 +00:00
@echo 'CC $@'
2024-08-05 19:53:44 +00:00
$(CC) -c $(CFLAGS) $(LDFLAGS) $< -o $@
2024-07-30 23:12:59 +00:00
2025-01-02 13:44:12 +00:00
$(BUILD_DIR)/test/%.o: test/%.c $(REQ) $(INCLUDE_DIR)/config.h
@echo 'CC $@'
$(CC) -c $(CFLAGS) $(LDFLAGS) $(TEST_CFLAGS) $< -o $@
2024-07-30 23:12:59 +00:00
install: all
install -d $(DESTDIR)$(PREFIX)/bin/
install -m 755 $(APP) $(DESTDIR)$(PREFIX)/bin/
install -d $(DESTDIR)$(PREFIX)/lib/systemd/system/
2024-07-30 23:12:59 +00:00
@cp youtubeUnblock.service $(BUILD_DIR)
@sed -i 's/$$(PREFIX)/$(subst /,\/,$(PREFIX))/g' $(BUILD_DIR)/youtubeUnblock.service
install -m 644 $(BUILD_DIR)/youtubeUnblock.service $(DESTDIR)$(PREFIX)/lib/systemd/system/
2024-07-30 23:12:59 +00:00
uninstall:
rm $(DESTDIR)$(PREFIX)/bin/youtubeUnblock
rm $(DESTDIR)$(PREFIX)/lib/systemd/system/youtubeUnblock.service
2024-08-03 23:20:09 +00:00
-systemctl disable youtubeUnblock.service
2024-07-30 23:12:59 +00:00
clean:
find $(BUILD_DIR) -maxdepth 1 -type f | xargs rm -rf
distclean: clean
2024-07-30 23:12:59 +00:00
rm -rf $(BUILD_DIR)
ifeq ($(USE_SYS_LIBS), no)
2024-07-30 23:12:59 +00:00
$(MAKE) distclean -C deps/libnetfilter_queue || true
$(MAKE) distclean -C deps/libmnl || true
$(MAKE) distclean -C deps/libnfnetlink || true
endif
2024-09-21 19:13:32 +00:00
$(MAKE) clean -C deps/cyclone || true