[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

how to advice please : rules with dependencies created in commands

Subject: how to advice please : rules with dependencies created in commands
Date: Fri, 5 May 2006 07:26:41 -0500

Here's the problem described as simple as I can.  The real version deals
with Oracle 8 and much more complex.   But I think this simple version
will demonstrate the problem.
2 existing files : prog_1.c , prog_1.h
After compilation prog_1 create N files (.c,.h,.sql,...) based on input.
For this example it will be command line input.  real world is parameter
file.  My example only goes 2 level deep. My real world goes 4 levels

In a nutshell
target : prereq_1 prereq_2
 (COMMAND) > prereq_2

So here's what I do now to create another .c and a .h file
gcc -o x prog_1.c
x prog_2

Now in the directory I have prog_2.c and prog_2.h

So now how do I arrange a makefile so that I have the dependencies
captured for prog_2.c

We have to prove in a demo that we can accomplish all dependencies.

Here's what I can conceive
# may be 1 to N values. represented here as var, 
#but in real world is a parameters file passed to prog_1
INPUT_X : prog_2 prog_3 prog_4

.PHONY: all
all : x

#$(INPUT_X) does not exist until the commands for rule x fire
x : prog_1.c prog_1.h $(INPUT_X)
  gcc -o $@ $<
  for f in $(INPUT_X)
    $@ $$f

#So how can rule x depend on prog_{2,3,4} until 
#rule x has treated them
define xxx
$(1) : $(1).c $(1).h
  gcc -o $@ $<
$(foreach x,$(INPUT_X),$(eval $(call xxx,$(x))))


if I make the define dependent on x then that would, sort of, create a
circular dependency.

here is the c and .h source code I wrote for testing.

#include <stdio.h>
#include "prog_1.h"

long bogus = 0;

int main(int argc,char** argv)
  char s[16];
  FILE* fp;
  fp = fopen(s,"w");
  fprintf(fp,"#include <stdio.h>\n#include \"%s.h\"\nlong bogus =
  fprintf(fp,"int main(int argc,char** argv)\n");
  fprintf(fp,"{ printf(\"hello world from %%s\\n\",argv[0]); }\n");
  fp = fopen(s,"w");
  fprintf(fp,"#ifndef %s_h\n",argv[1]);
  fprintf(fp,"#define %s_h\n",argv[1]);
  fprintf(fp,"extern long bogus;\n");

#ifndef prog_1_H

extern long bogus;

#define prog_1_H

reply via email to

[Prev in Thread] Current Thread [Next in Thread]