Makefile: fix dependencies generation

This patch was inspired by crrev.com/c/2091999, the goal is to help
Cr50 makefiles (the main users of the tpm2 library) to avoid
unnecessary compilations.

Here is the description from the above patch slightly edited for
clarity and to match the tpm2 use case.

vvvvvvv
The main goal of this is to fix "make --question -C tpm2" behavior
for the Cr50 project which depends on this library.

Without this fix, when invoking make with the --question flag,
a build of all *.o was triggered.

This was because the "-include $(DEPS)" make step depended on *.d
files. That would then trigger the primary

"$(obj)/$(OBJ_PREFIX)%.d $(obj)/$(OBJ_PREFIX)%.o:"

rule, which [yes generated .d files, but also] generated the objects.

The following article explains the art of makefile depends quite well:
http://make.mad-scientist.net/papers/advanced-auto-dependency-generation
^^^^^^^

On top of that this patch does the following:

 - add -MP to the compiler invocation to address the problem of
   moving/deleted .h files.

 - add a target to print the list of updated object files, this allows
   the user (the Cr50 makefile) to know exactly what needs to be
   linked in, instead of globbing.

 - add a dummy file target depending on all updated object files, this
   simplifies Cr50 makefiles.

BUG=None
TEST=make clean; make -q && echo Fail
    # No CC builds should occur and no Fail was emitted
    # Before this change, the make -q would trigger a build
    make clean; make || echo Fail; make -q || echo Fail
    # No Fail should be emitted
    make
    touch tpm_manufacture.h
    make
    # See endorsement.o, tpm_manufacture.o, and libtpm2.a
    # being remade.
    make
    mv tpm_manufacture.h new_tpm_manufacture.h
    sed -i 's/tpm_manufacture.h/new_tpm_manufacture.h/' \
       endorsement.c tpm_manufacture.c
    make
    # See endorsement.o, tpm_manufacture.o, and libtpm2.a
    # being remade and no complaints about missing .h files.
    make build/.copied_objs
    # See the set of *.co.o and .copied_objs generated.

