/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.8
 
1
#                                                       Edam's Makefile v1.9
2
2
#___________________________________________________________________________
3
3
#                                                            S E T T I N G S
4
4
 
5
 
# Target binary
 
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
6
13
TARGET          := tim
7
14
 
8
15
# All source files
9
 
CC_SRCS         := 
 
16
CC_SRCS         := tim.cc
10
17
C_SRCS          := 
11
18
S_SRCS          := 
12
19
 
13
 
# Libraries
 
20
# Libraries to link
14
21
LIBRARIES       := 
15
22
 
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
# Subdirectories to make
 
24
SUBDIRS         := 
28
25
 
29
26
# Software
30
27
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
 
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)
 
37
 
 
38
#___________________________________________________________________________
 
39
 
 
40
DEPFILE         := depends.mk
51
41
_SRCS           := $(CC_SRCS) $(C_SRCS) $(S_SRCS)
52
42
_OBJS           := $(addsuffix .o,$(basename $(_SRCS)))
53
43
LDLIBS          := $(addprefix -l,$(LIBRARIES))
54
44
 
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
 
45
.PHONY: all target clean clean_all run depend dep $(SUBDIRS)
 
46
 
 
47
all:    $(SUBDIRS) $(TARGET)
 
48
 
 
49
target: $(TARGET)
65
50
 
66
51
clean:
67
 
        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)
68
58
        rm -f *~
69
59
 
 
60
clean_all: $(SUBDIRS) clean
 
61
 
70
62
run:    $(TARGET)
71
 
        ./$(TARGET)
 
63
        $(if $(BUILDLIB),@echo Can\'t run a library\!,./$(TARGET))
72
64
 
73
 
depend dep:
 
65
#depend dep:
74
66
#       makedepend -f- -- $(CPPFLAGS) -- $(_SRCS) > $(DEPFILE)
75
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
 
76
87
#___________________________________________________________________________
77
 
#include $(DEPFILE)