Skip to content

Commit 38a5e89

Browse files
committed
Makefile clean up
Move Windows toolchain settings in a separate makefile fragment and harmonize the messages that are printed during the build for both GNU and Windows platforms.
1 parent 5d94175 commit 38a5e89

File tree

8 files changed

+51
-62
lines changed

8 files changed

+51
-62
lines changed

example/gnu_make.mk

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# Makefile for Wirepas C Mesh API example, GNU make version
22

3+
# Variables
4+
35
# This example needs the C Mesh API library
46
MESH_LIB_FOLDER := ../lib
57
MESH_LIB := $(MESH_LIB_FOLDER)/build/mesh_api_lib.a
68

79
# Detect platform and set toolchain variables
8-
include $(MESH_LIB_FOLDER)/platform.mk
10+
include $(MESH_LIB_FOLDER)/tools.mk
911

1012
# Path of source files and build outputs
1113
SOURCEPREFIX := .
@@ -38,12 +40,12 @@ define COMPILE
3840
endef
3941

4042
define LINK
41-
echo " Linking $(1)"
42-
$(CC) $(CFLAGS) $(LDFLAGS) -o $(1) $(2) $(MESH_LIB)
43+
echo " LD $(1)"
44+
$(CC) $(LDFLAGS) -o $(1) $(2) $(MESH_LIB)
4345
endef
4446

4547
define CLEAN
46-
echo " Cleaning up"
48+
echo " CLEAN"
4749
$(RM) -r $(BUILDPREFIX)
4850
endef
4951

example/nmake.mk

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
11
# Makefile for Wirepas C Mesh API example, Microsoft NMAKE version
22

3+
# Variables
4+
35
# This example needs the C Mesh API library
46
MESH_LIB_FOLDER = ..\lib
57
MESH_LIB = $(MESH_LIB_FOLDER)\build\mesh_api_lib.lib
68

7-
# Microsoft Visual studio command line toolchain on Windows
8-
# Use Visual Studio defaults
9-
#CC = cl
10-
#AS = ml
11-
12-
# Visual Studio C compiler flags
13-
CFLAGS = $(CFLAGS) /nologo /W4 /WX /O2 /MD /TC
14-
15-
# Linker flags
16-
LDFLAGS = $(LDFLAGS) /nologo
17-
18-
# Platform flags
19-
!MESSAGE Platform: WIN32
20-
PLATFORM_IS_WIN32 = 1
21-
CFLAGS = $(CFLAGS) /DPLATFORM_IS_WIN32=1
9+
# Detect platform and set toolchain variables
10+
!INCLUDE $(MESH_LIB_FOLDER)\tools_msvc.mk
2211

2312
# Path of source files and build outputs
2413
SOURCEPREFIX = .
@@ -53,18 +42,19 @@ all: app
5342
app: lib $(TARGET_APP)
5443

5544
clean:
56-
echo Cleaning up
45+
echo CLEAN
5746
-del /F $(OBJECTS) $(TARGET_APP) >NUL 2>NUL
5847
-rmdir /S /Q $(BUILDPREFIX) >NUL 2>NUL
5948

6049
lib:
6150
cd $(MESH_LIB_FOLDER) && $(MAKE) /nologo /f nmake.mk
6251

6352
.c.obj:
53+
echo CC $*.c
6454
-mkdir $(@D) >NUL 2>NUL
6555
$(CC) $(CFLAGS) /c /Fo$@ $*.c
6656

6757
$(TARGET_APP): $(OBJECTS) $(MESH_LIB)
68-
echo Linking $@
58+
echo LINK $@
6959
-mkdir $(@D) >NUL 2>NUL
7060
$(CC) $(LDFLAGS) /Fe$@ $**

lib/gnu_make.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Variables
44

55
# Detect platform and set toolchain variables
6-
include platform.mk
6+
include tools.mk
77

88
# Path of source files and build outputs
99
SOURCEPREFIX := .
@@ -43,12 +43,12 @@ define COMPILE
4343
endef
4444

4545
define LINK_LIB
46-
echo " Linking $(1)"
46+
echo " AR $(1)"
4747
$(ARCHIVE) $(1) $(2)
4848
endef
4949

5050
define CLEAN
51-
echo " Cleaning up"
51+
echo " CLEAN"
5252
$(RM) -r $(BUILDPREFIX)
5353
endef
5454

lib/nmake.mk

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,8 @@
22

33
# Variables
44

5-
# Microsoft Visual studio command line toolchain on Windows
6-
# Use Visual Studio defaults
7-
#CC = cl
8-
#AS = ml
9-
10-
# Visual Studio C compiler flags
11-
CFLAGS = $(CFLAGS) /nologo /W4 /WX /O2 /MD /TC
12-
13-
# Linker flags
14-
LDFLAGS = $(LDFLAGS)
15-
16-
# Platform flags
17-
!MESSAGE Platform: WIN32
18-
PLATFORM_IS_WIN32 = 1
19-
CFLAGS = $(CFLAGS) /DPLATFORM_IS_WIN32=1
5+
# Detect platform and set toolchain variables
6+
!INCLUDE tools_msvc.mk
207

