femtoTCP/Makefile
2024-12-15 17:05:37 +01:00

91 lines
2.2 KiB
Makefile

CC?=gcc
CFLAGS:=-Wall -Werror -Wextra -I.
CFLAGS+=-g -ggdb
LDFLAGS+=-pthread
OBJ=build/femtotcp.o \
build/port/posix/linux_tap.o
EXE=build/tcpecho build/tcp_netcat_poll build/tcp_netcat_select \
build/test-evloop build/test-dns
LIB=libfemtotcp.so
PREFIX=/usr/local
all: $(EXE) $(LIB)
#Static library
static: CFLAGS+=-static
static: libtcpip.a
libtcpip.a: $(OBJ)
@ar rcs $@ $^
libfemtotcp.so:CFLAGS+=-fPIC
libfemtotcp.so: build/pie/port/posix/bsd_socket.o build/pie/femtotcp.o \
build/pie/port/posix/linux_tap.o
@mkdir -p `dirname $@` || true
@echo "[LD] $@"
@$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ -Wl,--start-group $(^) -Wl,--end-group
clean:
@rm -rf build
asan: $(EXE) $(LIB)
asan:CFLAGS+=-fsanitize=address
asan:LDFLAGS+=-static-libasan
# Test
unit:LDFLAGS+=-lcheck -lm -lpthread -lrt -ldl -lsubunit
build/test-evloop: $(OBJ) build/test/test_linux_eventloop.o
@echo "[LD] $@"
@$(CC) $(CFLAGS) $(LDFLAGS) -o $@ -Wl,--start-group $(^) -Wl,--end-group
build/test-dns: $(OBJ) build/test/test_linux_dhcp_dns.o
@echo "[LD] $@"
@$(CC) $(CFLAGS) $(LDFLAGS) -o $@ -Wl,--start-group $(^) -Wl,--end-group
build/tcpecho: $(OBJ) build/port/posix/bsd_socket.o build/test/tcp_echo.o
@echo "[LD] $@"
@$(CC) $(CFLAGS) $(LDFLAGS) -o $@ -Wl,--start-group $(^) -Wl,--end-group
build/tcp_netcat_poll: $(OBJ) build/port/posix/bsd_socket.o build/test/tcp_netcat_poll.o
@echo "[LD] $@"
@$(CC) $(CFLAGS) $(LDFLAGS) -o $@ -Wl,--start-group $(^) -Wl,--end-group
build/tcp_netcat_select: $(OBJ) build/port/posix/bsd_socket.o build/test/tcp_netcat_select.o
@echo "[LD] $@"
@$(CC) $(CFLAGS) $(LDFLAGS) -o $@ -Wl,--start-group $(^) -Wl,--end-group
build/%.o: src/%.c
@mkdir -p `dirname $@` || true
@echo "[CC] $<"
@$(CC) $(CFLAGS) -c $< -o $@
build/pie/%.o: src/%.c
@mkdir -p `dirname $@` || true
@echo "[CC] $<"
@$(CC) $(CFLAGS) -c $< -o $@
unit: build/test/unit
build/test/unit:
@mkdir -p build/test/
@echo "[CC] unit.c"
@$(CC) $(CFLAGS) -c src/test/unit/unit.c -o build/test/unit.o
@echo "[LD] $@"
@$(CC) -o build/test/unit build/test/unit.o $(LDFLAGS)
# Install dynamic library to re-link linux applications
#
install:
install libfemtotcp.so $(PREFIX)/lib
ldconfig
.PHONY: clean all static