Change-Id: Ie492c08caec82b3de29a9e067aa7a3225110a50d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/tpm2/+/2606746
Tested-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-by: Craig Hesling <hesling@chromium.org>
1 file changed
tree: 80bbeabd626668bcbd7f5dcb0b1f4dc1f13f8754
  1. .gitignore
  2. ActivateCredential.c
  3. ActivateCredential_fp.h
  4. AlgorithmCap.c
  5. AlgorithmCap_fp.h
  6. Attest_spt.c
  7. Attest_spt_fp.h
  8. BaseTypes.h
  9. Bits.c
  10. Bits_fp.h
  11. Cancel.c
  12. Capabilities.h
  13. Certify.c
  14. CertifyCreation.c
  15. CertifyCreation_fp.h
  16. Certify_fp.h
  17. ChangeEPS.c
  18. ChangeEPS_fp.h
  19. ChangePPS.c
  20. ChangePPS_fp.h
  21. Clear.c
  22. ClearControl.c
  23. ClearControl_fp.h
  24. Clear_fp.h
  25. Clock.c
  26. ClockRateAdjust.c
  27. ClockRateAdjust_fp.h
  28. ClockSet.c
  29. ClockSet_fp.h
  30. CommandAttributeData.c
  31. CommandAudit.c
  32. CommandAudit_fp.h
  33. CommandCodeAttributes.c
  34. CommandCodeAttributes_fp.h
  35. CommandDispatcher.c
  36. CommandDispatcher_fp.h
  37. Commands_fp.h
  38. Commit.c
  39. Commit_fp.h
  40. ContextLoad.c
  41. ContextLoad_fp.h
  42. ContextSave.c
  43. ContextSave_fp.h
  44. Context_spt.c
  45. Context_spt_fp.h
  46. CpriCryptPri.c
  47. CpriCryptPri_fp.h
  48. CpriDataEcc.c
  49. CpriDataEcc.h
  50. CpriECC.c
  51. CpriECC_fp.h
  52. CpriHash.c
  53. CpriHashData.c
  54. CpriHash_fp.h
  55. CpriMisc.c
  56. CpriMisc_fp.h
  57. CpriRNG.c
  58. CpriRNG_fp.h
  59. CpriRSA.c
  60. CpriRSA_fp.h
  61. CpriSym.c
  62. CpriSym_fp.h
  63. Create.c
  64. CreatePrimary.c
  65. CreatePrimary_fp.h
  66. Create_fp.h
  67. CryptSelfTest.c
  68. CryptSelfTest_fp.h
  69. CryptUtil.c
  70. CryptUtil_fp.h
  71. CryptoEngine.h
  72. DA.c
  73. DA_fp.h
  74. DRTM.c
  75. DictionaryAttackLockReset.c
  76. DictionaryAttackLockReset_fp.h
  77. DictionaryAttackParameters.c
  78. DictionaryAttackParameters_fp.h
  79. Duplicate.c
  80. Duplicate_fp.h
  81. ECC_Parameters.c
  82. ECC_Parameters_fp.h
  83. ECDH_KeyGen.c
  84. ECDH_KeyGen_fp.h
  85. ECDH_ZGen.c
  86. ECDH_ZGen_fp.h
  87. EC_Ephemeral.c
  88. EC_Ephemeral_fp.h
  89. EncryptDecrypt.c
  90. EncryptDecrypt_fp.h
  91. Entity.c
  92. Entity_fp.h
  93. Entropy.c
  94. EventSequenceComplete.c
  95. EventSequenceComplete_fp.h
  96. EvictControl.c
  97. EvictControl_fp.h
  98. ExecCommand.c
  99. ExecCommand_fp.h
  100. FieldUpgradeData.c
  101. FieldUpgradeData_fp.h
  102. FieldUpgradeStart.c
  103. FieldUpgradeStart_fp.h
  104. FirmwareRead.c
  105. FirmwareRead_fp.h
  106. FlushContext.c
  107. FlushContext_fp.h
  108. GetCapability.c
  109. GetCapability_fp.h
  110. GetCommandAuditDigest.c
  111. GetCommandAuditDigest_fp.h
  112. GetCommandCodeString.c
  113. GetCommandCodeString_fp.h
  114. GetRandom.c
  115. GetRandom_fp.h
  116. GetSessionAuditDigest.c
  117. GetSessionAuditDigest_fp.h
  118. GetTestResult.c
  119. GetTestResult_fp.h
  120. GetTime.c
  121. GetTime_fp.h
  122. Global.c
  123. Global.h
  124. HMAC.c
  125. HMAC_Start.c
  126. HMAC_Start_fp.h
  127. HMAC_fp.h
  128. Handle.c
  129. HandleProcess.c
  130. HandleProcess_fp.h
  131. Handle_fp.h
  132. Hash.c
  133. HashSequenceStart.c
  134. HashSequenceStart_fp.h
  135. Hash_fp.h
  136. Hierarchy.c
  137. HierarchyChangeAuth.c
  138. HierarchyChangeAuth_fp.h
  139. HierarchyControl.c
  140. HierarchyControl_fp.h
  141. Hierarchy_fp.h
  142. Implementation.h
  143. Import.c
  144. Import_fp.h
  145. IncrementalSelfTest.c
  146. IncrementalSelfTest_fp.h
  147. InternalRoutines.h
  148. LICENSE
  149. Load.c
  150. LoadExternal.c
  151. LoadExternal_fp.h
  152. Load_fp.h
  153. Locality.c
  154. LocalityPlat.c
  155. Locality_fp.h
  156. MakeCredential.c
  157. MakeCredential_fp.h
  158. Makefile
  159. Manufacture.c
  160. Manufacture_fp.h
  161. Marshal_ActivateCredential.c
  162. Marshal_Certify.c
  163. Marshal_CertifyCreation.c
  164. Marshal_ChangeEPS.c
  165. Marshal_ChangePPS.c
  166. Marshal_Clear.c
  167. Marshal_ClearControl.c
  168. Marshal_ClockRateAdjust.c
  169. Marshal_ClockSet.c
  170. Marshal_Commit.c
  171. Marshal_ContextLoad.c
  172. Marshal_ContextSave.c
  173. Marshal_Create.c
  174. Marshal_CreatePrimary.c
  175. Marshal_DictionaryAttackLockReset.c
  176. Marshal_DictionaryAttackParameters.c
  177. Marshal_Duplicate.c
  178. Marshal_ECC_Parameters.c
  179. Marshal_ECDH_KeyGen.c
  180. Marshal_ECDH_ZGen.c
  181. Marshal_EC_Ephemeral.c
  182. Marshal_EncryptDecrypt.c
  183. Marshal_EventSequenceComplete.c
  184. Marshal_EvictControl.c
  185. Marshal_FieldUpgradeData.c
  186. Marshal_FieldUpgradeStart.c
  187. Marshal_FirmwareRead.c
  188. Marshal_FlushContext.c
  189. Marshal_GetCapability.c
  190. Marshal_GetCommandAuditDigest.c
  191. Marshal_GetRandom.c
  192. Marshal_GetSessionAuditDigest.c
  193. Marshal_GetTestResult.c
  194. Marshal_GetTime.c
  195. Marshal_HMAC.c
  196. Marshal_HMAC_Start.c
  197. Marshal_Hash.c
  198. Marshal_HashSequenceStart.c
  199. Marshal_HierarchyChangeAuth.c
  200. Marshal_HierarchyControl.c
  201. Marshal_Import.c
  202. Marshal_IncrementalSelfTest.c
  203. Marshal_Load.c
  204. Marshal_LoadExternal.c
  205. Marshal_MakeCredential.c
  206. Marshal_NV_Certify.c
  207. Marshal_NV_ChangeAuth.c
  208. Marshal_NV_DefineSpace.c
  209. Marshal_NV_Extend.c
  210. Marshal_NV_GlobalWriteLock.c
  211. Marshal_NV_Increment.c
  212. Marshal_NV_Read.c
  213. Marshal_NV_ReadLock.c
  214. Marshal_NV_ReadPublic.c
  215. Marshal_NV_SetBits.c
  216. Marshal_NV_UndefineSpace.c
  217. Marshal_NV_UndefineSpaceSpecial.c
  218. Marshal_NV_Write.c
  219. Marshal_NV_WriteLock.c
  220. Marshal_ObjectChangeAuth.c
  221. Marshal_PCR_Allocate.c
  222. Marshal_PCR_Event.c
  223. Marshal_PCR_Extend.c
  224. Marshal_PCR_Read.c
  225. Marshal_PCR_Reset.c
  226. Marshal_PCR_SetAuthPolicy.c
  227. Marshal_PCR_SetAuthValue.c
  228. Marshal_PP_Commands.c
  229. Marshal_PolicyAuthValue.c
  230. Marshal_PolicyAuthorize.c
  231. Marshal_PolicyCommandCode.c
  232. Marshal_PolicyCounterTimer.c
  233. Marshal_PolicyCpHash.c
  234. Marshal_PolicyDuplicationSelect.c
  235. Marshal_PolicyFidoSigned.c
  236. Marshal_PolicyGetDigest.c
  237. Marshal_PolicyLocality.c
  238. Marshal_PolicyNV.c
  239. Marshal_PolicyNameHash.c
  240. Marshal_PolicyNvWritten.c
  241. Marshal_PolicyOR.c
  242. Marshal_PolicyPCR.c
  243. Marshal_PolicyPassword.c
  244. Marshal_PolicyPhysicalPresence.c
  245. Marshal_PolicyRestart.c
  246. Marshal_PolicySecret.c
  247. Marshal_PolicySigned.c
  248. Marshal_PolicyTicket.c
  249. Marshal_Quote.c
  250. Marshal_RSA_Decrypt.c
  251. Marshal_RSA_Encrypt.c
  252. Marshal_ReadClock.c
  253. Marshal_ReadPublic.c
  254. Marshal_Rewrap.c
  255. Marshal_SelfTest.c
  256. Marshal_SequenceComplete.c
  257. Marshal_SequenceUpdate.c
  258. Marshal_SetAlgorithmSet.c
  259. Marshal_SetCommandCodeAuditStatus.c
  260. Marshal_SetPrimaryPolicy.c
  261. Marshal_Shutdown.c
  262. Marshal_Sign.c
  263. Marshal_StartAuthSession.c
  264. Marshal_Startup.c
  265. Marshal_StirRandom.c
  266. Marshal_TestParms.c
  267. Marshal_Unseal.c
  268. Marshal_VerifySignature.c
  269. Marshal_ZGen_2Phase.c
  270. MathFunctions.c
  271. MathFunctions_fp.h
  272. MemoryLib.c
  273. MemoryLib_fp.h
  274. NV.c
  275. NVMem.c
  276. NV_Certify.c
  277. NV_Certify_fp.h
  278. NV_ChangeAuth.c
  279. NV_ChangeAuth_fp.h
  280. NV_DefineSpace.c
  281. NV_DefineSpace_fp.h
  282. NV_Extend.c
  283. NV_Extend_fp.h
  284. NV_GlobalWriteLock.c
  285. NV_GlobalWriteLock_fp.h
  286. NV_Increment.c
  287. NV_Increment_fp.h
  288. NV_Read.c
  289. NV_ReadLock.c
  290. NV_ReadLock_fp.h
  291. NV_ReadPublic.c
  292. NV_ReadPublic_fp.h
  293. NV_Read_fp.h
  294. NV_SetBits.c
  295. NV_SetBits_fp.h
  296. NV_UndefineSpace.c
  297. NV_UndefineSpaceSpecial.c
  298. NV_UndefineSpaceSpecial_fp.h
  299. NV_UndefineSpace_fp.h
  300. NV_Write.c
  301. NV_WriteLock.c
  302. NV_WriteLock_fp.h
  303. NV_Write_fp.h
  304. NV_fp.h
  305. NV_spt.c
  306. NV_spt_fp.h
  307. OWNERS
  308. Object.c
  309. ObjectChangeAuth.c
  310. ObjectChangeAuth_fp.h
  311. Object_fp.h
  312. Object_spt.c
  313. Object_spt_fp.h
  314. OsslCryptoEngine.h
  315. PCR.c
  316. PCR_Allocate.c
  317. PCR_Allocate_fp.h
  318. PCR_Event.c
  319. PCR_Event_fp.h
  320. PCR_Extend.c
  321. PCR_Extend_fp.h
  322. PCR_Read.c
  323. PCR_Read_fp.h
  324. PCR_Reset.c
  325. PCR_Reset_fp.h
  326. PCR_SetAuthPolicy.c
  327. PCR_SetAuthPolicy_fp.h
  328. PCR_SetAuthValue.c
  329. PCR_SetAuthValue_fp.h
  330. PCR_fp.h
  331. PP.c
  332. PPPlat.c
  333. PP_Commands.c
  334. PP_Commands_fp.h
  335. PP_fp.h
  336. PRESUBMIT.cfg
  337. Platform.h
  338. PlatformData.c
  339. PlatformData.h
  340. PolicyAuthValue.c
  341. PolicyAuthValue_fp.h
  342. PolicyAuthorize.c
  343. PolicyAuthorize_fp.h
  344. PolicyCommandCode.c
  345. PolicyCommandCode_fp.h
  346. PolicyCounterTimer.c
  347. PolicyCounterTimer_fp.h
  348. PolicyCpHash.c
  349. PolicyCpHash_fp.h
  350. PolicyDuplicationSelect.c
  351. PolicyDuplicationSelect_fp.h
  352. PolicyFidoSigned.c
  353. PolicyFidoSigned_fp.h
  354. PolicyGetDigest.c
  355. PolicyGetDigest_fp.h
  356. PolicyLocality.c
  357. PolicyLocality_fp.h
  358. PolicyNV.c
  359. PolicyNV_fp.h
  360. PolicyNameHash.c
  361. PolicyNameHash_fp.h
  362. PolicyNvWritten.c
  363. PolicyNvWritten_fp.h
  364. PolicyOR.c
  365. PolicyOR_fp.h
  366. PolicyPCR.c
  367. PolicyPCR_fp.h
  368. PolicyPassword.c
  369. PolicyPassword_fp.h
  370. PolicyPhysicalPresence.c
  371. PolicyPhysicalPresence_fp.h
  372. PolicyRestart.c
  373. PolicyRestart_fp.h
  374. PolicySecret.c
  375. PolicySecret_fp.h
  376. PolicySigned.c
  377. PolicySigned_fp.h
  378. PolicyTicket.c
  379. PolicyTicket_fp.h
  380. Policy_spt.c
  381. Policy_spt_fp.h
  382. Power.c
  383. PowerPlat.c
  384. Power_fp.h
  385. PropertyCap.c
  386. PropertyCap_fp.h
  387. Quote.c
  388. Quote_fp.h
  389. README
  390. RSAData.c
  391. RSAKeySieve.c
  392. RSAKeySieve.h
  393. RSAKeySieve_fp.h
  394. RSA_Decrypt.c
  395. RSA_Decrypt_fp.h
  396. RSA_Encrypt.c
  397. RSA_Encrypt_fp.h
  398. ReadClock.c
  399. ReadClock_fp.h
  400. ReadPublic.c
  401. ReadPublic_fp.h
  402. Rewrap.c
  403. Rewrap_fp.h
  404. SelfTest.c
  405. SelfTest_fp.h
  406. SequenceComplete.c
  407. SequenceComplete_fp.h
  408. SequenceUpdate.c
  409. SequenceUpdate_fp.h
  410. Session.c
  411. SessionProcess.c
  412. SessionProcess_fp.h
  413. Session_fp.h
  414. SetAlgorithmSet.c
  415. SetAlgorithmSet_fp.h
  416. SetCommandCodeAuditStatus.c
  417. SetCommandCodeAuditStatus_fp.h
  418. SetPrimaryPolicy.c
  419. SetPrimaryPolicy_fp.h
  420. Shutdown.c
  421. Shutdown_fp.h
  422. Sign.c
  423. Sign_fp.h
  424. StartAuthSession.c
  425. StartAuthSession_fp.h
  426. Startup.c
  427. Startup_fp.h
  428. StirRandom.c
  429. StirRandom_fp.h
  430. TPMB.h
  431. TPMCmdp.c
  432. TPMCmds.c
  433. TPM_Types.h
  434. TcpServer.c
  435. TestParms.c
  436. TestParms_fp.h
  437. Ticket.c
  438. Ticket_fp.h
  439. Time.c
  440. Time_fp.h
  441. Tpm.h
  442. TpmBuildSwitches.h
  443. TpmError.h
  444. TpmFail.c
  445. TpmFail_fp.h
  446. TpmTcpProtocol.h
  447. Unique.c
  448. Unique_fp.h
  449. Unseal.c
  450. Unseal_fp.h
  451. VendorString.h
  452. VerifySignature.c
  453. VerifySignature_fp.h
  454. ZGen_2Phase.c
  455. ZGen_2Phase_fp.h
  456. _TPM_Hash_Data.c
  457. _TPM_Hash_Data_fp.h
  458. _TPM_Hash_End.c
  459. _TPM_Hash_End_fp.h
  460. _TPM_Hash_Start.c
  461. _TPM_Hash_Start_fp.h
  462. _TPM_Init.c
  463. _TPM_Init_fp.h
  464. bits.h
  465. bool.h
  466. endorsement.c
  467. fuzz/
  468. libtpm2.pc.in
  469. marshal_fp.h
  470. marshal_test.c
  471. parsep3
  472. parsep4
  473. stubs_ecc.c
  474. stubs_hash.c
  475. stubs_sym.c
  476. swap.h
  477. thirdparty_preinstall.sh
  478. tpm_generated.c
  479. tpm_generated.h
  480. tpm_manufacture.c
  481. tpm_manufacture.h
  482. tpm_types.h