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