Hi /wsr/,
I'm trying to write a Makefile for my little C project which is made by a small library and a smaller program.
Let's say I have the following tree in the root of my project:
Makefile
libmeme/Makefile
libmeme/libmeme.c
libmeme/libmeme.h
pepethefrog/Makefile
pepethefrog/pepethefrog.c
What I want to achieve:
* The Makefile in the project will compile (and install) libmeme and pepethefrog calling their Makefile
* It must be possible to compile (and install) libmeme and pepethefrog on their own using their own Makefile
* The current working directory will be used for building, unless specified WORKDIR=, so that i can mkdir build && cd build && make -f ../Makefile or just make WORKDIR=/tmp
What I have achieved so far:
→ Makefile in the root of the project:
[code]export BASEDIR= $(dir $(lastword $(MAKEFILE_LIST)))
export WORKDIR?= $(CURDIR)
.PHONY: all libmeme pepethefrog
all: libmeme pepethefrog
libmeme:
cd $(BASEDIR)libmeme && $(MAKE)
pepethefrog:
cd $(BASEDIR)pepethefrog && $(MAKE)[/code]
(and how can I make it work with both bsd and gnu make? how can I remove trailing slash from BASEDIR in such a way it works with both implementations?)
→ libmeme/Makefile
[code]CC= cc
CFLAGS= -fPIC
LDFLAGS= `pkg-config --libs libcurl libpcre libcrypto`
BASEDIR= $(dir $(lastword $(MAKEFILE_LIST)))
WORKDIR?= $(CURDIR)
PREFIX?= /usr/local
.PHONY: all install deinstall
all: libmeme.so
install: $(WORKDIR)/libmeme.so
install -oroot -groot -m644 $(BASEDIR)libmeme.h $(PREFIX)/include
install -oroot -groot -m755 $(WORKDIR)/libmeme.so $(PREFIX)/lib
deinstall:
rm -f $(PREFIX)/include/libmeme.h
rm -f $(PREFIX)/lib/libmeme
libmeme.so: $(BASEDIR)libmeme.c
$(CC) $(CFLAGS) $(LDFLAGS) -o $(WORKDIR)/$@ -c $<[/code]
(With this problem is: each rule is for a target. Will it still count as target if the rule name and the generated file mismatch? E.g.: rule "shit" with generates "../build/shit")
Holy fucking shit the bord raped the code.
Btw, pepethefrog/Makefile just follows the same logic.
Moreover, how can I have the first Makefile (in the root) behave so that I can call `make libmeme install` and it will build and install libmeme only?
How to big projects handle all this? (Don't tell me they use CMake of autotools. If so, how do autotools do then?)
>>226255
http://aegis.sourceforge.net/auug97.pdf
>>226270
Did you even read what I wrote?
>* It must be possible to compile (and install) libmeme and pepethefrog on their own using their own Makefile
>>226273
Did you even read the paper?
Clearly not.
>>226276
Sorry, Makefiles drive me crazy. I will answer when I'll cool down.
>>226255
use cmake. Writing makefiles on your own sucks