This question is not opinion-based - I am looking for objective drawbacks to the easy approach that I know may not be ideal, but seems quite alright prima facie.
EDIT: I do not mean to imply that in some way I am writing my own Make in C - no, I'm only wondering if, in simple and small programs, this sort of approach has any drawbacks over make.
Now, the question.
C is a general purpose, systems-programming oriented language, so it is safe to assume that one can hack-together anything with it.
Of course, we have different languages and tools allowing us to use the best tool for the job, and Makefiles are specifically for compiling efficiently and with least hassle - this I get.But, one can basically do with C what they do with a makefile - and apparently with no more difficulty !?
Apart from 'not using industry standards', what objective drawbacks does such an approach bring ?
A bad 2-minute sample, by no means perfect or finished, and without the file-selective compilation, but just to kind of illustrate my point -
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("\n Mode : "); int mode; scanf("%d",&mode);
if(mode==1){
system("cc -Wall -o3 file1.c file2.c -o bin_file_name");
}
else if(mode==2){
system("cc -Wall -Wextra -pedantic -Wconversion -o0 file1.c file2.c -o bin_file_name");
}
return 0;
}
You could write a C program which efficiently builds a given project. This is what you shown code seems to imply.
For more complex projects that would of course be more complex.
Soon you would develop your program to do some analysis (e.g. dependencies) automatically, instead of hardcoding it each time.
Then you would discover, that from project to project, those analysis need to take different, project-specific, concepts and structures into account.
That would introduce the concept of project-specific configuration into your program.
At that point you would have reinvented the make tool, with its project-specific configuration done in files like makefiles.
make does many things more than your toy example does. Here are just a few of the most common:
Getting all these details right is complex. Why would you want to spend time writing your own program to do these, when what you really want to work on is your application? And you would have to write a new one of these programs for every project.
Of course, each of these programs would be very similar. You would probably write a library of functions to handle the common tasks. Guess what -- your library would be doing what make already automates.
You can also do what awk and sed do by writing C programs. But the whole point of creating tools is that they automate tasks that lots of different people have to do the same way.
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