/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.3
2
 
#___________________________________________________________________________
3
 
#                                                            S E T T I N G S
4
 
 
5
 
# Target binary
6
 
TARGET          = exectest
 
1
#                                          Edam's general-purpose makefile v1.11
 
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          := 
7
14
 
8
15
# All source files
9
 
CC_SRCS         = 
10
 
C_SRCS          = 
11
 
S_SRCS          = exectest.s
12
 
 
13
 
# Libraries
14
 
LIBRARIES       = 
15
 
 
16
 
# Debug?
17
 
DEBUG           = -g
18
 
 
19
 
# Build flags
20
 
CPPFLAGS        = $(DEBUG) -O2
21
 
ASFLAGS         = $(DEBUG) -f elf
22
 
LDFLAGS         = $(DEBUG) -Wall -s -nostartfiles
23
 
 
24
 
#___________________________________________________________________________
25
 
#                                                                    M E A T
 
16
SOURCES         := tim.cc
 
17
 
 
18
# Libraries to link
 
19
LIBRARIES       := 
 
20
 
 
21
# Subdirectories to make
 
22
SUBDIRS         := 
26
23
 
27
24
# Software
28
 
AS=nasm
29
 
 
30
 
# More variables...
31
 
DEPFILE         = Depends
32
 
_SRCS           = $(CC_SRCS) $(C_SRCS) $(S_SRCS)
33
 
_OBJS           = $(addsuffix .o,$(basename $(_SRCS)))
34
 
LDLIBS          = $(addprefix -l,$(LIBRARIES))
35
 
 
36
 
# Main rule...
37
 
$(TARGET): $(_OBJS)
38
 
        gcc -o $(TARGET) $(LDFLAGS) $(_OBJS) $(LDLIBS)
39
 
 
40
 
#___________________________________________________________________________
41
 
#                                                                  R U L E S
42
 
 
43
 
.PHONY: all clean depend dep
44
 
 
45
 
all:    clean depend $(TARGET)
46
 
 
47
 
clean:
48
 
        rm -f core $(DEPFILE) $(_OBJS)
49
 
        rm -f *~
50
 
 
51
 
depend dep:
52
 
#       makedepend -f- -- $(CPPFLAGS) -- $(_SRCS) > $(DEPFILE)
53
 
 
54
 
#___________________________________________________________________________
55
 
#include $(DEPFILE)
 
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)))
 
40
LDLIBS          := $(addprefix -l,$(LIBRARIES))
 
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
 
72
 
 
73
#depend dep:
 
74
#       makedepend -f- -- $(CPPFLAGS) -- $(SOURCES) > $(DEPFILE)
 
75
 
 
76
$(SUBDIRS):
 
77
        @echo ==== Sub directory: $@
 
78
        @$(MAKE) --no-print-directory -C $@ $(filter-out $(SUBDIRS),$(MAKECMDGOALS))
 
79
 
 
80
$(TARGET): $(OBJECTS)
 
81
ifdef BUILDALIB
 
82
        $(AR) rcs $(TARGET) $(OBJECTS)
 
83
else
 
84
        $(CXX) $(if $(BUILDSOLIB),-shared) -o $(TARGET) $(LDFLAGS) $(OBJECTS) $(LDLIBS) 
 
85
endif
 
86
 
 
87
#%.o:   %.c
 
88
#       $(CC) -c $(CPPFLAGS) $(CFLAGS)
 
89
#%.o:   %.cc
 
90
#       $(CXX) -c $(CPPFLAGS) $(CXXFLAGS)
 
91
#%.o:   %.s
 
92
#       $(AS) $(ASFLAGS)
 
93
 
 
94
-include $(DEPFILE)
 
95
 
 
96
#_______________________________________________________________________________