libcasio/Makefile.vars

292 lines
7.2 KiB
Makefile
Raw Normal View History

2017-06-12 01:06:23 +02:00
#!/usr/bin/make -f
-include Makefile.cfg
# Correct the target.
2017-06-12 01:06:23 +02:00
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
2017-06-12 01:06:23 +02:00
MAINTAINER_MAIL := thomas@touhey.fr
MAINTAINER := $(MAINTAINER_NAME) <$(MAINTAINER_MAIL)>
# Project version.
2017-06-12 01:06:23 +02:00
MAJOR := 0
MINOR := 1
INDEV := yes
VERSION := $(MAJOR).$(MINOR)$(if $(INDEV),-indev)
# Name of some components.
LIB := casio
# ---
# Utilities.
# ---
# Package configuration.
2017-06-12 01:06:23 +02:00
PKGCONFIG := $(TARGET)pkg-config
# Compiler.
2017-06-12 01:06:23 +02:00
CC := $(TARGET)gcc
2017-06-12 01:06:23 +02:00
CWERROR := all extra no-attributes no-unused-macros no-vla no-multichar
ifneq ($(MORE_WARNINGS),)
2018-05-04 21:19:12 +02:00
CWERROR += shadow write-strings redundant-decls format \
2017-06-12 01:06:23 +02:00
format-security implicit-function-declaration \
date-time missing-prototypes return-type pointer-arith \
stack-protector no-unused-parameter
endif
CWARN := $(CWERROR:%=-W%)
#CMOREFLAGS :=
2017-06-12 01:06:23 +02:00
CFLAGS := -I $(INCDIR) $(CWARN) -std=c99 -pedantic \
2019-12-30 23:33:37 +01:00
$(if $(STATIC),-DLIBCASIO_STATIC,-fPIC) $(if $(OPTIMIZE), $(if $(OPTIMIZE_SIZE),-Os,-O2), ) \
2017-06-12 01:06:23 +02:00
-D LOGLEVEL="casio_loglevel_$(LOG_LEVEL)" \
$(shell $(PKGCONFIG) --cflags $(ALLDEPS) 2>/dev/null) \
$(CMOREFLAGS)
# Linker.
2017-06-12 01:06:23 +02:00
LD := $(TARGET)gcc
2017-06-12 01:06:23 +02:00
LDFLAGS := $(if $(STATIC),,-shared) \
$(shell $(PKGCONFIG) --libs $(ALLDEPS) 2>/dev/null) -lm
ifneq ($(FOR_WINDOWS),)
2020-01-03 13:56:15 +01:00
LDFLAGS += -Wl,--out-implib,build/lib$(NAME).dll.a \
2017-06-12 01:06:23 +02:00
-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 :=
2017-06-12 01:06:23 +02:00
LDFLAGS += $(LDMOREFLAGS)
# Archive manager, directory maker, file copier, file mover,
# symbolic link maker, file/folder remover, documentation creator,
# installer, gzipper.
2017-06-12 01:06:23 +02:00
AR := $(TARGET)ar
2017-06-12 01:06:23 +02:00
MD := mkdir -p
CP := cp
MV := mv
LN := ln -sf
RM := rm -f
A2X := a2x
INST := install
2018-04-25 19:02:58 +02:00
GZIP := gzip -f
# ---
# Dependencies definitions.
# ---
# libcasio, defined here.
DEP_libcasio_CFLAGS := -I include
2020-01-03 13:25:50 +01:00
DEP_libcasio_LIBS := -L build -lcasio $(if $(FOR_WINDOWS), -lws2_32, )
2018-05-04 21:19:12 +02:00
# 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.
2018-04-25 04:05:13 +02:00
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.
2018-04-25 04:05:13 +02:00
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 :=
2018-05-04 21:19:12 +02:00
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
2020-01-03 00:35:06 +01:00
L_AS_DEP := $(if $(STATIC),./build/$(L_ANAME),$(if \
2018-04-25 04:05:13 +02:00
$(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 \
2018-04-25 19:02:58 +02:00
$(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),)
2020-01-03 13:56:15 +01:00
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
2020-01-03 00:35:06 +01:00
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)) \
2018-04-25 19:02:58 +02:00
-D BIN="\"$1$(if $(FOR_WINDOWS),.exe)\"" \
2018-04-27 15:32:44 +02:00
-D NAME="\"libcasio utilities\"" -D VERSION="\"$(VERSION)\"" \
2018-04-25 19:02:58 +02:00
-D MAINTAINER="\"$(MAINTAINER_NAME) <$(MAINTAINER_MAIL)>\"" \
-D DEFAULT_STORAGE="\"$(DEFAULT_STORAGE)\"" \
2018-04-27 15:32:44 +02:00
-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 :=
2017-06-12 01:06:23 +02:00
define check-man
M_SECTIONS += $1
M_PAGES_$1 += $2
2017-06-12 01:06:23 +02:00
endef
$(foreach doc,$(wildcard $(M_SRCDIR)/*.*.txt),\
$(eval $(call check-man,$(patsubst .%,%,$(suffix $(basename $(doc)))),\
$(notdir $(basename $(basename $(doc)))))))
2017-06-12 01:06:23 +02:00
# Remove duplicate sections.
M_SECTIONS := $(sort $(M_SECTIONS))
# ---
# Check for DESTDIR (add as prefix to installation root).
# ---
2017-06-12 01:06:23 +02:00
# Save original library and include dir.
2017-06-12 01:06:23 +02:00
OIINCDIR := $(IINCDIR)
OILIBDIR := $(ILIBDIR)
# Make it.
2017-06-12 01:06:23 +02:00
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.