Professional Web Applications Themes

How to include header files in makefiles - FreeBSD

Hi all, I'm setting up a build system for a small project and I want to use included makefiles. I have a base.mk that looks like this: ..PATH.h : ../ ../include ..INCLUDES : .h CFLAGS = -O -pipe -Wall -g CFLAGS += $(.INCLUDES) OBJS = ${SRCS:R:S/$/.o/g} and a bin.mk that looks like this: include ../include/mk/base.mk all: ${BIN} ${BIN}: ${OBJS} ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} so that a makefile for a specific program looks like this: BIN = app SRCS = app.c LDFLAGS += -pthread include ../include/mk/bin.mk But I'm having a problem figuring out how to handle header files. I have ...

  1. #1

    Default How to include header files in makefiles


    Hi all,

    I'm setting up a build system for a small project and I want to use included
    makefiles. I have a base.mk that looks like this:

    ..PATH.h : ../ ../include
    ..INCLUDES : .h

    CFLAGS = -O -pipe -Wall -g
    CFLAGS += $(.INCLUDES)

    OBJS = ${SRCS:R:S/$/.o/g}

    and a bin.mk that looks like this:

    include ../include/mk/base.mk

    all: ${BIN}

    ${BIN}: ${OBJS}
    ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC}

    so that a makefile for a specific program looks like this:

    BIN = app
    SRCS = app.c
    LDFLAGS += -pthread
    include ../include/mk/bin.mk

    But I'm having a problem figuring out how to handle header files. I have
    some that are local to this binary, but others are in the project include
    directory.

    How can I include the .h files so the .c files are recompiled when the
    header files they require are changed? GNU make has 'make depend' but I'd
    like a better, BSDmake-centric way, if possible.

    Thanks for your help,

    jm
    --
    Jonathon Guest

  2. #2

    Default Re: How to include header files in makefiles

    Jonathon McKitrick wrote: 

    I will answer here, but be aware that you're getting all of my
    prejudices too, so take things with a grain of salt.

    First item deals with the .path statements, and more specifically, your
    use of relative addressing. It's my own experience that, if you use
    relative addressing, you make troubleshooting a broken build much more
    difficult, because

    1) relative addressing means you have to be forever translating paths in
    listings, and very often the number of include paths gets to be rather long.
    2) all the stuff like "../.." in listings is quite difficult to read
    3) with the $(.CURDIR) variable, it's extremely easy to use absolute
    addressing. You can also make use of $(.OBJDIR), and it's not so hard
    to make makefiles that work off of read-only sources like cdroms.

     

    The Make(1) man page doesn't show "include", the advertised command is
    ".include". If you use .include, then you can modify your make, if you
    want, with the -m argument, and so get specific directories to be added
    to the search path for make include files. I'm not sure, but I think
    that raw "include) is more a gmake item, and it's absolute addressing.
    Don't forget the "-" argument, so that you allow includes to fail if
    they need to, like for generating dependencies.
     

    Well, did you look at the files in /usr/share/mk, and specifically
    bsd.dep.mk? You can even use the FreeBSD sources to figure out (to use
    as examples) how things should work.

    Don't forget the use of -m, because you can use it to add to the include
    directory list, and so be able to add your own include files without
    corrupting the system files.

    I honestly keep on switching back and forth, between thinking that the
    best make is bmake, or gmake. They both have key items that make them
    uniquely better.
     

    Chuck Guest

  3. #3

    Default Re: How to include header files in makefiles

    On Fri, Mar 18, 2005 at 04:38:15PM +0000, Chuck Robey wrote:
    : 1) relative addressing means you have to be forever translating paths in
    : listings, and very often the number of include paths gets to be rather long.

    Okay, I can fix that easily.

    : The Make(1) man page doesn't show "include", the advertised command is
    : ".include". If you use .include, then you can modify your make, if you

    Also fixable.

    : >How can I include the .h files so the .c files are recompiled when the
    : >header files they require are changed? GNU make has 'make depend' but I'd
    : >like a better, BSDmake-centric way, if possible.
    :
    : Well, did you look at the files in /usr/share/mk, and specifically
    : bsd.dep.mk? You can even use the FreeBSD sources to figure out (to use
    : as examples) how things should work.

    This is the key I want to get working. I'll take a look at those files, but
    they are pretty deep.

    : I honestly keep on switching back and forth, between thinking that the
    : best make is bmake, or gmake. They both have key items that make them
    : uniquely better.

    I haven't decided yet. Most BSD people are (predictably) anti-gmake. I
    have to use gmake for a Linux project I'm on.

    Jonathon McKitrick
    --
    My other computer is your Windows box.
    Jonathon Guest

Similar Threads

  1. Pls include build # in your subject header
    By Vista in forum Windows Vista
    Replies: 11
    Last Post: March 28th, 12:31 PM
  2. Replies: 3
    Last Post: July 30th, 02:02 PM
  3. include() header and footer
    By Jez in forum PHP Development
    Replies: 3
    Last Post: July 12th, 04:52 PM
  4. header/include files and compilers
    By Johnny Shih in forum UNIX Programming
    Replies: 1
    Last Post: July 5th, 02:43 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139