[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Makefile done right

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 7
Thread images: 1

File: makefile.gif (14KB, 600x168px) Image search: [Google]
makefile.gif
14KB, 600x168px
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
Thread posts: 7
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.