summaryrefslogtreecommitdiffstats
path: root/native_client_sdk/src/examples/dlopen/Makefile
blob: c19fa4954c5d4e175c5a8c502fa7e2774acf380b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# Copyright (c) 2012 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

#
# GNU Make based build file.  For details on GNU Make see:
#   http://www.gnu.org/software/make/manual/make.html
#

#
# Project information
#
# These variables store project specific settings for the project name
# build flags, files to copy or install.  In the examples it is typically
# only the list of sources and project name that will actually change and
# the rest of the makefile is boilerplate for defining build rules.
#
PROJECT:=dlopen
WARNINGS:=-Wno-long-long -Wall
CXXFLAGS:=-g -O0 -pthread -std=gnu++98 $(WARNINGS)
LDFLAGS:=-g -ldl -lppapi_cpp -lppapi


#
# Get pepper directory for toolchain and includes.
#
# If PEPPER_ROOT is not set, then assume it can be found a two directories up,
# from the default example directory location.
#
THIS_MAKEFILE:=$(abspath $(lastword $(MAKEFILE_LIST)))
NACL_SDK_ROOT?=$(abspath $(dir $(THIS_MAKEFILE))../..)

#
# Compute tool paths
#
#
OSNAME:=$(shell python $(NACL_SDK_ROOT)/tools/getos.py)
TC_PATH:=$(abspath $(NACL_SDK_ROOT)/toolchain/$(OSNAME)_x86_glibc)
CXX:=$(TC_PATH)/bin/i686-nacl-g++
NMF:=python $(NACL_SDK_ROOT)/tools/create_nmf.py

#
# Create shell aliases
#
# Create Python based aliases for common shell commands like copy or move.
#
COPY:= python $(NACL_SDK_ROOT)/tools/oshelpers.py cp
MKDIR:= python $(NACL_SDK_ROOT)/tools/oshelpers.py mkdir
RM:= python $(NACL_SDK_ROOT)/tools/oshelpers.py rm
MV:= python $(NACL_SDK_ROOT)/tools/oshelpers.py mv

#
# Disable DOS PATH warning when using Cygwin based tools Windows
#
CYGWIN ?= nodosfilewarning
export CYGWIN


#
# NMF Manifiest generation
#
NMF:=python $(NACL_SDK_ROOT)/tools/create_nmf.py
NMF+=-D $(TC_PATH)/x86_64-nacl/bin/objdump
NMF_PATHS:=-L $(TC_PATH)/x86_64-nacl/lib32 -L $(TC_PATH)/x86_64-nacl/lib
NMF_PATHS+=-L lib32 -L lib64


#
# Disable DOS PATH warning when using Cygwin based tools Windows
#
CYGWIN ?= nodosfilewarning
export CYGWIN


# Declare the ALL target first, to make the 'all' target the default build.
# Since the NMF file requires all the binaires for generation we use that as
# the dependency.
all : $(PROJECT).nmf

# Rules to create subdirectories for libraries
lib32:
	$(MKDIR) -p $@

lib64:
	$(MKDIR) -p $@

# Copy all files to that config
$(foreach src,$(COPY_FILES),$(eval $(call FILE_COPY,$(src),DBG)))

# Build debug version dlopen nexe and eightball.so for 32 and 64 bit.
dlopen_x86_32.o: dlopen.cc $(THIS_MAKE)
	$(CXX) -o $@ -c $< -m32 $(CXXFLAGS)

dlopen_x86_32.nexe: dlopen_x86_32.o
	$(CXX) -o $@ $< -m32 $(LDFLAGS)

dlopen_x86_64.o: dlopen.cc $(THIS_MAKE)
	$(CXX) -o $@ -c $< -m64 $(CXXFLAGS)

dlopen_x86_64.nexe: dlopen_x86_64.o
	$(CXX) -o $@ $< -m64 $(LDFLAGS)

eightball_x86_32.o: eightball.cc $(THIS_MAKE)
	$(CXX) -o $@ -c $< -m32 $(CXXFLAGS) -fPIC

lib32/libeightball.so: eightball_x86_32.o | lib32
	$(CXX) -o $@ $< -m32 $(LDFLAGS) -shared

eightball_x86_64.o: eightball.cc $(THIS_MAKE)
	$(CXX) -o $@ -c $< -m64 $(CXXFLAGS) -fPIC

lib64/libeightball.so: eightball_x86_64.o | lib64
	$(CXX) -o $@ $< -m64 $(LDFLAGS) -shared

#
# NMF Manifiest generation
#
# Use the python script create_nmf to scan the binaries for dependencies using
# objdump.  Pass in the (-L) paths to the default library toolchains so that we
# can find those libraries and have it automatically copy the files (-s) to
# the target directory for us.
NEXES:=dlopen_x86_32.nexe dlopen_x86_64.nexe
NEXES+=lib32/libeightball.so lib64/libeightball.so
NMF_ARGS:=-D $(TC_PATH)/x86_64-nacl/bin/objdump
NMF_PATHS:=-L $(TC_PATH)/x86_64-nacl/lib32 -L $(TC_PATH)/x86_64-nacl/lib64

$(PROJECT).nmf : $(NEXES)
	$(NMF) -o $@ -s . $^ $(NMF_PATHS)

# Define a phony rule so it always runs, to build nexe and start up server.
.PHONY: RUN 
RUN: all
	python ../httpd.py