/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

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