/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:34:42 UTC
  • Revision ID: edam@waxworlds.org-20090305133442-tiu2f46d8xgc9v2u
Tags: 1.9
- added SUBDIRS for recursing
- added check for SUBDIRS to clean
- added new goal, clean_all, which recurses
- added BUILDSO switch to build a shared library
- renamed dependency files

Show diffs side-by-side

added added

removed removed

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