help-make
[Top][All Lists]
Advanced

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

RE: how to advice please : rules with dependencies created in commands


From: PATTON, BILLY \(SBCSI\)
Subject: RE: how to advice please : rules with dependencies created in commands
Date: Fri, 5 May 2006 09:12:13 -0500

Here I have a makefile that will create all programs and their
dependencies.
Problem now is that I don't know how to have top program have dependency
on something that it creates based on the value of a variable.
Obviously prog_1 : $(CREATE) would fail.  They are created by prog_1
.PHONY: all
SRCS     := prog_1.c
CREATE   := prog_2 prog_3 prog_4
all     : prog_1

MAKEDEPEND = /opt/langtools/lbin/cpp.ansi -M -E $< \
             | sed -n 's/^\# *[0-9][0-9]* *"\([^"]*\)".*/$*.o: \1/p' \
             | sort | uniq > $*.d
MAKEDEPEND2 = /opt/langtools/lbin/cpp.ansi -M -E $$f.c \
             | sed -n 's/^\# *[0-9][0-9]* *"\([^"]*\)".*/$*.o: \1/p' \
             | sort | uniq > $$f.d

prog_1 : $(SRCS:.c=.o)
        @gcc -o $@ $?
        @for f in $(CREATE) ; do \
          $@ $$f ; \
          $(MAKEDEPEND2); \
          sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
              -e '/^$$/ d' -e 's/$$/ :/' < $$f.d >> $$f.P; \
          rm -f $*.d ; \
          gcc -c -o $$f $$f.c ; \
        done

-include $(addsuffix .P,$(CREATE))

%.o : %.c
        @$(MAKEDEPEND); \
        cp $*.d $*.P; \
        sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
            -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $*.P; \
        rm -f $*.d ; \
        gcc -c -o $@ $<

-include $(SRCS:.c=.P)

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

long bogus = 0;

int main(int argc,char** argv)
{
  char s[16];
  FILE* fp;
  sprintf(s,"%s.c",argv[1]);
  fp = fopen(s,"w");
  fprintf(fp,"#include <stdio.h>\n#include \"%s.h\"\nlong bogus =
0;\n",argv[1]);
  fprintf(fp,"int main(int argc,char** argv)\n");
  fprintf(fp,"{ printf(\"hello world from %%s\\n\",argv[0]);
return(0);}\n");
  close(fp);
  sprintf(s,"%s.h",argv[1]);
  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");
  fprintf(fp,"#endif\n");
  close(fp);
  return(0);
}

__HEADER__

#ifndef prog_1_H
#define prog_1_H
extern long bogus;
#endif





reply via email to

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