Makefile 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. # Copyright 2015 The Chromium OS Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. # This Makefile normally builds in a 'build' subdir, but use
  5. #
  6. # make BUILD=<dir>
  7. #
  8. # to put the output somewhere else.
  9. ##############################################################################
  10. # Configuration variables come first.
  11. # Verbose? Use V=1
  12. ifeq (${V},)
  13. Q := @
  14. endif
  15. # Quiet? Use QUIET=1
  16. ifeq (${QUIET},)
  17. PRINTF := printf
  18. else
  19. PRINTF := :
  20. endif
  21. CC ?= gcc
  22. LD = ${CC}
  23. PKG_CONFIG ?= pkg-config
  24. SRCDIR := $(shell pwd)
  25. export SRCDIR
  26. BUILD = ${SRCDIR}/build
  27. export BUILD
  28. KEYDIR = ${SRCDIR}/testkeys
  29. CFLAGS = -Wall -Werror
  30. # Create / use dependency files
  31. CFLAGS += -MMD -MF $@.d
  32. ##############################################################################
  33. # Create output directories if necessary. Do this via explicit shell commands
  34. # so it happens before trying to generate/include dependencies.
  35. _dir_create := $(shell [ -d ${BUILD} ] || mkdir -p ${BUILD}))
  36. _keydir_create := $(shell [ -d ${KEYDIR} ] || mkdir -p ${KEYDIR}))
  37. INC_PATH := $(shell ${PKG_CONFIG} --cflags libcrypto)
  38. CFLAGS += ${INC_PATH}
  39. CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
  40. LDLIBS += ${CRYPTO_LIBS}
  41. ##############################################################################
  42. # Sources
  43. LIBSRC = bdb.c host.c sha.c rsa.c
  44. LIBOBJ = ${LIBSRC:%.c=${BUILD}/%.o}
  45. BDBTESTSRC = bdb_test.c
  46. BDBTESTOBJ = ${BDBTESTSRC:%.c=${BUILD}/%.o}
  47. BDBTEST = ${BUILD}/bdb_test
  48. BDBCREATESRC = bdb_create.c
  49. BDBCREATEOBJ = ${BDBCREATESRC:%.c=${BUILD}/%.o}
  50. BDBCREATE = ${BUILD}/bdb_create
  51. DUMPRSASRC = dump_rsa.c
  52. DUMPRSAOBJ = ${DUMPRSASRC:%.c=${BUILD}/%.o}
  53. DUMPRSA = ${BUILD}/dump_rsa
  54. ALL_OBJS = ${LIBOBJ} ${BDBTESTOBJ} ${BDBCREATEOBJ}
  55. ALL_EXES = ${BDBTEST} ${BDBCREATE} ${DUMPRSA}
  56. ##############################################################################
  57. # Targets
  58. .PHONY: all
  59. all: ${ALL_EXES}
  60. .PHONY: clean
  61. clean:
  62. ${Q}/bin/rm -rf ${BUILD}
  63. .PHONY: bdb
  64. bdb: ${BDBCREATE}
  65. ${Q}${BDBCREATE}
  66. .PHONY: runtests
  67. runtests: ${BDBTEST}
  68. ${Q}${BDBTEST}
  69. .PHONY: testkeys
  70. testkeys: ${DUMPRSA}
  71. ${Q}openssl genrsa -F4 -out ${KEYDIR}/bdbkey.pem 4096
  72. ${Q}openssl req -batch -new -x509 -key ${KEYDIR}/bdbkey.pem \
  73. -out ${KEYDIR}/bdbkey.crt
  74. ${Q}${DUMPRSA} -cert ${KEYDIR}/bdbkey.crt > ${KEYDIR}/bdbkey.keyb
  75. ${Q}openssl genrsa -3 -out ${KEYDIR}/subkey.pem 3072
  76. ${Q}openssl req -batch -new -x509 -key ${KEYDIR}/subkey.pem \
  77. -out ${KEYDIR}/subkey.crt
  78. ${Q}${DUMPRSA} -cert ${KEYDIR}/subkey.crt > ${KEYDIR}/subkey.keyb
  79. ${BDBTEST}: ${BDBTESTOBJ} ${LIBOBJ}
  80. @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
  81. ${Q}${LD} -o ${BDBTEST} ${CFLAGS} $^ ${LIBS} ${LDLIBS}
  82. ${BDBCREATE}: ${BDBCREATEOBJ} ${LIBOBJ}
  83. @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
  84. ${Q}${LD} -o ${BDBCREATE} ${CFLAGS} $^ ${LIBS} ${LDLIBS}
  85. ${DUMPRSA}: ${DUMPRSAOBJ} ${LIBOBJ}
  86. @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
  87. ${Q}${LD} -o ${DUMPRSA} ${CFLAGS} $^ ${LIBS} ${LDLIBS}
  88. ##############################################################################
  89. # Generic build rules. LIBS and OBJS can be overridden to tweak the generic
  90. # rules for specific targets.
  91. ${BUILD}/%: ${BUILD}/%.o ${OBJS} ${LIBS}
  92. @${PRINTF} " LD $(subst ${BUILD}/,,$@)\n"
  93. ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $< ${OBJS} ${LIBS} ${LDLIBS}
  94. ${BUILD}/%.o: %.c
  95. @${PRINTF} " CC $(subst ${BUILD}/,,$@)\n"
  96. ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
  97. # Include generated dependencies
  98. ALL_DEPS += ${ALL_OBJS:%.o=%.o.d}
  99. -include ${ALL_DEPS}