Hack Forums
[C] Fun Makefile Challenge - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C] Fun Makefile Challenge (/showthread.php?tid=5522961)



Fun Makefile Challenge - g4143 - Jan 13, 2017

Fun Makefile Challenge...

Can you create a simple makefile program which will take a simple makefile(no macros and no date/time checks) and make the contents of the makefile? Basically you have to write a program which will parse a simple makefile and then do each of the steps of the makefile.

Here's an example to work from:

doubleit.h
Code
int double_it(int);

doubleit.c
Code
int double_it(int x){
    return x * 2;
}

tripleit.h
Code
int triple_it(int);

tripleit.c
Code
int triple_it(int x){
    return x * 3;
}

main.c
Code
#include <stdio.h>

#include "doubleit.h"
#include "tripleit.h"

#define VALUE 12345

int main(int argc, char ** args){

    fprintf(stdout, "%d\n", double_it(VALUE));
    fprintf(stdout, "%d\n", triple_it(VALUE));

    return 0;
}

makefile
Code
main: main.o doubleit.o tripleit.o
    gcc -o main main.o doubleit.o tripleit.o

main.o: main.c
    gcc -c main.c

doubleit.o: doubleit.c
    gcc -c doubleit.c

tripleit.o: tripleit.c
    gcc -c tripleit.c

Now copy all the files to your system and then write a program which will parse the makefile and preform each of its steps to produce a exe called main.

Note: This example uses the gcc compiler so you may have to modify the makfile if you use another compiler.

Also: The solution for the makefile program can be written in any language.


* - HFDone - Jan 14, 2017

like you say its just simple parse with checks and cmd run
im too lazy forgive me ...


* - g4143 - Jan 14, 2017

(Jan 14, 2017 01:21 PM)HFDone Wrote:  like you say its just simple parse with checks and cmd run
im too lazy forgive me ...

Interesting reply... Its just simple but I'm too lazy.... Not too lazy for a post.


* - 0xDEAD10CC - Jan 14, 2017

This isn't really a challenge it's just time, but involves nothing but simple filesystem IO and process creation with arguments.


* - g4143 - Jan 14, 2017

(Jan 14, 2017 09:07 PM)0xDEAD10CC Wrote:  This isn't really a challenge it's just time, but involves nothing but simple filesystem IO and process creation with arguments.

Then by all means post a 'non-challenge' solution. Remember it has to function as a simple makefile utility which can take any number of files and create an executable.

Odd how people will take the time to gripe but not try a solution.


* - Annabelle Lee - Jan 14, 2017

Wouldn't the program simply be just reading the file and then calling other programs in order to actually do the compiling and linking? That's what I understood from it.


* - g4143 - Jan 14, 2017

(Jan 14, 2017 09:38 PM)AnnabelleLee Wrote:  Wouldn't the program simply be just reading the file and then calling other programs in order to actually do the compiling and linking? That's what I understood from it.

If you understand the basic concepts of a Makefile(minus checking for date/time stamps and macros) then you will get the basic of it. Basically a makfile will compile a list of source files in the proper order to create some final executable(s).


* - 0xDEAD10CC - Jan 15, 2017

(Jan 14, 2017 09:42 PM)g4143 Wrote:  If you understand the basic concepts of a Makefile(minus checking for date/time stamps and macros) then you will get the basic of it. Basically a makfile will compile a list of source files in the proper order to create some final executable(s).

By "basic" concept of a makefile your example would require you to check the object file's existence, and calling gcc with the proper arguments. That's why I'm not doing this, it's personally not an interesting thing for me to spend my time on and to re-create a basic and limited version of make.exe.

Good luck to those that try this though anyways.


* - g4143 - Jan 15, 2017

(Jan 15, 2017 12:39 AM)0xDEAD10CC Wrote:  By "basic" concept of a makefile your example would require timestamp checks among other things for those object files if not just a basic filesystem existence check... Aside from that you're just calling gcc with the proper arguments. That's why I'm not doing this, it's personally not an interesting thing for me to spend my time on and to re-create a basic and limited version of make.exe.

Well then don't do it. Why do people feel the need to explain their lack of interest in a volunteer challenge? It's volunteer. It's not required and you don't need written permission to be excused from this exercise.


* - 0xDEAD10CC - Jan 15, 2017

(Jan 15, 2017 12:52 AM)g4143 Wrote:  Well then don't do it. Why do people feel the need to explain their lack of interest in a volunteer challenge? It's volunteer. It's not required and you don't need written permission to be excused from this exercise.

I'm explaining the procedure required to do this challenge for if anyone actually tries this, which had led me to the point of why I am not interested, and even more likely why nobody else has attempted this... How about you do it in the proper language for this forum? (C/C++, or Obj-C)