Dépôt historique pour les p7utils.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

157 lines
4.9 KiB

#!/usr/bin/make -f
#*****************************************************************************#
# Include configuration #
#*****************************************************************************#
-include Makefile.cfg
# Correct target
TARGET := $(if $(TARGET),$(TARGET)-)
#*****************************************************************************#
# Project main information #
#*****************************************************************************#
# Project name.
NAME := p7utils
# Author information.
MAINTAINER_NAME := Thomas \"Cakeisalie5\" Touhey
MAINTAINER_MAIL := thomas@touhey.fr
# Project license.
LICENSE := GPLv2
# Project version.
MAJOR := 4
MINOR := 0
INDEV := y
# Project version string.
VERSION := $(MAJOR).$(MINOR)$(if $(INDEV),-indev)
#*****************************************************************************#
# Project directories #
#*****************************************************************************#
# Sources directory
SRCDIR := ./src
# Objects directory
OBJDIR := ./obj
# Manpages sources directory
DOCDIR := ./doc
# Manpages directory
MANDIR := ./man
#*****************************************************************************#
# Binary utilities #
#*****************************************************************************#
# Package configuration
PKGCONFIG := $(TARGET)pkg-config
# C Compiler
CC := $(TARGET)gcc
# - Check flags (enable warnings)
CWARN := -Wall -Wextra -Wno-unused-macros -Wno-vla
# - Maintainer flags
ifdef MORE_WARNINGS
CWERROR := shadow write-strings redundant-decls format format-nonliteral \
format-security implicit-function-declaration \
date-time missing-prototypes return-type pointer-arith
CWARN += $(CWERROR:%=-W%) -Wstack-protector -Wno-unused-parameter
endif
# - More flags (profiling, ...)
#CMOREFLAGS :=
# - All C Compiler flags
CFLAGS := $(CWARN) -std=gnu11 -O2 -D NAME="$(NAME)" -D VERSION="$(VERSION)" \
-D MAINTAINER="$(MAINTAINER_NAME) <$(MAINTAINER_MAIL)>" \
-D DEFAULT_STORAGE="$(DEFAULT_STORAGE)" \
-D DEFAULT_ZOOM="$(DEFAULT_ZOOM)" \
$(CMOREFLAGS)
# Linker
LD := $(TARGET)gcc
# - Specific linker flags
LDFLAGS_Linux := -Wl,-z,relro
# - Linker flags
LDFLAGS := $(if $(FOR_WINDOWS),,$(LDFLAGS_Linux))
# Raw ELF object maker
LDR := $(TARGET)ld -r
# Maker
MAKE := make --no-print-directory
# Directory maker
MD := mkdir -p
# File remover
RM := rm -f
# Installer
INSTALL := install
# Asciidoc
A2X := a2x
# Gzipper
GZIP := gzip -f
#*****************************************************************************#
# Binaries and sources #
#*****************************************************************************#
# Look for binaries
BINARIES := $(notdir $(shell find $(SRCDIR) -mindepth 1 -maxdepth 1 \
-type d | sort))
# Get their libs
define get-binary-libs
LIBS_$1 := $(shell make -f $(SRCDIR)/$1/vars.mk libs 2>/dev/null)
DISABLE_$1 := $(shell make -f $(SRCDIR)/$1/vars.mk disable 2>/dev/null \
&& echo y)
endef
$(foreach bin,$(BINARIES), \
$(eval $(call get-binary-libs,$(bin))))
# Get the default binaries
DEFAULT_BINARIES := $(foreach bin,$(BINARIES), \
$(if $(DISABLE_$(bin)),,$(bin)))
# Look for their sources
define get-binary-sources
SRC_$1 := $(shell find $(SRCDIR)/$1 \
-mindepth 1 -name "*.c" \
-printf "%P\n" | sort)
# - get the flags
CFLAGS_$1 := $(CFLAGS) $(shell $(PKGCONFIG) $(LIBS_$1) --cflags 2>/dev/null) \
-D BIN="$1$(if $(FOR_WINDOWS),.exe)"
LDFLAGS_$1 := $(LDFLAGS) $(shell $(PKGCONFIG) $(LIBS_$1) --libs 2>/dev/null)
endef
$(foreach bin,$(BINARIES), \
$(eval $(call get-binary-sources,$(bin))))
# Get the directories
DIRS := $(sort $(dir \
$(foreach bin,$(BINARIES),$(SRC_$(bin):%=$(OBJDIR)/$(bin)/%))))
#*****************************************************************************#
# Look for manpages #
#*****************************************************************************#
# Get the manpages sections and contents
MAN_SECTIONS :=
define check-man
MAN_SECTIONS += $1
MAN_$1 += $2
endef
$(foreach doc, $(basename $(shell find $(DOCDIR) \
-maxdepth 1 -mindepth 1 -printf "%P\n" -type f -or -type l -name "*.*.txt")), \
$(eval $(call check-man,$(patsubst .%,%,$(suffix $(doc))),$(basename $(doc)))))
# Remove duplicate sections.
MAN_SECTIONS := $(sort $(MAN_SECTIONS))
#*****************************************************************************#
# Check for DESTDIR (add as prefix to installation root) #
#*****************************************************************************#
define add-dest-dir
$1 = $(DESTDIR)$($1)
endef
$(if $(DESTDIR), $(foreach idir,IBINDIR IMANDIR, \
$(eval $(call add-dest-dir,$(idir)))))
# End of file.