View being textual's sins from makefile

Source: Internet
Author: User

After reading the GNU Make project management for several days,
Makefile rules are simple, but creating a makefile that can really work effectively is definitely beyond the imagination of most people.
Target of Makefile:
1. you do not need to manually specify the dependency between files (that is. cpp and. h file, and. others contained in the H file. the dependency between files ).
2. After rm is a file in the project, makefile can automatically maintain the dependency between files (these relationships are recorded in makefile ).
In order to achieve these two goals, this book discusses and proposes several solutions, but there are all kinds of shortcomings. Although the final solution can work, however, the traces of hack are too obvious, and even to support this trick (that is, to add an imaginary empty target for each prerequisites, which was invented by the automake team ), even gcc has added an inexplicable option-MP (hack Ah hack ).
If main. cpp contains f. h, the dependency between main. cpp and f. h should be recorded.
If main. cpp is dependent on f. h, but f. h is removed from the project, the dependency between main. cpp and f. h should be removed.
Where is the dependency record? Makefile.
These dependencies are automatically generated because the workload specified manually is too large.
The work of removing some dependencies is also automatic (manual work is to rm the file on which other files are dependent from the directory.
The so-called automatic mode is implemented by makefile itself.
Depending on dependencies, maintain dependencies. Currently, makefile is used for these two tasks.
In addition, if you want to run make only once, you can do everything:
Update the dependency under the guidance of the dependency, and then follow the updated dependency.
That is:
Under the guidance of makefile, update the makefile (in fact, it is the. d file that records dependencies in the update include), and then follow the updated makefile to do things.
To achieve the first goal, make will repeat it again after updating the dependency (although it was clever to solve the problem again later, but it was too "clever ).
To achieve the second goal, gcc adds an inexplicable option-MP in the identity 108,000 with the C ++ compiler.
Makefile is very heavy ~
It doesn't matter if the burden is heavy. The computer is doing it. The key is its hack, which cannot be tolerated.
Why not separate these tasks?
For example, a special program (named remove-from-project) is used to remove related items from the makefile that records dependencies.
Use add-to-project to add a new file to makefile.
It is easy to do this in the IDE with the project management function.
It is also easy to do in the command line.
But the problem is that the makefile is too casual.
Add-to-project and remove-from-project can assume that the information required by makefile will not be completely changed?
It cannot.
Not only can add-to-project and remove-from-project be modified, but any common text editor is always in Eric S. raymond added and deleted it under the guidance of Being Textual.
Poor makefile, It is not
Class Makefile {
Public:
Void add_to_project (fname );
Void remove_from_project (fname );
Private:
...
};
It's something someone can change.
Struct Makefile {
...
};
In fact, the sin lies not in Being Textual (Be not Being Textual itself is the implementation details), but in Being Textual's purpose:
"Enable normal text editors to edit them ".

========================================================== ========================================================== ==========
Note: It's.
About four years ago (when I wrote the above content), I was scared by makefile.
Therefore
When I still don't know scons, I also tried to make something similar with python (epm, address: http://sourceforge.net/apps/mediawiki/epm/index.php? Title = % E4 % B8 % AD % E6 % 96% 87% E5 % 85% A5 % E5 % 8F % A3 ). Over the past few years, my own C ++ project, ranging from a single file to hundreds of files, has been managed using the PMNs. Of course, this is just because of zookeeper, and it cannot be compared with scons in all aspects (if I knew scons at the time, there would be no such thing ). However, let's take a look at my comments on makefile.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.