Skip to content

Commit 295d20d

Browse files
committed
Refactor Makefile
1 parent 3ac4142 commit 295d20d

File tree

7 files changed

+123
-60
lines changed

7 files changed

+123
-60
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.swp
2+
*~

Makefile

Lines changed: 79 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,100 @@
1-
2-
PYTHON_VERSION=2.7
3-
PYTHON_LIBS=FindPackage GetAvailable GuessLatest CheckDependencies DescribeProgram UseFlags Corrections
4-
PYTHON_SITE=lib/python$(PYTHON_VERSION)/site-packages
51
PROGRAM=Scripts
62
VERSION=git-$(shell date +%Y%m%d)
73
goboPrograms?=/Programs
84
PREFIX?=
9-
DESTDIR=$(goboPrograms)/$(PROGRAM)/$(VERSION)
5+
DESTDIR=$(PREFIX)/$(goboPrograms)/$(PROGRAM)/$(VERSION)
6+
7+
INSTALL_FILE = install
8+
INSTALL_DIR = install -d
109

11-
man_files = $(shell cd bin; grep -l Parse_Options * | xargs -i echo share/man/man1/{}.1)
12-
exec_files = $(patsubst src/%.c,bin/%,$(wildcard src/*.c))
10+
PYTHON_VERSION=2.7
11+
PYTHON_LIBS=Corrections
12+
PYTHON_SITE=python$(PYTHON_VERSION)/site-packages
1313

14-
all: python $(exec_files) manuals
14+
MAN_FILES = $(shell grep -l Parse_Options bin/* | xargs -i echo {}.1)
15+
EXEC_FILES = $(patsubst src/%.c,bin/%,$(wildcard src/*.c))
16+
SCRIPT_FILES = AddUser AttachProgram DeduceName FindPackage GoboPath install PrioritiseUpdates ScriptFunctions UnversionExecutables VersionExecutables Alien AugmentCommandNotFoundDatabase Dependencies FindQuick GrepQuick InstallPackage ProblemReport SignProgram UpdateKdeRecipe which Alien-Cabal CheckDependants DescribeProgram FixAttributes GrepReplace KillProcess RemoveBroken SuggestDuplicates UpdateSettings xmlcatalog Alien-CPAN CheckDependencies DetachProgram FixDirReferences GuessLatest ListProgramFiles RemoveEmpty SuggestUpdates UpdateXorgRecipe Alien-LuaRocks CleanModules DisableProgram FixInfo GuessProgramCase RemoveProgram SymlinkProgram UpgradeSystem Alien-PIP Corrections FilterColors GenBuildInformation HasCompatiblePackage MergeTree Rename SystemFind UseFlags Alien-RubyGems CreatePackage FilterLines GetAvailable Hashes NamingConventions RescueInstallPackage SystemInfo VerifyProgram
1517

16-
debug: python
17-
cd src; $(MAKE) debug
18+
.PHONY: all clean install
1819

19-
python:
20-
for f in $(PYTHON_LIBS); \
21-
do libf=$(PYTHON_SITE)/$$f.py; \
22-
rm -f $$libf; ln -nfs ../../../bin/$$f $$libf; \
23-
done
24-
cd $(PYTHON_SITE) && \
20+
all: python_all
21+
@$(MAKE) -C src
22+
23+
python_all:
24+
mkdir -p lib/$(PYTHON_SITE)
25+
$(foreach PYTHON_LIB, $(PYTHON_LIBS), \
26+
ln -nfs ../../../bin/$(PYTHON_LIB) lib/$(PYTHON_SITE)/$(PYTHON_LIB).py ; \
27+
)
28+
cp lib/python/*.py lib/$(PYTHON_SITE)
29+
cd lib/$(PYTHON_SITE) && \
2530
for f in *.py; \
26-
do python -c "import `basename $$f .py`"; \
31+
do python -c "import `basename $$f .py`"; \
2732
done
2833

29-
clean:
34+
python_clean:
35+
rm -rf lib/$(dir $(PYTHON_SITE))
36+
37+
clean: python_clean
38+
@$(MAKE) -C src clean
39+
@echo "Cleaning man pages"
40+
$(foreach MAN_FILE, $(MAN_FILES), \
41+
rm -f $(MAN_FILE) ; \
42+
)
43+
@echo "Cleaning binaries"
44+
$(foreach EXE_FILE, $(EXEC_FILES), \
45+
rm -f $(EXE_FILE) ; \
46+
)
3047
rm -rf Resources/FileHash*
31-
find * -path "*~" -or -path "*/.\#*" -or -path "*.bak" | xargs rm -f
32-
cd src && $(MAKE) clean
33-
cd $(PYTHON_SITE) && rm -f *.pyc *.pyo
34-
rm -f $(exec_files)
35-
rm -rf share/man/man1
3648

37-
manuals: $(man_files)
49+
python_install:
50+
@echo "Installing python libraries"
51+
mkdir -p lib/$(PYTHON_SITE)
52+
cp -r lib/$(PYTHON_SITE) $(DESTDIR)/lib
53+
54+
manuals: $(MAN_FILES)
3855

39-
$(man_files): share/man/man1/%.1: bin/%
40-
@mkdir -p share/man/man1
56+
$(MAN_FILES): %.1: %
57+
@echo "Generating man page $@"
4158
help2man --name=" " --source="GoboLinux" --no-info $< --output $@
4259

43-
$(exec_files): bin/%: src/%
60+
$(EXEC_FILES): bin/%: src/%
4461
cp -af $< $@
4562
chmod a+x $@
4663

47-
src/%: src/%.c
48-
$(MAKE) -C src
64+
install_manuals: manuals
65+
$(INSTALL_DIR) -d -m 755 $(DESTDIR)/share/man/man1
66+
$(foreach MAN_FILE, $(MAN_FILES), \
67+
$(INSTALL_FILE) -m 644 $(MAN_FILE) $(DESTDIR)/share/man/man1 ; \
68+
)
69+
70+
install_scripts:
71+
@echo "Installing scripts"
72+
$(INSTALL_DIR) -d -m 755 $(DESTDIR)/bin
73+
$(foreach SCRIPT_FILE, $(SCRIPT_FILES), \
74+
$(INSTALL_FILE) -m 755 bin/$(SCRIPT_FILE) $(DESTDIR)/bin ; \
75+
)
76+
77+
install_data:
78+
@echo "Installing Data"
79+
$(INSTALL_DIR) -d -m 755 $(DESTDIR)/Data
80+
cp -r Data $(DESTDIR)
81+
82+
install_resources:
83+
@echo "Installing Resources"
84+
cp -r Resources $(DESTDIR)
85+
86+
install_share_data:
87+
@echo "Installing share data"
88+
cp -rf share $(DESTDIR)
89+
90+
install_functions:
91+
@echo "Installing Functions"
92+
cp -rf Functions $(DESTDIR)
4993

50-
.PHONY: all python manuals debug clean
94+
prepare_install:
95+
@echo "Installing $(PROGRAM) into $(DESTDIR)"
96+
$(INSTALL_DIR) -m 755 $(DESTDIR)
5197

52-
install: python $(exec_files) manuals
53-
@echo "Installing Scripts into $(PREFIX)/$(DESTDIR)"
54-
@install -d -m 755 $(PREFIX)/$(DESTDIR)
55-
@echo "Copying files ..."
56-
@./bin/ListProgramFiles `pwd` | grep -v "^src" | grep -v "^Makefile" | \
57-
cpio --pass-through --quiet --verbose --unconditional $(PREFIX)/$(DESTDIR)
98+
install: all prepare_install install_scripts install_data install_resources install_share_data install_functions python_install install_manuals
99+
@$(MAKE) DESTDIR=$(DESTDIR) -C src install
100+
@echo "Installed $(PROGRAM) into $(DESTDIR)"
File renamed without changes.

lib/python2.7/site-packages/Corrections.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/Makefile

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,74 @@
1-
2-
MYCFLAGS = -O2 -Wall
1+
DESTDIR?=
32
CC = gcc
3+
CFLAGS = -O2 -Wall
4+
INSTALL_FILE=install -s
5+
INSTALL_DIR=install -d
46

5-
STATIC=-static
6-
ifeq ($(shell uname -s),Darwin)
7-
STATIC=
8-
endif
9-
7+
# Running on windows
108
IS_CYGWIN=$(shell uname | grep -i cygwin &>/dev/null && echo yes || echo no)
119
ifeq ($(IS_CYGWIN),yes)
1210
RM_EXE=-rm -f *.exe
1311
endif
1412

13+
STATIC_CFLAGS = $(CFLAGS) -static
14+
ifneq ($(shell uname -s),Darwin)
15+
STATIC_CFLAGS = $(CFLAGS)
16+
endif
17+
18+
# Add compiler options
19+
ifdef DEBUG
20+
CFLAGS += -g -DDEBUG
21+
STATIC_CFLAGS += -g -DDEBUG
22+
INSTALL_FILE=install
23+
endif
24+
25+
exec_files = $(patsubst %.c,%,$(wildcard *.c))
26+
1527
dynamic_exec = BackgroundExec SuperUserName IsExecutable usleep LinkOrExpandAll List CommandNotFound GetSupportedFilesystems
1628
static_exec = RescueSymlinkProgram
1729
other_exec = FindDependencies Runner
1830

1931
# first rule
20-
default: all
2132

22-
.PHONY: all default
33+
.PHONY: all clean static debug install
2334

2435
all: $(dynamic_exec) $(static_exec) $(other_exec)
2536

2637
$(dynamic_exec): %: %.c
27-
$(CC) $(MYCFLAGS) $< -o $@
28-
@if [ -e "$@.exe" ]; then \
38+
@echo "Compiling $@"
39+
$(CC) $(CFLAGS) $< -o $@
40+
if [ -e "$@.exe" ]; then \
2941
mv $@.exe $@; \
3042
fi
3143

3244
$(static_exec): %: %.c
33-
$(CC) $(MYCFLAGS) $< -o $@ $(STATIC)
34-
@if [ -e "$@.exe" ]; then \
45+
@echo "Compiling $@"
46+
$(CC) $(STATIC_CFLAGS) $< -o $@
47+
if [ -e "$@.exe" ]; then \
3548
mv $@.exe $@; \
3649
fi
3750

3851
FindDependencies: %: %.c
39-
$(CC) $(MYCFLAGS) $< -o $@ -DBUILD_MAIN
52+
@echo "Compiling $@"
53+
$(CC) $(CFLAGS) $< -o $@ -DBUILD_MAIN
4054

4155
Runner: Runner.c FindDependencies.c
42-
$(CC) $(MYCFLAGS) $^ -o $@
43-
chmod 4755 $@
44-
45-
debug: MYCFLAGS = -g -DDEBUG -Wall
46-
debug: all
47-
48-
static: MYCFLAGS = $(STATIC)
49-
static: all
56+
@echo "Compiling $@"
57+
$(CC) $(CFLAGS) $^ -o $@
5058

5159
clean:
60+
@echo "Cleaning sources"
5261
rm -f $(dynamic_exec) $(static_exec) $(other_exec) lib*.so lib*.so.* *.o
5362
$(RM_EXE)
5463

55-
.PHONY: all clean static debug install
64+
install: all
65+
@echo "Installing compiled binaries"
66+
ifndef DESTDIR
67+
$(error DESTDIR is not set)
68+
endif
69+
$(INSTALL_DIR) -d -m 755 $(DESTDIR)/bin
70+
$(foreach EXEC_FILE, $(exec_files), \
71+
$(INSTALL_FILE) -m 755 $(EXEC_FILE) $(DESTDIR)/bin ; \
72+
)
73+
chmod 4755 $(DESTDIR)/bin/Runner
74+

0 commit comments

Comments
 (0)