1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
# SPDX-License-Identifier: MIT
# Basic DIRes
DESTDIR ?=
PREFIX ?= /usr
BINDIR ?= $(PREFIX)/bin
MANDIR ?= $(PREFIX)/share/man
# Build with pcre by default
ENABLE ?= libpcre2-posix
# GNU make executes the commands here and sets the variables to the outputs
EXTRA_LIBS = $(shell $(EXTRA_LIBS!))
EXTRA_FLAGS = $(shell $(EXTRA_FLAGS!))
# pmake executes the commands, GNU make creates variables with a ! suffix
EXTRA_LIBS!= pkg-config --libs $(ENABLE) 2>/dev/null || echo
EXTRA_FLAGS!= pkg-config --cflags $(ENABLE) 2>/dev/null || echo
#Default flags
CFLAGS ?= -Wall -O2 -g
# Overwrites for the linker
MYLDLIBS = $(EXTRA_LIBS)
MYCFLAGS = -DHAVE_CONFIG_H $(EXTRA_FLAGS)
# Linker and compiler commands
MYLD = $(CC) $(LDFLAGS) $(TARGET_ARCH)
MYCC = $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH)
# Features to test for when creating configure.h
FEATURES := GETOPT_LONG POSIX_FADVISE XATTR $(ENABLE)
all: hardlink
config.log config.h:
@for feat in $(FEATURES); do \
printf "Checking for %s..." "$$feat" | tee -a config.log; \
if $(MYCC) $(MYCFLAGS) -o /dev/null \
-DTEST_$$(echo $$feat | sed s#-#_#) configure.c $(LDLIBS) $(MYLDLIBS) 2>>config.log; then \
printf "\tOK\n" | tee -a config.log; \
echo "#define HAVE_$$(echo $$feat | sed s#-#_#) 1" >&3; \
else \
printf "\tFAIL\n" | tee -a config.log ; \
echo "#undef HAVE_$$(echo $$feat | sed s#-#_#)" >&3; \
fi; \
done 3> config.h
hardlink.o: hardlink.c config.h
$(MYCC) $(MYCFLAGS) -o $@ -c hardlink.c
hardlink: hardlink.o
$(MYLD) -o $@ hardlink.o $(LDLIBS) $(MYLDLIBS)
install: hardlink
install -d $(DESTDIR)$(BINDIR)
install -d $(DESTDIR)$(MANDIR)/man1
install -m 755 hardlink $(DESTDIR)$(BINDIR)/hardlink
install -m 644 hardlink.1 $(DESTDIR)$(MANDIR)/man1/hardlink.1
clean:
rm -f hardlink hardlink.o config.h config.log
|