linux / unix makefiles

This is a discussion on linux / unix makefiles within the Linux Programming forums, part of the Platform Specific Boards category; Okay I have written a program that is ready to be distributed. The only problem though is that I am ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    110

    linux / unix makefiles

    Okay I have written a program that is ready to be distributed.

    The only problem though is that I am unsure as to how I would go about createing a makefile so that people would be able to type:

    make myfilename

    instead of:

    gcc -o outputfile servarl.input.files.c -L/path/to/lib -lsomelib (and so on and so forth).

    Thanks for you help.

    Later,
    WebmasterMattD
    WebmasterMattD.NET

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    I'm not too up on make, but here's an attempt that might work (yep, it's untested!)

    Code:
    CC = gcc
    APP = outputfile
    
    SRC = input.file1.c input.file2.c input.file3.c
    
    LIBS = "-Lsomelib -Lanotherlib"
    
    LIBPATHS = "-L/path/to/lib"
    
    all: ${SRC}
    	$(CC) -o$(APP) ${LIBPATH} ${LIBS} $(SRC)
    You can then do make all. Well, thats the theory anyway
    Comments anyone?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User JasonLikesJava's Avatar
    Join Date
    Mar 2002
    Posts
    175
    CC = gcc
    APP = outputfile

    SRC = input.file1.c input.file2.c input.file3.c

    LIBS = "-lsomelib -lanotherlib"

    LIBPATHS = "-L/path/to/lib"

    $(APP): input.file.1.o input.file.2.o input.file.3.o
    :::tab:::$(CC) -o $(APP) ${LIBPATHS} ${LIBS} input.file.1.o input.file.2.o input.file.3.o

    input.file.1.c: header.h or_any_files_that_this_on_depends_on.o
    :::tab:::$(CC) -o input.file.1.o ${LIBPATHS} ${LIBS} input.file.1.c

    input.file.2.c: header.h or_any_files_that_this_on_depends_on.o
    :::tab:::$(CC) -o input.file.2.o ${LIBPATHS} ${LIBS} input.file.2.c

    input.file.3.c: header.h or_any_files_that_this_on_depends_on.o
    :::tab:::$(CC) -o input.file.3.o ${LIBPATHS} ${LIBS} input.file.3.c

    all: ${SRC}
    $(CC) -o $(APP) ${LIBPATHS} ${LIBS} $(SRC)

    This makefile will only compile (I hope :::untested:: the objects whose sources have been changed, which is good for large projects.

    running:
    $info make

    and looking at the simple sample makefile helped me a lot and it may help you understand makefiles a lot better.
    Last edited by JasonLikesJava; 05-01-2002 at 11:26 AM.

  4. #4
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    Code:
    #sample make file
    
    appname: appsrc1.c appsrc2.c appsrc3.c
    	gcc -o appname -llibraryhere -Wall appsrc1.c appsrc2.c appsrc3.c
    http://docs.linux.cz/gnumake/
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    110
    Cool,

    thanks for you help peoplez.

    Later,
    WebmasterMattD
    WebmasterMattD.NET

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. UNIX (Linux, BSD, etc) Programming :: UNIX
    By kuphryn in forum Linux Programming
    Replies: 6
    Last Post: 04-01-2004, 07:44 PM
  2. Unix Linux?
    By Coder87C in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 11-30-2003, 07:44 AM
  3. programming linux with gcc, emacs, and makefiles
    By Captain Penguin in forum Linux Programming
    Replies: 1
    Last Post: 11-02-2002, 11:04 AM
  4. C in Windows comparing Unix & Linux?
    By Hee Jeong in forum Windows Programming
    Replies: 1
    Last Post: 01-16-2002, 02:03 AM
  5. Differences b/w Unix and Linux
    By OS Idiot in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 12-15-2001, 08:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21