releasing package jattach version 2.0-1
[sven/jattach.git] / Makefile
1 JATTACH_VERSION=2.0
2
3 ifneq ($(findstring Windows,$(OS)),)
4   CL=cl.exe
5   CFLAGS=/O2 /D_CRT_SECURE_NO_WARNINGS
6   JATTACH_EXE=jattach.exe
7   JATTACH_DLL=jattach.dll
8 else 
9   CFLAGS ?= -O3
10   JATTACH_EXE=jattach
11
12   UNAME_S:=$(shell uname -s)
13   ifeq ($(UNAME_S),Darwin)
14     JATTACH_DLL=libjattach.dylib
15   else
16     JATTACH_DLL=libjattach.so
17   endif
18
19   ifeq ($(UNAME_S),Linux)
20     ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
21     RPM_ROOT=$(ROOT_DIR)/build/rpm
22     SOURCES=$(RPM_ROOT)/SOURCES
23     SPEC_FILE=jattach.spec
24   endif
25 endif
26
27
28 .PHONY: all dll clean rpm-dirs rpm
29
30 all: build build/$(JATTACH_EXE)
31
32 dll: build build/$(JATTACH_DLL)
33
34 build:
35         mkdir -p build
36
37 build/jattach: src/posix/*.c src/posix/*.h
38         $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -DJATTACH_VERSION=\"$(JATTACH_VERSION)\" -o $@ src/posix/*.c
39
40 build/$(JATTACH_DLL): src/posix/*.c src/posix/*.h
41         $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -DJATTACH_VERSION=\"$(JATTACH_VERSION)\" -fPIC -shared -fvisibility=hidden -o $@ src/posix/*.c
42
43 build/jattach.exe: src/windows/jattach.c
44         $(CL) $(CFLAGS) /DJATTACH_VERSION=\"$(JATTACH_VERSION)\" /Fobuild/jattach.obj /Fe$@ $^ advapi32.lib /link /SUBSYSTEM:CONSOLE,5.02
45
46 clean:
47         rm -rf build
48
49 $(RPM_ROOT):
50         mkdir -p $(RPM_ROOT)
51
52 rpm-dirs: $(RPM_ROOT)
53         mkdir -p $(RPM_ROOT)/SPECS
54         mkdir -p $(SOURCES)/bin
55         mkdir -p $(RPM_ROOT)/BUILD
56         mkdir -p $(RPM_ROOT)/SRPMS
57         mkdir -p $(RPM_ROOT)/RPMS
58         mkdir -p $(RPM_ROOT)/tmp
59
60 rpm: rpm-dirs build build/$(JATTACH_EXE)
61         cp $(SPEC_FILE) $(RPM_ROOT)/
62         cp build/jattach $(SOURCES)/bin/
63         rpmbuild -bb \
64                 --define '_topdir $(RPM_ROOT)' \
65                 --define '_tmppath $(RPM_ROOT)/tmp' \
66                 --clean \
67                 --rmsource \
68                 --rmspec \
69                 --buildroot $(RPM_ROOT)/tmp/build-root \
70                 $(RPM_ROOT)/jattach.spec