/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 general-purpose makefile v1.10
2
 
#_______________________________________________________________________________
3
 
#                                                                S E T T I N G S
4
 
 
5
 
# Overridable options
6
 
# (better to specify these in environment/command line)
7
 
#export DEBUGMODE       := 1
8
 
#export STATICLIBS      := 1
9
 
 
10
 
# Target binary/library
11
 
#BUILDALIB      := 1
12
 
#BUILDSOLIB     := 1
13
 
TARGET          := tim.a
 
1
#                                                       Edam's Makefile v1.8
 
2
#___________________________________________________________________________
 
3
#                                                            S E T T I N G S
 
4
 
 
5
# Target binary
 
6
TARGET          := tim
14
7
 
15
8
# All source files
16
 
SOURCES         := tim.cc
 
9
CC_SRCS         := 
 
10
C_SRCS          := 
 
11
S_SRCS          := 
17
12
 
18
 
# Libraries to link
 
13
# Libraries
19
14
LIBRARIES       := 
20
15
 
21
 
# Subdirectories to make
22
 
SUBDIRS         := 
 
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         := 
 
26
 
 
27
#___________________________________________________________________________
23
28
 
24
29
# Software
25
 
AS              := nasm
26
 
CC              := gcc
27
 
CXX             := g++
28
 
 
29
 
# Flags
30
 
CPPFLAGS        := 
31
 
CFLAGS          := $(if $(DEBUGMODE),-g -D DEBUG,-O2)
32
 
CXXFLAGS        := $(if $(DEBUGMODE),-g -D DEBUG,-O2)
33
 
ASFLAGS         := -f elf $(if $(DEBUGMODE),-g -dDEBUG,-O2)
34
 
LDFLAGS         := -Wall $(if $(DEBUGMODE),,-s) $(if $(STATICLIBS), -static)
35
 
 
36
 
#_______________________________________________________________________________
37
 
 
38
 
DEPFILE         := depends.mk
39
 
OBJECTS         := $(addsuffix .o,$(basename $(SOURCES)))
 
30
AS                      := nasm
 
31
CC                      := $(if $(CPPBUILD), g++, gcc)
 
32
 
 
33
ifdef DEBUGMODE
 
34
 
 
35
# Debug build flags
 
36
CPPFLAGS        := -g -D DEBUG $(CPPFLAGS)
 
37
ASFLAGS         := -f elf -g -dDEBUG $(ASFLAGS)
 
38
LDFLAGS         := -Wall $(if $(STATICLIBS), -static) $(LDFLAGS)
 
39
 
 
40
else
 
41
 
 
42
# Release build flags
 
43
CPPFLAGS        := -O2 $(CPPFLAGS)
 
44
ASFLAGS         := -f elf -O2 $(ASFLAGS)
 
45
LDFLAGS         := -Wall -s $(if $(STATICLIBS), -static) $(LDFLAGS)
 
46
 
 
47
endif
 
48
 
 
49
# More variables...
 
50
DEPFILE         := Depends
 
51
_SRCS           := $(CC_SRCS) $(C_SRCS) $(S_SRCS)
 
52
_OBJS           := $(addsuffix .o,$(basename $(_SRCS)))
40
53
LDLIBS          := $(addprefix -l,$(LIBRARIES))
41
 
TARGET          := $(patsubst %.so,%,$(patsubst %.a,%,$(TARGET)))
42
 
TARGET          := $(TARGET)$(if $(BUILDALIB),.a,)$(if $(BUILDSOLIB),.so,)
43
 
 
44
 
.PHONY: all subdirs target clean clean_all run depend dep $(SUBDIRS)
45
 
 
46
 
all: subdirs target
47
 
 
48
 
subdirs: $(SUBDIRS)
49
 
 
50
 
target: $(TARGET)
 
54
 
 
55
.PHONY: all clean run depend dep
 
56
 
 
57
all:    depend $(TARGET)
 
58
 
 
59
$(TARGET): $(_OBJS)
 
60
ifdef BUILDLIB
 
61
        $(AR) rcs $(TARGET) $(_OBJS)
 
62
else
 
63
        $(CC) -o $(TARGET) $(LDFLAGS) $(LDLIBS) $(_OBJS)
 
64
endif
51
65
 
52
66
clean:
53
 
ifeq "$(MAKECMDGOALS)" "clean"
54
 
ifdef SUBDIRS
55
 
        @echo NOT RECURSING: Use \"make clean_all\" to clean subdirectoried as well...
56
 
endif
57
 
endif
58
 
        rm -f core $(DEPFILE) $(OBJECTS) $(TARGET)
 
67
        rm -f core $(DEPFILE) $(_OBJS)
59
68
        rm -f *~
60
69
 
61
 
clean_all: subdirs clean
62
 
 
63
 
ifndef BUILDALIB
64
 
ifndef BUILDSOLIB
65
 
run: target
 
70
run:    $(TARGET)
66
71
        ./$(TARGET)
67
 
endif
68
 
endif
69
 
 
70
 
#depend dep:
71
 
#       makedepend -f- -- $(CPPFLAGS) -- $(SOURCES) > $(DEPFILE)
72
 
 
73
 
$(SUBDIRS):
74
 
        @$(MAKE) --no-print-directory -C $@ $(MAKECMDGOALS)
75
 
 
76
 
$(TARGET): $(OBJECTS)
77
 
ifdef BUILDALIB
78
 
        $(AR) rcs $(TARGET) $(OBJECTS)
79
 
else
80
 
        $(CXX) $(if $(BUILDSOLIB),-shared) -o $(TARGET) $(LDFLAGS) $(OBJECTS) $(LDLIBS) 
81
 
endif
82
 
 
83
 
#%.o:   %.c
84
 
#       $(CC) -c $(CPPFLAGS) $(CFLAGS)
85
 
#%.o:   %.cc
86
 
#       $(CXX) -c $(CPPFLAGS) $(CXXFLAGS)
87
 
#%.o:   %.s
88
 
#       $(AS) $(ASFLAGS)
89
 
 
90
 
-include $(DEPFILE)
91
 
 
92
 
#_______________________________________________________________________________
 
72
 
 
73
depend dep:
 
74
#       makedepend -f- -- $(CPPFLAGS) -- $(_SRCS) > $(DEPFILE)
 
75
 
 
76
#___________________________________________________________________________
 
77
#include $(DEPFILE)