-
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,
-
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?
-
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.
-
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/
-
Cool,
thanks for you help peoplez.
Later,