PDA

View Full Version : linux / unix makefiles



WebmasterMattD
05-01-2002, 02:58 AM
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,

Hammer
05-01-2002, 03:41 AM
I'm not too up on make, but here's an attempt that might work (yep, it's untested!)




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?

JasonLikesJava
05-01-2002, 11:20 AM
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.

Lynux-Penguin
05-01-2002, 05:27 PM
#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/

WebmasterMattD
05-02-2002, 02:48 AM
Cool,

thanks for you help peoplez.

Later,