218
# Path of source files and build outputs
229
SOURCEPREFIX = .
@@ -60,15 +47,16 @@ all: lib
6047
lib: $(TARGET_LIB)
6148

6249
clean:
63-
echo Cleaning up
50+
echo CLEAN
6451
-del /F $(OBJECTS) $(TARGET_LIB) >NUL 2>NUL
6552
-rmdir /S /Q $(BUILDPREFIX) >NUL 2>NUL
6653

6754
.c.obj:
55+
echo CC $*.c
6856
-mkdir $(@D) >NUL 2>NUL
6957
$(CC) $(CFLAGS) /c /Fo$@ $*.c
7058

7159
$(TARGET_LIB): $(OBJECTS)
72-
echo Linking $@
60+
echo LIB $@
7361
-mkdir $(@D) >NUL 2>NUL
7462
lib /NOLOGO /OUT:$@ $**
File renamed without changes.

lib/tools_msvc.mk

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Toolchain settings for Wirepas C Mesh API library, Microsoft NMAKE version
2+
3+
# Microsoft Visual studio command line toolchain on Windows
4+
# Use Visual Studio defaults
5+
#CC = cl
6+
#AS = ml
7+
8+
# Visual Studio C compiler flags
9+
CFLAGS = $(CFLAGS) /nologo /W4 /WX /O2 /MD /TC
10+
11+
# Linker flags
12+
LDFLAGS = $(LDFLAGS) /nologo
13+
14+
# Platform flags
15+
!MESSAGE Platform: WIN32
16+
PLATFORM_IS_WIN32 = 1
17+
CFLAGS = $(CFLAGS) /DPLATFORM_IS_WIN32=1

test/gnu_make.mk

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# Makefile for Wirepas C Mesh API test suite, GNU make version
22

3+
# Variables
4+
35
# This example needs the C Mesh API library
46
MESH_LIB_FOLDER := ../lib
57
MESH_LIB := $(MESH_LIB_FOLDER)/build/mesh_api_lib.a
68

79
# Detect platform and set toolchain variables
8-
include $(MESH_LIB_FOLDER)/platform.mk
10+
include $(MESH_LIB_FOLDER)/tools.mk
911

1012
# Path of source files and build outputs
1113
SOURCEPREFIX := .
@@ -46,12 +48,12 @@ define COMPILE
4648
endef
4749

4850
define LINK
49-
echo " Linking $(1)"
50-
$(CC) $(CFLAGS) $(LDFLAGS) -o $(1) $(2) $(MESH_LIB)
51+
echo " LD $(1)"
52+
$(CC) $(LDFLAGS) -o $(1) $(2) $(MESH_LIB)
5153
endef
5254

5355
define CLEAN
54-
echo " Cleaning up"
56+
echo " CLEAN"
5557
$(RM) -r $(BUILDPREFIX)
5658
endef
5759

test/nmake.mk

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
11
# Makefile for Wirepas C Mesh API test suite, Microsoft NMAKE version
22

3+
# Variables
4+
35
# This example needs the C Mesh API library
46
MESH_LIB_FOLDER = ..\lib
57
MESH_LIB = $(MESH_LIB_FOLDER)\build\mesh_api_lib.lib
68

7-
# Microsoft Visual studio command line toolchain on Windows
8-
# Use Visual Studio defaults
9-
#CC = cl
10-
#AS = ml
11-
12-
# Visual Studio C compiler flags
13-
CFLAGS = $(CFLAGS) /nologo /W4 /WX /O2 /MD /TC
14-
15-
# Linker flags
16-
LDFLAGS = $(LDFLAGS) /nologo
17-
18-
# Platform flags
19-
!MESSAGE Platform: WIN32
20-
PLATFORM_IS_WIN32 = 1
21-
CFLAGS = $(CFLAGS) /DPLATFORM_IS_WIN32=1
9+
# Detect platform and set toolchain variables
10+
!INCLUDE $(MESH_LIB_FOLDER)\tools_msvc.mk
2211

2312
# Path of source files and build outputs
2413
SOURCEPREFIX = .
@@ -61,18 +50,19 @@ all: app
6150
app: lib $(TARGET_APP)
6251

6352
clean:
64-
echo Cleaning up
53+
echo CLEAN
6554
-del /F $(OBJECTS) $(TARGET_APP) >NUL 2>NUL
6655
-rmdir /S /Q $(BUILDPREFIX) >NUL 2>NUL
6756

6857
lib:
6958
cd $(MESH_LIB_FOLDER) && $(MAKE) /nologo /f nmake.mk
7059

7160
.c.obj:
61+
echo CC $*.c
7262
-mkdir $(@D) >NUL 2>NUL
7363
$(CC) $(CFLAGS) /c /Fo$@ $*.c
7464

7565
$(TARGET_APP): $(OBJECTS) $(MESH_LIB)
76-
echo Linking $@
66+
echo LINK $@
7767
-mkdir $(@D) >NUL 2>NUL
7868
$(CC) $(LDFLAGS) /Fe$@ $**

0 commit comments

Comments
 (0)