Files
ftpsrv/Makefile.linux
2026-03-28 00:49:16 +03:00

88 lines
2.7 KiB
Makefile

# Copyright (C) 2025 John Törnblom
#
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING. If not see
# <http://www.gnu.org/licenses/>.
ELF := ftpsrv-posix.elf
VERSION_TAG := $(shell git describe --abbrev=6 --dirty --always --tags)
PTHREAD_FLAGS := -pthread
USE_AOCL_ZLIB ?= 1
DEPFLAGS := -MMD -MP
OBJDIR := .build/linux
AOCL_DIR := third_party/aocl-compression
AOCL_BUILD_DIR := $(AOCL_DIR)/build-ftpsrv
AOCL_LIB := $(AOCL_BUILD_DIR)/libaocl_compression.a
AOCL_TRACKED := $(addprefix $(AOCL_DIR)/,$(shell git -C $(AOCL_DIR) ls-files 2>/dev/null))
AOCL_CFLAGS := -I$(AOCL_DIR) -I$(AOCL_BUILD_DIR) -I$(AOCL_DIR)/algos/zlib -I$(AOCL_DIR)/algos/common
ifeq ($(USE_AOCL_ZLIB),1)
ZLIB_CFLAGS := $(AOCL_CFLAGS)
ZLIB_LIBS := $(AOCL_LIB) -lstdc++ -lm
else
ZLIB_CFLAGS := $(shell pkg-config --cflags zlib)
ZLIB_LIBS := $(shell pkg-config --libs zlib)
endif
CFLAGS := -Wall -Werror -DVERSION_TAG=\"$(VERSION_TAG)\" -I. $(ZLIB_CFLAGS) $(PTHREAD_FLAGS) $(DEPFLAGS)
SOURCE := srv.c cmd.c notify.c io.c modez.c self.c sha256.c
SOURCE += main-linux.c cmd-linux.c self-linux.c
SOURCE += io-linux.c
OBJECTS := $(patsubst %.c,$(OBJDIR)/%.o,$(SOURCE))
DEPS := $(OBJECTS:.o=.d)
all: $(ELF)
$(ELF): $(OBJECTS) $(if $(filter 1,$(USE_AOCL_ZLIB)),$(AOCL_LIB))
$(CC) $(CFLAGS) -o $@ $(OBJECTS) $(ZLIB_LIBS) $(PTHREAD_FLAGS)
$(OBJDIR):
mkdir -p $@
$(OBJDIR)/%.o: %.c | $(OBJDIR)
$(CC) $(CFLAGS) -c -o $@ $<
$(AOCL_BUILD_DIR)/CMakeCache.txt: $(AOCL_DIR)/CMakeLists.txt
@test -e $(AOCL_DIR)/.git || (echo "AOCL submodule is missing. Run: git submodule update --init --recursive" && false)
cmake -S $(AOCL_DIR) -B $(AOCL_BUILD_DIR) \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_STATIC_LIBS=ON \
-DBUILD_EXAMPLE=OFF \
-DBUILD_DOC=OFF \
-DBUILD_UTILITY=OFF \
-DAOCL_ENABLE_THREADS=OFF \
-DNATIVE_ENABLE_THREADS=OFF \
-DAOCL_EXCLUDE_BZIP2=ON \
-DAOCL_EXCLUDE_LZ4=ON \
-DAOCL_EXCLUDE_LZ4HC=ON \
-DAOCL_EXCLUDE_LZMA=ON \
-DAOCL_EXCLUDE_SNAPPY=ON \
-DAOCL_EXCLUDE_ZSTD=ON
$(AOCL_LIB): $(AOCL_BUILD_DIR)/CMakeCache.txt $(AOCL_TRACKED)
cmake --build $(AOCL_BUILD_DIR) --target aocl_compression -j
clean-aocl:
rm -rf $(AOCL_BUILD_DIR)
clean:
rm -f $(ELF)
rm -rf $(OBJDIR)
test: $(ELF)
./$^
-include $(DEPS)