MIT License – How to Mark Code Lines

licensingmit-license

When I am using some code licensed with the MIT license, but it's not in seperate files, is it OK mark it like this?

/* Here starts code licensed under the MIT License (../MIT.txt) */
// code
/* Here is the end of code licensed under the MIT License (../MIT.txt) */

Where in ../MIT.txt file, it would contain the MIT License text and the original author's copyright notices.

Also, when most of code is MIT licensed and I'm only changing some sections of the functions can I mark those parts with the same method as above but with my own license? Yes, it's going to be a lot of kilobytes of comments.

Best Answer

When you use MIT-licensed code in a non-MIT-licensed project, simply marking the MIT-licensed parts of the source code is not a good strategy. The license allows you to do just about anything with the code – including sublicensing the code –, under this one restriction:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

Note that the MIT license should also be displayed to the end user of your software. Where you display your copyright to the user, you should also add something like

This program includes code from the FooBar library, used under the following license:

The "FooBar" library  
Copyright (c) <year> <copyright holders>

<license body>

In addition, you might want to explicitly mark the sections in the code that were taken from an MIT-licensed source. From my understanding, this is not required, but it would be ethical.

When you modify an MIT-licensed source, you should not mark your contributions with a separate license, because this requires an user of the source to follow both the original license and your license. Instead, choose one of the following options:

  • License your contributions under the same license as the rest of the code. You can edit the copyright notice to reflect that you contributed to the source, without marking what exactly you changed.
  • Re-license the MIT-licensed source under your license, in a manner permitted by the MIT license. See above.

Notes:

  • I'm a programmer, not a lawyer.
  • The term “MIT license” is fairly ambiguous. This answer assumes the Expat License, but is also applicable to the X11 License.