#!/usr/bin/make -f -include Makefile.cfg # Correct the target. TARGET := $(if $(TARGET),$(TARGET)-) # --- # Main information about the project. # --- # Name and description. NAME := libtio DESCRIPTION := Platform-independent streams. # 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 := tio # --- # 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),-DLIBTIO_STATIC,-fPIC) $(if $(OPTIMIZE_SIZE),-Os,-O2) \ -D LOGLEVEL="tio_loglevel_$(LOG_LEVEL)" \ $(shell $(PKGCONFIG) --cflags $(ALLDEPS) 2>/dev/null) \ $(CMOREFLAGS) C_INCLUDE_PATH := # Linker. LD := $(TARGET)gcc # 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. # --- # standard math library. DEP_math_CFLAGS := DEP_math_LIBS := -lm # libusb, communication library. DEP_libusb_CFLAGS := $(if $(NO_LIBUSB),,\ $(shell $(PKGCONFIG) libusb-1.0 --cflags)) DEP_libusb_LIBS := $(if $(NO_LIBUSB),,\ $(shell $(PKGCONFIG) libusb-1.0 --libs)) # --- # Informations about the library. # --- # Dependencies. L_DEPS := L_DEPS_PRIV := $(if $(NO_LIBUSB),,libusb) # 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),$(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$(LIB).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 # --- # 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.