1
# Jamrules -- the rule boilerplate for InitNG
2
# Copyright (C) 2009  Eric MSP Veith <eveith@wwweb-library.net>
3
# Licensed under GNU GPL v3, see the included file "COPYING" for details.
4
#
5
# This file contains predefined variables available throughout the whole build
6
# process as well as some rules needed for creating the executables and
7
# libraries.
8
# Normally, a packager or quite anyone building InitNG doesn't have to change
9
# anything in here, but can rely on environmental variables or the -s
10
# parameter to jam, e.g. OPTIM="" for compiler optimization flags.
11
# If you have to change something in here to make InitNG build, it is probably
12
# a bug, and you should contact the author of the build system.
13
#
14
15
16
### PART 1: CONFIGURATION VARIABLES
17
#
18
# This part defines a bunch of variables that are used throughout the build
19
# and describe certain features of InitNG, like the version number, the name,
20
# installation paths, and so on.
21
#
22
# These are defaults; please don't change them here unless you intent the
23
# change to be permanent.  Most of them are set during ./configure run, but if
24
# not, either use the "-s" parameter or environment variables.
25
#
26
27
include "config.jam" ;
28
if ! $(CONFIGURED)
29
{
30
    Echo "*** Error: config.jam was not found." ;
31
    Echo "Please run ./configure first." ;
32
    Echo "If configure is not there, run: aclocal -Iaclocal && autoconf" ;
33
    Echo "" ;
34
    Exit "*** Not configured, stopping." ;
35
}
36
37
# Destination directory for package creation.
38
DESTDIR ?= ;
39
40
# Build defines. Don't add them as real parameters, just the define itself.
41
# Jam figures out what compiler command line switch to use itself.
42
DEFINES += HAVE_CONFIG_H _XOPEN_SOURCE=600 DEBUG ;
43
44
# Global C build and linker flags aside from CFLAGS passed to configure:
45
CCFLAGS += -std=c99 -Wall -O2 ;
46
CCFLAGS += -Werror -Wmissing-prototypes -Wmissing-declarations
47
    -Wstrict-prototypes -Wimplicit -Wredundant-decls -Wnested-externs
48
    -Wwrite-strings -Wsign-compare -Winline -Wswitch -Wreturn-type
49
    -Wparentheses -Wmissing-braces -Wformat -Wformat-nonliteral
50
    -Wformat-security -Wsequence-point -Wundef -Wunused -Wcomment ;
51
LINKFLAGS += -rdynamic -fPIC ;
52
53
54
### PART 2: USER-CONFIGURABLES
55
#
56
# This section holds parameters that are configurable by the user and have
57
# influence on the build. They mostly enable or disable certain features of
58
# InitNG.
59
#
60
# As above, please use the "-s" switch or environment variables!
61
#
62
63
if $(CHECK_RO) { DEFINES += CHECK_RO ; }
64
if $(FORCE_NOCOLOR) { DEFINES += FORCE_NOCOLOR ; }
65
if $(FORCE_POSIX_IFILES) { DEFINES += FORCE_POSIX_IFILES ; }
66
67
68
### PART 3: PATHS FOR 3RD-PARTY LIBRARIES
69
#
70
# This section includes variables that set up include or library paths for
71
# modules that need 3rd-party libraries like D-BUS or others.
72
#
73
74
DBUS_INCLUDES = "`pkg-config --cflags-only-I dbus-1`" ;
75
DBUS_LIBS = "`pkg-config --cflags-only-I --cflags-only-l dbus-1`" ;
76
77
78
### PART 4: CUSTOM RULES
79
#
80
# The following section houses rules that are used exclusively by InitNG's
81
# build system.
82
#
83
84
# Builds a static library from a set of subdirectories given as arguments to
85
# this rule. It takes care of creating the objects in the right place,
86
# cleaning up and running Ar. It does not, however, handle recursion.
87
rule LibraryFromSubdirs
88
{
89
    local _o = [ ObjectsFromSubdir $(>) ] ;
90
    LibraryFromObjects $(<) : $(_o) ;
91
}
92
93
94
# Does pretty much the same as LibraryFromSubdirs, but creates an executable
95
# instead.
96
rule MainFromSubdirs
97
{
98
    local _o = [ ObjectsFromSubdir $(>) ] ;
99
    MainFromObjects $(<) : $(_o) ;
100
}
101
102
103
# Workhouse for subdir compile. Iterates over all subdirectories given and
104
# turns the *.c sources found there into objects. Returns a list of all
105
# objects created.
106
# USAGE: ObjectsFromSubdir foo bar baz ;
107
rule ObjectsFromSubdir
108
{
109
    local _sources _objects _subdir ;
110
    
111
    for _subdir in $(<)
112
    {
113
        # Get all source files
114
        _sources = [ Glob [ FDirName $(SUBDIR) $(_subdir) ] : *.c ] ;
115
116
        # Adjust grist (otherwise we get $(SUBDIR) twice)
117
        _sources = $(_sources:D=$(_subdir)) ;
118
119
        # Keep track of the objects we're about to create
120
        _objects += $(_sources:S=$(SUFOBJ)) ;
121
122
        # Do the actual compile
123
        Objects $(_sources) ;
124
    }
125
126
    Clean clean : $(_objects) ;
127
    return $(_objects) ;
128
}
129
130
131
# Creates an InitNG module from a given subdirectory. Will automatically link
132
# it against libinitng.a, and build a shared library named by the scheme
133
# "mod$(SUBDIR)$(SUF)".
134
rule ModuleFromSubdir
135
{
136
    local _lib = mod$(<) ;
137
    local _obj = [ ObjectsFromSubdir $(<) ] ;
138
139
    LINKFLAGS on $(_lib) += -fPIC -rdynamic 
140
        -shared -Wl,-soname,$(_lib)
141
        -Wl,--whole-archive [ FDirName $(TOP) core libinitng$(SUFLIB) ] 
142
        -Wl,--no-whole-archive -ldl ;
143
    MainFromObjects $(_lib).so : $(_obj) ;
144
145
    Clean clean : $(_lib) ;
146
    return $(_lib) ;
147
}
148
149
150
# Creates a shared library from C sources. You need to supply the target's
151
# file name, nothing else happens here than adding the GCC linker flags to
152
# turn a binary into a shared object.
153
# USAGE: SharedLibrary NAME : SOURCE1 SOURCE2 ... SOURCEn ;
154
rule SharedLibrary
155
{
156
    local _sofile _soname _soversion _somajorversion ;
157
    local _match = [ Match (.*)(\.(\d+)(\.\d+)*)? : $(<) ] ;
158
159
    _sofile = $(1) ;
160
    _soname = $(_match[1]).$(_match[3]) ;
161
    _soversion = $(match[3-4]) ;
162
    _somajorversion = $(match[3]) ;
163
164
    DEPENDS $(<) : $(_soname) $(_sofile) ;
165
166
    LINKFLAGS on $(<) += -shared -Wl,-soname,$(_soname) ;
167
    Main $(<) : $(>) ;
168
}
169
170
171
# Sets up housekeeping for an InitNG C source directory. It is basically the
172
# same as SubDir, but does some additional tasks to make life easier:
173
#   1. Calls "SubDir",
174
#   2. Adds $(TOP) and $(TOP)/include to the include path.
175
rule SrcDir
176
{
177
    SubDir $(<) ;
178
    SubDirHdrs $(TOP) ;
179
    SubDirHdrs $(TOP) include ;
180
}