A Turkish court has handed life sentences to 40 people convicted of plotting to assassinate President Recep Tayyip Erdogan during last year's failed coup attempt.