Jan 13, 2017 09:33 PM
(This post was last modified: Jan 13, 2017 09:43 PM by g4143.)
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
doubleit.c
tripleit.h
tripleit.c
main.c
makefile
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.
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.cNow 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.


