I'm writing a C program using gcc in cygwin. My question is, how do you create a makefile? I mean, what file-extension does it have? I know how to write simple rules, but I can't save a file in the text-editor with the right extension? Impossible to find any info about this... This is prolly a super-newbie question. So let the flaming begin. :-P
Activating the extensionUpdate Makefile Path by going to File > Preferences > Settings and then selecting makefile under Extensions. After updating Makefile Path, type “makefile” into the Command Palette and run a Makefile Tools command to activate the extension.
A makefile is a text file that contains instructions for how to compile and link (or build) a set of source code files. A program (often called a make program) reads the makefile and invokes a compiler, linker, and possibly other programs to make an executable file.
Open a Makefile projectSelect File | Open from the main menu. In the dialog that opens, click Open as Project. Cleaning is required for the project load as the Make build is incremental and only the updated files are compiled.
If your installation of make is not available in the default path, you can configure it in VS Code at File > Preferences > Settings > Extensions makefile. To compile and link the project, you can add a Makefile to the root of the project folder. It will be detected automatically by the extension.
As you are using Cygwin which in turn means that you are using GNU make, I cite the relevant portion of the GNU make manual:
3.2 What Name to Give Your Makefile
By default, when make looks for the makefile, it tries the following names, in order: GNUmakefile, makefile and Makefile. Normally you should call your makefile either makefile or Makefile. (We recommend Makefile because it appears prominently near the beginning of a directory listing, right near other important files such as README.) The first name checked, GNUmakefile, is not recommended for most makefiles. You should use this name if you have a makefile that is specific to GNU make, and will not be understood by other versions of make. Other make programs look for makefile and Makefile, but not GNUmakefile.
[...]
If you want to use a nonstandard name for your makefile, you can specify the makefile name with the ‘-f’ or ‘--file’ option. The arguments ‘-f name’ or ‘--file=name’ tell make to read the file name as the makefile. If you use more than one ‘-f’ or ‘--file’ option, you can specify several makefiles. All the makefiles are effectively concatenated in the order specified. The default makefile names GNUmakefile, makefile and Makefile are not checked automatically if you specify ‘-f’ or ‘--file’.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With