home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / unix / question / 10480 < prev    next >
Encoding:
Text File  |  1992-08-29  |  1.7 KB  |  64 lines

  1. Path: sparky!uunet!mcsun!uknet!doc.ic.ac.uk!syma!william
  2. From: william@syma.sussex.ac.uk (William Craven)
  3. Newsgroups: comp.unix.questions
  4. Subject: Using C macros in Makefiles
  5. Keywords: C Macros Make Makefiles
  6. Message-ID: <1992Aug24.132028.23314@syma.sussex.ac.uk>
  7. Date: 24 Aug 92 13:20:28 GMT
  8. Organization: University of Sussex
  9. Lines: 54
  10.  
  11. The Makefile below creates two programs  server  and  client  - and they
  12. both share common C source codes. However the common C source codes now have
  13. preCompiler defines which are based on whether the code being compiled is
  14. for the  server  or for the  client. How can I set up a macro such that
  15. make will provide the correct define flag for the C compiler ?  At present
  16. the defines are passed only at loading phase not during compilation.
  17. Will I have to rewrite the suffix macro for .o.c ?
  18.  
  19. Ideas most appreciated and I will summarise if anybody has solutions.
  20.  
  21. Many Thanks .......
  22.  
  23. William Craven                william@central.sussex.ac.uk
  24. UNIX Systems, Computing Service      or william@syma.sussex.ac.uk
  25. University of Sussex
  26. Brighton, UK
  27.  
  28.  
  29. #
  30. # Makefile for rsvcRPC system
  31. #
  32.  
  33. RSVCSRC = rsvc_common.c rsvc_xdr.c
  34. RSVCOBJ = rsvc_common.o rsvc_xdr.o
  35. RSVCINC = rsvc.h
  36.  
  37. SRVRSRC = rsvc_server.c ${RSVCSRC}
  38. SRVROBJ = rsvc_server.o ${RSVCOBJ}
  39. SRVRINC = ${RSVCINC}
  40. SRVRFLG = -DrsvcSERVER
  41.  
  42. CLNTSRC = rsvc_client.c ${RSVCSRC}
  43. CLNTOBJ = rsvc_client.o ${RSVCOBJ}
  44. CLNTINC = ${RSVCINC}
  45. CLNTFLG = -DrsvcCLIENT
  46.  
  47. CC = cc
  48. CFLAGS =
  49.  
  50. all:    server client
  51.  
  52. server: ${SRVROBJ}
  53.     ${CC} ${CFLAGS} ${SRVRFLG} -o server ${SRVROBJ}
  54.  
  55. ${SRVROBJ}: ${SRVRSRC} ${SRVRINC}
  56.  
  57. client: ${CLNTOBJ}
  58.     ${CC} ${CFLAGS} ${CLNTFLG} -o client ${CLNTOBJ}
  59.  
  60. ${CLNTOBJ}: ${CLNTSRC} ${CLNTINC}
  61.  
  62. clean:
  63.     rm -f *.o server &&& reUs
  64.