$40
Assignment One
Create a Directory Top
Under this create 4 sub directories 1,2,3 4
In each of these sub directories, create a small C function: An example is given below:
./Top/1/mySqr.c
int mySquare(int x){
return x*x;
}
./Top/2/myPythonInC.c
#define PY_SSIZE_T_CLEAN
#include <Python.h
int myPythonInC(int argc, char *argv[])
{
wchar_t *program = Py_DecodeLocale(argv[0], NULL); if (program == NULL) {
fprintf(stderr, "Fatal error: cannot decode argv[0]\n"); exit(1); }
Py_SetProgramName(program); /* optional but recommended */
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
"print('Today is', ctime(time()))\n"); if (Py_FinalizeEx() < 0) { exit(120);
}
PyMem_RawFree(program);
return 0;
}
And similarly with other programming languages or scripts in sub directories 3 and 4.
Write the application in the parent directory --- something similar to the following:
./Top/myApp.c
#include <stdio.h
extern mySquare(); extern myPythonInC();
int main(int argc, char *argv[]){
int a=3,b;
b= mySquare(a); printf("%d\n",b); myPythonInC(1,argv);
}
Have a makefile in each directory of this hierarchy. The Makefile in ./Top should recursively call make in all the sub directories.
Do’s:
Create object files in a subdirectory called obj
Create final executable in a subdirectory called exe
Set global options only in the parent
Have multiple targets in your makefile (for example clean, all, RUN, only certain functions etc –be creative J )
Brownie Points:
Use shell creatively
Don’ts:
Have a single Makefile replicated in all directories.
Notes:
Compilation string for python embedding in C (this is machine specific)
-I/usr/include/python3.6 -lpython3.6m