libcasio/Makefile.vars

292 lines
7.2 KiB
Makefile
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/make -f
-include Makefile.cfg
# Correct the target.
TARGET := $(if $(TARGET),$(TARGET)-)
# ---
# Main information about the project.
# ---
# Name and description.
NAME := libcasio
DESCRIPTION := Library and utils for using CASIO protocols and file formats.
# Maintainer information.
MAINTAINER_NAME := Thomas «Cakeisalie5» Touhey
MAINTAINER_MAIL := thomas@touhey.fr
MAINTAINER := $(MAINTAINER_NAME) <$(MAINTAINER_MAIL)>
# Project version.
MAJOR := 0
MINOR := 1
INDEV := yes
VERSION := $(MAJOR).$(MINOR)$(if $(INDEV),-indev)
# Name of some components.
LIB := casio
# ---
# Utilities.
# ---
# Package configuration.
PKGCONFIG := $(TARGET)pkg-config
# Compiler.
CC := $(TARGET)gcc
CWERROR := all extra no-attributes no-unused-macros no-vla no-multichar
ifneq ($(MORE_WARNINGS),)
CWERROR += shadow write-strings redundant-decls format \
format-security implicit-function-declaration \
date-time missing-prototypes return-type pointer-arith \
stack-protector no-unused-parameter
endif
CWARN := $(CWERROR:%=-W%)
#CMOREFLAGS :=
CFLAGS := -I $(INCDIR) $(CWARN) -std=c99 -pedantic \
$(if $(STATIC),-DLIBCASIO_STATIC,-fPIC) $(if $(OPTIMIZE), $(if $(OPTIMIZE_SIZE),-Os,-O2), ) \
-D LOGLEVEL="casio_loglevel_$(LOG_LEVEL)" \
$(shell $(PKGCONFIG) --cflags $(ALLDEPS) 2>/dev/null) \
$(CMOREFLAGS)
# Linker.
LD := $(TARGET)gcc
LDFLAGS := $(if $(STATIC),,-shared) \
$(shell $(PKGCONFIG) --libs $(ALLDEPS) 2>/dev/null) -lm
ifneq ($(FOR_WINDOWS),)
LDFLAGS += -Wl,--out-implib,build/lib$(NAME).dll.a \
-lws2_32 -lsetupapi -luuid
else
LDFLAGS += $(if $(STATIC),,-Wl,-soname,$(SONAME) \
-e lib$(NAME)__version \
-Wl,-z,relro -Wl,-z,combreloc -Wl,-z,defs)
endif
#LDMOREFLAGS :=
LDFLAGS += $(LDMOREFLAGS)
# Archive manager, directory maker, file copier, file mover,
# symbolic link maker, file/folder remover, documentation creator,
# installer, gzipper.
AR := $(TARGET)ar
MD := mkdir -p
CP := cp
MV := mv
LN := ln -sf
RM := rm -f
A2X := a2x
INST := install
GZIP := gzip -f
# ---
# Dependencies definitions.
# ---
# libcasio, defined here.
DEP_libcasio_CFLAGS := -I include
DEP_libcasio_LIBS := -L build -lcasio $(if $(FOR_WINDOWS), -lws2_32, )
# standard math library.
DEP_math_CFLAGS :=
DEP_math_LIBS := -lm
# zlib, compression library.
DEP_zlib_CFLAGS := $(shell $(PKGCONFIG) zlib --cflags)
DEP_zlib_LIBS := $(shell $(PKGCONFIG) zlib --libs)
# libusb, communication library.
DEP_libusb_CFLAGS := $(shell $(PKGCONFIG) libusb-1.0 --cflags)
DEP_libusb_LIBS := $(shell $(PKGCONFIG) libusb-1.0 --libs)
# imagemagick, for image manipulation.
DEP_magick_CFLAGS := $(shell $(PKGCONFIG) MagickCore --cflags 2>/dev/null)
DEP_magick_LIBS := $(shell $(PKGCONFIG) MagickCore --libs 2>/dev/null)
# SDL, for simple graphical utilities.
DEP_sdl_CFLAGS := $(shell $(PKGCONFIG) sdl2 --cflags 2>/dev/null)
DEP_sdl_LIBS := $(shell $(PKGCONFIG) sdl2 --libs 2>/dev/null)
# ---
# Informations about the library.
# ---
# Dependencies.
L_DEPS :=
L_DEPS_PRIV := zlib $(if $(NO_LIBUSB),,libusb) math
# Folders.
L_INCDIR := ./include
L_SRCDIR := ./lib
L_OBJDIR := ./build/lib
# Destination (dynamic and static library name).
L_SONAME := $(if $(FOR_WINDOWS),lib$(LIB).dll,lib$(LIB).so.$(MAJOR))
L_SONAMES := ./build/$(if $(FOR_WINDOWS),lib$(LIB).dll,lib$(LIB).so.*)
L_ANAME := lib$(LIB)$(if $(FOR_WINDOWS),.lib,.a)
L_ANAMES := ./build/lib$(LIB).lib ./build/lib$(LIB).a \
./build/lib$(LIB).dll.a
L_AS_DEP := $(if $(STATIC),./build/$(L_ANAME),$(if \
$(FOR_WINDOWS),./build/$(L_SONAME),./build/lib$(LIB).so))
# Files.
L_SRC := $(patsubst $(L_SRCDIR)/%,%,$(wildcard $(L_SRCDIR)/*.c \
$(L_SRCDIR)/**/*.c $(L_SRCDIR)/**/**/*.c $(L_SRCDIR)/**/**/**/*.c))
L_OBJ := $(L_SRC:%=$(L_OBJDIR)/%.o)
L_OBJDIRS := $(sort $(dir $(L_OBJ)))
L_INCp := $(patsubst $(L_INCDIR)/%,%,$(wildcard $(L_INCDIR)/*.h \
$(L_INCDIR)/**/*.h $(L_INCDIR)/**/**/*.h $(L_INCDIR)/**/**/**/*.h))
L_INC := $(L_INCp:%=$(L_INCDIR)/%) \
$(wildcard $(L_SRCDIR)/*.h $(L_SRCDIR)/**/*.h)
# Flags.
L_CFLAGS := $(CFLAGS) $(foreach dep,$(L_DEPS) $(L_DEPS_PRIV),\
$(DEP_$(dep)_CFLAGS)) -I $(L_INCDIR)
L_LIBS := $(foreach dep,$(L_DEPS) $(L_DEPS_PRIV),$(DEP_$(dep)_LIBS))
L_LDFLAGS := $(if $(STATIC),,-shared) $(L_LIBS)
ifneq ($(FOR_WINDOWS),)
L_LDFLAGS += -Wl,--out-implib,./build/lib$(NAME).dll.a -lws2_32 -lsetupapi -luuid
else
L_LDFLAGS += $(if $(STATIC),,"-Wl,-soname,$(L_SONAME)" \
-e lib$(LIB)__version "-Wl,-z,relro" "-Wl,-z,combreloc" \
-Wl,-z,defs)
endif
# ---
# Informations about the utilities.
# ---
# Folders.
U_SRCDIR := ./src
U_OBJDIR := ./build/utils
# Look for utilities.
UTILS := $(patsubst $(U_SRCDIR)/%,%,$(wildcard $(U_SRCDIR)/*))
# Get the dependencies.
# `U_DEPS_<util>`: dependencies for util <util>.
# `U_DIS_<util>`: if the util is disabled or not.
define get-util-info
U_DEPS_$1 := $(shell make -f $(U_SRCDIR)/$1/vars.mk $(if $(STATIC), libs_static, libs) 2>/dev/null)
U_DIS_$1 := $(shell make -f $(U_SRCDIR)/$1/vars.mk disable 2>/dev/null \
&& echo y)
endef
$(foreach util,$(UTILS),\
$(eval $(call get-util-info,$(util))))
# Get the default utilities.
DEFAULT_UTILS := $(foreach util,$(UTILS),\
$(if $(U_DIS_$(util)),,$(util)))
# Look for the utilities source files and flags.
# It is important to not merge this function with the `get-util-info` as
# you cannot use a variable defined earlier in such a function, you have
# to do a second one.
define get-util-source
U_SRC_$1 := $(patsubst $(U_SRCDIR)/$1/%,%,$(wildcard $(U_SRCDIR)/$1/*.c \
$(U_SRCDIR)/$1/**/*.c))
U_INC_$1 := $(patsubst $(U_INCDIR)/$1/%,%,$(wildcard $(U_SRCDIR)/$1/*.h \
$(U_SRCDIR)/$1/**/*.h)) \
$(if $(filter libcasio,$(U_DEPS_$1)),$(L_INCp:%=$(L_INCDIR)/%))
U_CFLAGS_$1 := $(CFLAGS) $(foreach dep,$(U_DEPS_$1),$(DEP_$(dep)_CFLAGS)) \
-D BIN="\"$1$(if $(FOR_WINDOWS),.exe)\"" \
-D NAME="\"libcasio utilities\"" -D VERSION="\"$(VERSION)\"" \
-D MAINTAINER="\"$(MAINTAINER_NAME) <$(MAINTAINER_MAIL)>\"" \
-D DEFAULT_STORAGE="\"$(DEFAULT_STORAGE)\"" \
-D DEFAULT_ZOOM="\"$(DEFAULT_ZOOM)\"" -D DEFAULT_ZOOM_I="$(DEFAULT_ZOOM)"
U_LIBS_$1 := $(foreach dep,$(U_DEPS_$1),$(DEP_$(dep)_LIBS))
U_LDFLAGS_$1 := $(foreach dep,$(U_DEPS_$1),$(DEP_$(dep)_LIBS))
endef
define get-util-objects
U_OBJ_$1 := $(U_SRC_$1:%=$(U_OBJDIR)/$1/%.o)
endef
$(foreach util,$(UTILS),\
$(eval $(call get-util-source,$(util))))
$(foreach util,$(UTILS),\
$(eval $(call get-util-objects,$(util))))
# Get the object directories.
U_OBJDIRS := $(sort $(dir $(foreach util,$(UTILS),\
$(U_SRC_$(util):%=$(U_OBJDIR)/$(util)/%))))
# ---
# Manpages.
# ---
# Manpages folder.
M_SRCDIR := ./man
M_MANDIR := ./build/man
# Get the manpages sections and contents.
M_SECTIONS :=
define check-man
M_SECTIONS += $1
M_PAGES_$1 += $2
endef
$(foreach doc,$(wildcard $(M_SRCDIR)/*.*.txt),\
$(eval $(call check-man,$(patsubst .%,%,$(suffix $(basename $(doc)))),\
$(notdir $(basename $(basename $(doc)))))))
# Remove duplicate sections.
M_SECTIONS := $(sort $(M_SECTIONS))
# ---
# Check for DESTDIR (add as prefix to installation root).
# ---
# Save original library and include dir.
OIINCDIR := $(IINCDIR)
OILIBDIR := $(ILIBDIR)
# Make it.
define add-dest-dir
$1 = $(DESTDIR)$($1)
endef
$(if $(DESTDIR), $(foreach idir,\
IBINDIR IPKGDIR ILIBDIR IINCDIR IMANDIR HBINDIR, \
$(eval $(call add-dest-dir,$(idir)))))
# End of file.