Makefile autogenerated by shell script for a given .c code file

Hi,

I have learned native compilation of basic c code example programs from the net.
The issue is, .c code file doesn't come with respective Makefile.
Visited some web sites with Makefile manuals but still can not master writing Makefile file to work.

The idea is to have intelligent shell script, generating working Makefile for a given .c code file, providing some interactive options (dialog menu or the like).

It's a part of my research work on human cognition process based software solutions (old AI school).

To say it just in few words:

  • moving Makefile manual rules from text to shell script code.

Could you give me your helpful hand ?

Darius

Have you looked at GNU autotools? GNU build system - Wikipedia, the free encyclopedia

Hi,

automake approach
Automake - Wikipedia, the free encyclopedia
Approach

Automake aims to allow the programmer to write a makefile in a higher-level language, rather than having to write the whole makefile manually. In simple cases, it suffices to give:

  • a line that declares the name of the program to build;
  • a list of source files;
  • a list of command-line options to be passed to the compiler (for example, in which directories header files will be found);
  • a list of command-line options to be passed to the linker (which libraries the program needs and in what directories they are to be found).

...
###########
My input to Automake:

a line that declares the name of the program to build;

  • replace by standard name + date
    a list of source files;
  • have a code to scan directory for source files

a list of command-line options to be passed to the compiler (for example, in which directories header files will be found);

  • automate this procedure

a list of command-line options to be passed to the linker (which libraries the program needs and in what directories they are to be found).

  • trace program for libraries required and search file system for directories, they are to be found.

########
So I assume, the above input can be autogenerated by intelligent Automake.

===================

thanks,
exactly what I was looking for.
In my case, Makefile for Helloworld, downloaded from the net
-----------------------------------------------------------

helloworld: helloworld.o
cc -o $@ $<

helloworld.o: helloworld.c
cc -c -o $@ $<

.PHONY: clean

clean:
rm -f helloworld helloworld.o
--------------------------------
replaced by command line

gcc helloworld.c -o helloworld

Makefile template for Linux dialog
# $Id:
makefile.in,v 1.62 2008/07/20 18:30:36 tom Exp $
# template makefile for DIALOG
#
SHELL = /bin/sh

srcdir = @srcdir@
VPATH = @srcdir@

prefix = @prefix@
exec_prefix = @exec_prefix@

top_builddir = .

x = @EXEEXT@
o = .@OBJEXT@
.....
5441 in size total.

Ok.
Makefile.in for dialog is lost, deleted.
Any way to have an intelligent Automake to autogenerate and recover
makefile.in and generate makefile automagically ?

====================
So, what is really needed is some kind of compiler, autoconf, that takes an Autoconf program, configure.ac, and transforms it into a portable shell script, configure.
GNU Autoconf, Automake and Libtool
Learning the GNU development tools: Preface
Automake - Wikipedia, the free encyclopedia

Learning the GNU development tools: Preface
5.3 Hello world example with Autoconf and Automake

To get started we will show you how to do the Hello world program using `autoconf' and `automake'. In the fine tradition of K&R, the C version of the hello world program is:
#include <stdio.h>
main()
{
printf("Howdy world!\n");
}
Call this `hello.c' and place it under an empty directory. Simple programs like this can be compiled and ran directly with the following commands:
% gcc hello.c -o hello
% hello

Just to follow steps done by a human and have them repeated by intelligent, interactive Automake.

Darius

Hi,
spent another day with Makefile and Gnuplot, shell scripting, larning gnuplot to read a script, to read output from shell script , to read data file and more.

One example I follow now
compiling basic .c code examples from the net is:

gcc helloworld.c -o helloworld

It doesn't work for another example .c code program from the net

[admin@oo helloworld]$ gcc squares.c -o squares
squares.c: In function 'main':
squares.c:8: error: expected expression before '=' token
[admin@oo helloworld]$

---------
squares.c code is
what is wrong ?
--------------
#include <stdio.h>
main() {
double x;
FILE *datafile;

datafile = fopen("squares.dat","w");

for(x = 0.0; x < = 4.0; x += 1.0)
fprintf(datafile, "%4.1f %4.1f\n", x, x * x);

fclose(datafile);
}

This program should create data file to be read by gnuplot.

source
Introductory Graphing
Here is a C program to create this file.

(see above)

Darius

Thank you for your post, it is a bit hard for people to understand you. Could you be very specific about how we can help you, one question at a time? Thanks.

Thanks my friend.
There is nothing complicated in asking basic questions.
I will try to describe you the issue.
I have been living on the Internet for the last 20 years
and expected to access some learning technologies to learn faster what I need for some research projects I am working on.

Example:1
about you:
----------------------
Join Date: Sep 2000
Location: Asia Pacific
Posts: 4,666

4,666 posts in only 8 years.
You must be both Sheel Programming and Scripting expert and guru.
You are smart and there is no more chance to read or view all of your posts.

Example: 2

My efforts to learn basic of Gnuplot.
I have visited via Google about 20 web sites devoted to Gnuplot.
Both manuals , FAQ, examples , papers ..
and spend more than 24 hours reading and testing gnuplot examples.

Could you tell me how to access 1-page abbriged gnuplot manual, just basics:
few examples for dumb terminal,
how to plot from data file input
how to plot from live data stream
how to plot from shell, perl, javascript, php script
how to write plot macro as a script

So what I am really interested in, is 1-page manual.
Otherwide I visit interesting web pages, each 20-50 pages long
and extract and extract what I really need for tests, to build
1-page manual of interest to me.

The same with c code examples.
Some come with Makefile, some don't, just zipped directory of files.

In the last few days tried to compile Linux dialog
and curses.h is missing
ncurses-devel
not compiled yet. for my Linux embedded device.

I can ask you, others to help me or look for 1-page HowTo manual to get help on myself.

That's the problem.
Visiting Google I get access to hundreds of web pages devoted to gnuplot, Linux dialog, Shell scripting.
But what I really need is 1-page HowTo manual
or good answer to my HowTo question.

As people are busy answering hundreds of questions, and to get the right answer promptly is not easy, my solution to this problem is to extract just what counts from 100-page manuals.

In the case of shell programming and scripting forum with thousands of questions asked over and over again, such an organization of archives with already answered questions, to keep text as short as possible
and questions aggregated by categories, tags.

Tag cloud is still not a solution to your 489 pages long archives.

I am sure, the same question, asked by me, have been already asked and got answered hundreds of times in the past at this or another place.
On Usenet, other web sites, mayby on Google Groups or the like.

And I work really hard to find answers to my questions on the net before asking them on your forum.
Mayby I am wrong, but referring me to a right place is as good as giving me a right answer.

So human-based Google-like search engine is exactly what I am looking for.

As you claim that it takes humans some time to understand a question asked in fully, so mayby there is a way to replace humans by
some algorithms, generating such abriged 1-page manuals
for a question asked ( knowledge extraction from Google scanned, indexed
and ranked virtual libraries).

If you are aware of any such solution, please let me know.

Darius