/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:45:42 UTC
  • Revision ID: edam@waxworlds.org-20090305134542-llxrwg3d7xucnf60
Tags: 1.11
- fixed recursive cleaning
- notify when recursing during build

Show diffs side-by-side

added added

removed removed

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