Skip to content

Commit

Permalink
Merge pull request #270 from bitmark-property-system/master
Browse files Browse the repository at this point in the history
fix the Makefile to install libargon2.pc
  • Loading branch information
veorq committed May 20, 2019
2 parents e4ca309 + d363914 commit 62358ba
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ argon2
libargon2.a
libargon2.so*
libargon2.dylib
libargon2.pc
.DS_Store
src/*.o
src/blake2/*.o
Expand Down
94 changes: 80 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
RUN = argon2
BENCH = bench
GENKAT = genkat
ARGON2_VERSION ?= ZERO

# installation parameters for staging area and final installation path
# Note; if Linux and not Debian/Ubuntu version also add lib override to make command-line
# for RedHat/Fedora, add: LIBRARY_REL=lib64
DESTDIR ?=
PREFIX ?= /usr

# Increment on an ABI breaking change
ABI_VERSION = 1
Expand Down Expand Up @@ -56,40 +63,51 @@ endif

BUILD_PATH := $(shell pwd)
KERNEL_NAME := $(shell uname -s)
MACHINE_NAME := $(shell uname -m)

LIB_NAME = argon2
PC_NAME = lib$(LIB_NAME).pc
PC_SRC = $(PC_NAME).in

LIB_NAME=argon2
ifeq ($(KERNEL_NAME), Linux)
LIB_EXT := so.$(ABI_VERSION)
LIB_CFLAGS := -shared -fPIC -fvisibility=hidden -DA2_VISCTL=1
SO_LDFLAGS := -Wl,-soname,lib$(LIB_NAME).$(LIB_EXT)
LINKED_LIB_EXT := so
PC_EXTRA_LIBS ?= -lrt -ldl
endif
ifeq ($(KERNEL_NAME), $(filter $(KERNEL_NAME),FreeBSD NetBSD OpenBSD))
ifeq ($(KERNEL_NAME), $(filter $(KERNEL_NAME),DragonFly FreeBSD NetBSD OpenBSD))
LIB_EXT := so
LIB_CFLAGS := -shared -fPIC
PC_EXTRA_LIBS ?=
endif
ifeq ($(KERNEL_NAME), Darwin)
LIB_EXT := $(ABI_VERSION).dylib
LIB_CFLAGS := -dynamiclib -install_name @rpath/lib$(LIB_NAME).$(LIB_EXT)
LINKED_LIB_EXT := dylib
PC_EXTRA_LIBS ?=
endif
ifeq ($(findstring CYGWIN, $(KERNEL_NAME)), CYGWIN)
LIB_EXT := dll
LIB_CFLAGS := -shared -Wl,--out-implib,lib$(LIB_NAME).$(LIB_EXT).a
PC_EXTRA_LIBS ?=
endif
ifeq ($(findstring MINGW, $(KERNEL_NAME)), MINGW)
LIB_EXT := dll
LIB_CFLAGS := -shared -Wl,--out-implib,lib$(LIB_NAME).$(LIB_EXT).a
PC_EXTRA_LIBS ?=
endif
ifeq ($(findstring MSYS, $(KERNEL_NAME)), MSYS)
LIB_EXT := dll
LIB_CFLAGS := -shared -Wl,--out-implib,lib$(LIB_NAME).$(LIB_EXT).a
PC_EXTRA_LIBS ?=
endif
ifeq ($(KERNEL_NAME), SunOS)
CC := gcc
CFLAGS += -D_REENTRANT
LIB_EXT := so
LIB_CFLAGS := -shared -fPIC
PC_EXTRA_LIBS ?=
endif

ifeq ($(KERNEL_NAME), Linux)
Expand All @@ -111,20 +129,45 @@ HEADERS = include/argon2.h

INSTALL = install

DESTDIR =
PREFIX = /usr
INCLUDE_REL = include
LIBRARY_REL = lib
BINARY_REL = bin
# relative paths for different OS
ifeq ($(KERNEL_NAME), $(filter $(KERNEL_NAME),DragonFly FreeBSD))

# default for FreeBSD
BINARY_REL ?= bin
INCLUDE_REL ?= include
LIBRARY_REL ?= lib
PKGCONFIG_REL ?= libdata

else ifeq ($(KERNEL_NAME)-$(MACHINE_NAME), Linux-x86_64)

# default for Debian/Ubuntu x86_64
BINARY_REL ?= bin
INCLUDE_REL ?= include
LIBRARY_REL ?= lib/x86_64-linux-gnu
PKGCONFIG_REL ?= $(LIBRARY_REL)

else

# NetBSD, ... and Linux64/Linux32 variants that use plain lib directory
BINARY_REL ?= bin
INCLUDE_REL ?= include
LIBRARY_REL ?= lib
PKGCONFIG_REL ?= $(LIBRARY_REL)

endif

# absolute paths to staging area
INST_INCLUDE = $(DESTDIR)$(PREFIX)/$(INCLUDE_REL)
INST_LIBRARY = $(DESTDIR)$(PREFIX)/$(LIBRARY_REL)
INST_BINARY = $(DESTDIR)$(PREFIX)/$(BINARY_REL)
INST_PKGCONFIG = $(DESTDIR)$(PREFIX)/$(PKGCONFIG_REL)/pkgconfig

.PHONY: clean dist format $(GENKAT) all install

# main target
.PHONY: all
all: $(RUN) libs
libs: $(LIBRARIES)

.PHONY: libs
libs: $(LIBRARIES) $(PC_NAME)

$(RUN): $(SRC) $(SRC_RUN)
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
Expand All @@ -141,47 +184,70 @@ $(LIB_SH): $(SRC)
$(LIB_ST): $(OBJ)
ar rcs $@ $^

.PHONY: clean
clean:
rm -f $(RUN) $(BENCH) $(GENKAT)
rm -f $(LIB_SH) $(LIB_ST) kat-argon2*
rm -f '$(RUN)' '$(BENCH)' '$(GENKAT)'
rm -f '$(LIB_SH)' '$(LIB_ST)' kat-argon2* '$(PC_NAME)'
rm -f testcase
rm -rf *.dSYM
cd src/ && rm -f *.o
cd src/blake2/ && rm -f *.o
cd kats/ && rm -f kat-* diff* run_* make_*


# all substitutions to pc template
SED_COMMANDS = /^\#\#.*$$/d;
SED_COMMANDS += s\#@PREFIX@\#$(PREFIX)\#g;
SED_COMMANDS += s\#@EXTRA_LIBS@\#$(PC_EXTRA_LIBS)\#g;
SED_COMMANDS += s\#@UPSTREAM_VER@\#$(ARGON2_VERSION)\#g;
SED_COMMANDS += s\#@HOST_MULTIARCH@\#$(LIBRARY_REL)\#g;
SED_COMMANDS += s\#@INCLUDE@\#$(INCLUDE_REL)\#g;

# substitute PREFIX and PC_EXTRA_LIBS into pkgconfig pc file
$(PC_NAME): $(PC_SRC)
sed '$(SED_COMMANDS)' < '$(PC_SRC)' > '$@'


.PHONY: dist
dist:
cd ..; \
tar -c --exclude='.??*' -z -f $(DIST)-`date "+%Y%m%d"`.tgz $(DIST)/*

.PHONY: test
test: $(SRC) src/test.c
$(CC) $(CFLAGS) -Wextra -Wno-type-limits $^ -o testcase
@sh kats/test.sh
./testcase

.PHONY: testci
testci: $(SRC) src/test.c
$(CC) $(CI_CFLAGS) $^ -o testcase
@sh kats/test.sh
./testcase

.PHONY: test

.PHONY: format
format:
clang-format -style="{BasedOnStyle: llvm, IndentWidth: 4}" \
-i include/*.h src/*.c src/*.h src/blake2/*.c src/blake2/*.h

.PHONY: install
install: $(RUN) libs
$(INSTALL) -d $(INST_INCLUDE)
$(INSTALL) -m 0644 $(HEADERS) $(INST_INCLUDE)
$(INSTALL) -d $(INST_LIBRARY)
$(INSTALL) $(LIBRARIES) $(INST_LIBRARY)
$(INSTALL) -m 0644 $(LIBRARIES) $(INST_LIBRARY)
ifdef LINKED_LIB_SH
cd $(INST_LIBRARY) && ln -s $(notdir $(LIB_SH) $(LINKED_LIB_SH))
endif
$(INSTALL) -d $(INST_BINARY)
$(INSTALL) $(RUN) $(INST_BINARY)
$(INSTALL) -d $(INST_PKGCONFIG)
$(INSTALL) -m 0644 $(PC_NAME) $(INST_PKGCONFIG)

.PHONY: uninstall
uninstall:
cd $(INST_INCLUDE) && rm -f $(notdir $(HEADERS))
cd $(INST_LIBRARY) && rm -f $(notdir $(LIBRARIES) $(LINKED_LIB_SH))
cd $(INST_BINARY) && rm -f $(notdir $(RUN))
cd $(INST_PKG_CONFIG) && rm -f $(notdir $(PC_NAME))
16 changes: 0 additions & 16 deletions libargon2.pc

This file was deleted.

18 changes: 18 additions & 0 deletions libargon2.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# libargon2 info for pkg-config
## Template for downstream installers:
## - replace @UPSTREAM_VER@ with current version, e.g. '20160406'
## - replace @HOST_MULTIARCH@ with target arch lib, e.g. 'lib', 'lib/x86_64-linux-gnu' or 'lib64'
## - replace @PREFIX@ with install path, e.g. '/usr', '/usr/local', '/usr/pkg'
## - replace @INCLUDE@ with incluse path, e.g. 'include' or 'include/argon2'

prefix=@PREFIX@
exec_prefix=${prefix}
libdir=${prefix}/@HOST_MULTIARCH@
includedir=${prefix}/@INCLUDE@

Name: libargon2
Description: Development libraries for libargon2
Version: @UPSTREAM_VER@
Libs: -L${libdir} -largon2 @EXTRA_LIBS@
Cflags: -I${includedir}
URL: https://github.com/P-H-C/phc-winner-argon2

0 comments on commit 62358ba

Please sign in to comment.