-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmaky.mk
More file actions
126 lines (105 loc) · 3.6 KB
/
maky.mk
File metadata and controls
126 lines (105 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# MAKY -- v2.4
MAKYVERSION = 2.4
# Formerly part of MySetup Project
# https://github.com/carrieje/mysetup
#####
# LICENCE
# Generic Makefile with easy customization
# Copyright (C) 2014 Jeremy Carrier
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#####
# README
# To get some hints on how to use this makefile, run
# make help
#####
# BASIC CUSTOMIZATION
EXTENSION = cpp
COMPILER = g++
PACKAGES =
EXTRAINCL =
EXTRALIBS =
#####
# PLUMBING CUSTOMIZATION
MAINS = main.$(EXTENSION)
CFLAGS = -W -Wall -pedantic $(ALL_HDRS)
LDFLAGS = $(ALL_LIBS)
##### #### #####
# DO NOT CUSTOMIZE BELOW THIS LINE UNLESS YOU KNOW WHAT YOU DO #
##### #### #####
#####
# INTERNAL SETTINGS
ALL_HDRS = $(foreach pack, $(PACKAGES), $(shell echo `pkg-config --cflags $(pack)`)) $(EXTRAINCL)
ALL_LIBS = $(foreach pack, $(PACKAGES), `pkg-config --libs $(pack)`) $(EXTRALIBS)
EXT = $(EXTENSION)
CC = $(COMPILER)
ALLSRC = $(wildcard *.$(EXT))
SRC = $(filter-out $(MAINS),$(ALLSRC))
OBJ = $(SRC:.$(EXT)=.o)
.SECONDEXPANSION:
.PHONY: all clean mrproper list pkgs-avail pkgs-version help
#####
# COMPILATION TARGETS
all: pkgs-avail $(MAINS:.$(EXT)=)
$(MAINS:.$(EXT)=): $(OBJ) $$(@).o
$(CC) -o $@ $^ $(LDFLAGS)
%.o: %.$(EXT)
$(CC) -o $@ -c $< $(CFLAGS)
#####
# PHONY TARGETS
clean:
rm -rf $(OBJ) $(MAINS:.$(EXT)=.o)
mrproper: clean
rm -rf $(MAINS:.$(EXT)=)
list:
@echo -e "Sources $(SRC)\nObjets $(OBJ)\nMains $(MAINS)"
pkgs-version:
@for p in $(PACKAGES); do \
echo -n "$$p : "; \
pkg-config --modversion $$p; \
done
pkgs-avail:
@for p in $(PACKAGES); do \
pkg-config --exists $$p; \
if [ $$? -ne 0 ]; then \
echo -en "\033[31m" > /dev/stderr; \
echo -en "The package $$p does not exist" > /dev/stderr; \
echo -e "\033[0m" > /dev/stderr; \
fi; \
done
help:
@echo "Maky version $(MAKYVERSION)"; \
echo "Generic Makefile for all your projects (C, C++ and so...)"; \
echo "Even multi-main ones."; \
echo ""; \
echo "COMPILATION TARGETS :"; \
echo " * all : check for packages availability and make all"; \
echo " executables"; \
echo " * EXECUTABLE : name your main file without extension to"; \
echo " compile only this executable"; \
echo "INFORMATION TARGETS :"; \
echo " * clean : delete objects"; \
echo " * mrproper : delete objects and executables"; \
echo " * list : list all recognized files"; \
echo " * pkgs-version : list all the packages along with their"; \
echo " version number"; \
echo " * pkgs-avail : Check for pakages availability through"; \
echo " pkg-config. No output if all of the packages exist."; \
echo ""; \
echo "SETTINGS :"; \
echo " To set Maky for your project, edit it, and fill the"; \
echo " BASIC CUSTOMIZATION section."; \
echo " You can go further in editing the PLUMBING CUSTOMIZATION"; \
echo " section. For instance by adding a file containing a main in"; \
echo " the MAINS list.";