/make/edam-mk

To get this branch, use:
bzr branch http://bzr.ed.am/make/edam-mk

« back to all changes in this revision

Viewing changes to Makefile

  • Committer: edam
  • Date: 2009-03-05 13:32:10 UTC
  • Revision ID: edam@waxworlds.org-20090305133210-9i18m48si42bpidr
Tags: 1.8
- set CC correctly
- change assignments for non-recursive assignments
- added BUILDLIB switch to build a static library

Show diffs side-by-side

added added

removed removed

1
 
#                                                       Edam's Makefile v1.7
 
1
#                                                       Edam's Makefile v1.8
2
2
#___________________________________________________________________________
3
3
#                                                            S E T T I N G S
4
4
 
5
5
# Target binary
6
 
TARGET          = helloworld
 
6
TARGET          := tim
7
7
 
8
8
# All source files
9
 
CC_SRCS         = helloworld.cc
10
 
C_SRCS          = 
11
 
S_SRCS          = 
 
9
CC_SRCS         := 
 
10
C_SRCS          := 
 
11
S_SRCS          := 
12
12
 
13
13
# Libraries
14
 
LIBRARIES       =
15
 
 
16
 
# Options (comment-out to disable)
17
 
DEBUG           = 1
18
 
CPPBUILD        = 1
19
 
#STATICLIBS     = 1
20
 
 
21
 
# Other flags
22
 
CPPFLAGS        = 
23
 
ASFLAGS         = 
24
 
LDFLAGS         = 
 
14
LIBRARIES       := 
 
15
 
 
16
# Override options (better: specify in environment or on cmdline)
 
17
#DEBUGMODE      := 1
 
18
CPPBUILD        := 1
 
19
#STATICLIBS     := 1
 
20
BUILDLIB        := 1
 
21
 
 
22
# Initial flags
 
23
CPPFLAGS        := 
 
24
ASFLAGS         := 
 
25
LDFLAGS         := 
25
26
 
26
27
#___________________________________________________________________________
27
 
#                                                                    M E A T
28
28
 
29
29
# Software
30
 
AS=nasm
 
30
AS                      := nasm
 
31
CC                      := $(if $(CPPBUILD), g++, gcc)
31
32
 
32
 
ifdef DEBUG
 
33
ifdef DEBUGMODE
33
34
 
34
35
# Debug build flags
35
 
CPPFLAGS        := $(CPPFLAGS) -g -D DEBUG
36
 
ASFLAGS         := -f elf -g -dDEBUG
 
36
CPPFLAGS        := -g -D DEBUG $(CPPFLAGS)
 
37
ASFLAGS         := -f elf -g -dDEBUG $(ASFLAGS)
37
38
LDFLAGS         := -Wall $(if $(STATICLIBS), -static) $(LDFLAGS)
38
39
 
39
40
else
40
41
 
41
42
# Release build flags
42
 
CPPFLAGS        := $(CPPFLAGS) -O2
43
 
ASFLAGS         := -f elf -O2
 
43
CPPFLAGS        := -O2 $(CPPFLAGS)
 
44
ASFLAGS         := -f elf -O2 $(ASFLAGS)
44
45
LDFLAGS         := -Wall -s $(if $(STATICLIBS), -static) $(LDFLAGS)
45
46
 
46
47
endif
47
48
 
48
49
# More variables...
49
 
DEPFILE         = Depends
50
 
_SRCS           = $(CC_SRCS) $(C_SRCS) $(S_SRCS)
51
 
_OBJS           = $(addsuffix .o,$(basename $(_SRCS)))
52
 
LDLIBS          = $(addprefix -l,$(LIBRARIES))
53
 
 
54
 
# Main rule...
 
50
DEPFILE         := Depends
 
51
_SRCS           := $(CC_SRCS) $(C_SRCS) $(S_SRCS)
 
52
_OBJS           := $(addsuffix .o,$(basename $(_SRCS)))
 
53
LDLIBS          := $(addprefix -l,$(LIBRARIES))
 
54
 
 
55
.PHONY: all clean run depend dep
 
56
 
 
57
all:    depend $(TARGET)
 
58
 
55
59
$(TARGET): $(_OBJS)
56
 
        $(if $(CPPBUILD), g++, gcc) -o $(TARGET) $(LDFLAGS) $(_OBJS) $(LDLIBS)
57
 
 
58
 
#___________________________________________________________________________
59
 
#                                                                  R U L E S
60
 
 
61
 
.PHONY: all clean run depend dep
62
 
 
63
 
all:    clean depend $(TARGET)
 
60
ifdef BUILDLIB
 
61
        $(AR) rcs $(TARGET) $(_OBJS)
 
62
else
 
63
        $(CC) -o $(TARGET) $(LDFLAGS) $(LDLIBS) $(_OBJS)
 
64
endif
64
65
 
65
66
clean:
66
67
        rm -f core $(DEPFILE) $(_OBJS)