Skip to content

Refactor Makefile #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.swp
*~
123 changes: 87 additions & 36 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,57 +1,108 @@

PYTHON_VERSION=2.7
PYTHON_LIBS=FindPackage GetAvailable GuessLatest CheckDependencies DescribeProgram UseFlags Corrections
PYTHON_SITE=lib/python$(PYTHON_VERSION)/site-packages
PROGRAM=Scripts
VERSION=git-$(shell date +%Y%m%d)
goboPrograms?=/Programs
PREFIX?=
DESTDIR=$(goboPrograms)/$(PROGRAM)/$(VERSION)
DESTDIR=$(PREFIX)/$(goboPrograms)/$(PROGRAM)/$(VERSION)

man_files = $(shell cd bin; grep -l Parse_Options * | xargs -i echo share/man/man1/{}.1)
exec_files = $(patsubst src/%.c,bin/%,$(wildcard src/*.c))
INSTALL_FILE = install
INSTALL_DIR = install -d

all: python $(exec_files) manuals
PYTHON_VERSION=2.7
PYTHON_LIBS=FindPackage GetAvailable GuessLatest CheckDependencies DescribeProgram UseFlags Corrections
PYTHON_SITE=python$(PYTHON_VERSION)/site-packages

debug: python
cd src; $(MAKE) debug
RUBY_VERSION=1.8
RUBY_SITE=ruby/site_ruby/$(RUBY_VERSION)
RUBY_DIR=$(RUBY_SITE)/gobo

MAN_FILES = $(shell cd bin;grep -l Parse_Options * | xargs -i echo share/man/man1/{}.1)
EXEC_FILES = $(patsubst src/%.c,%,$(wildcard src/*.c))
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

.PHONY: all clean install

all: python manuals
@$(MAKE) -C src
$(foreach EXE_FILE, $(EXEC_FILES), \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason for removing the generation of .pyc files?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ops! my bad! Added .pyc files generation again

cp -af src/$(EXE_FILE) bin ; \
chmod a+x bin/$(EXE_FILE) ; \
)

python:
for f in $(PYTHON_LIBS); \
do libf=$(PYTHON_SITE)/$$f.py; \
rm -f $$libf; ln -nfs ../../../bin/$$f $$libf; \
done
cd $(PYTHON_SITE) && \
mkdir -p lib/$(PYTHON_SITE)
$(foreach PYTHON_LIB, $(PYTHON_LIBS), \
ln -nfs ../../../bin/$(PYTHON_LIB) lib/$(PYTHON_SITE)/$(PYTHON_LIB).py ; \
)
cp lib/python/*.py lib/$(PYTHON_SITE)
cd lib/$(PYTHON_SITE) && \
for f in *.py; \
do python -c "import `basename $$f .py`"; \
do python -c "import `basename $$f .py`"; \
done

clean:
rm -rf Resources/FileHash*
find * -path "*~" -or -path "*/.\#*" -or -path "*.bak" | xargs rm -f
cd src && $(MAKE) clean
cd $(PYTHON_SITE) && rm -f *.pyc *.pyo
rm -f $(exec_files)
python_clean:
rm -rf lib/$(dir $(PYTHON_SITE))

clean: python_clean
@$(MAKE) -C src clean
@echo "Cleaning man pages"
rm -rf share/man/man1
@echo "Cleaning binaries"
$(foreach EXE_FILE, $(EXEC_FILES), \
rm -f src/$(EXE_FILE) ; \
rm -f bin/$(EXE_FILE) ; \
)
rm -rf Resources/FileHash*

python_install: python
@echo "Installing python libraries"
mkdir -p $(DESTDIR)/lib/$(dir $(PYTHON_SITE))
cp -r lib/$(dir $(PYTHON_SITE)) $(DESTDIR)/lib

manuals: $(man_files)
ruby_install:
@echo "Installing ruby libraries"
$(INSTALL_DIR) -d -m 755 $(DESTDIR)/lib/$(RUBY_SITE)
cp -r lib/$(RUBY_DIR) $(DESTDIR)/lib/$(RUBY_SITE)

$(man_files): share/man/man1/%.1: bin/%
$(MAN_FILES): share/man/man1/%.1: bin/%
@mkdir -p share/man/man1
help2man --name=" " --source="GoboLinux" --no-info $< --output $@

$(exec_files): bin/%: src/%
cp -af $< $@
chmod a+x $@
manuals: $(MAN_FILES)

install_manuals: $(MAN_FILES)
$(INSTALL_DIR) -d -m 755 $(DESTDIR)/share/man/man1
$(foreach MAN_FILE, $(MAN_FILES), \
$(INSTALL_FILE) -m 644 $(MAN_FILE) $(DESTDIR)/share/man/man1 ; \
)

install_scripts:
@echo "Installing scripts"
$(INSTALL_DIR) -d -m 755 $(DESTDIR)/bin
$(foreach SCRIPT_FILE, $(SCRIPT_FILES), \
$(INSTALL_FILE) -m 755 bin/$(SCRIPT_FILE) $(DESTDIR)/bin ; \
)

install_data:
@echo "Installing Data"
$(INSTALL_DIR) -d -m 755 $(DESTDIR)/Data
cp -r Data $(DESTDIR)

install_resources:
@echo "Installing Resources"
cp -r Resources $(DESTDIR)

install_share_data:
@echo "Installing share data"
cp -rf share $(DESTDIR)

src/%: src/%.c
$(MAKE) -C src
install_functions:
@echo "Installing Functions"
cp -rf Functions $(DESTDIR)

.PHONY: all python manuals debug clean
prepare_install:
@echo "Installing $(PROGRAM) into $(DESTDIR)"
$(INSTALL_DIR) -m 755 $(DESTDIR)

install: python $(exec_files) manuals
@echo "Installing Scripts into $(PREFIX)/$(DESTDIR)"
@install -d -m 755 $(PREFIX)/$(DESTDIR)
@echo "Copying files ..."
@./bin/ListProgramFiles `pwd` | grep -v "^src" | grep -v "^Makefile" | \
cpio --pass-through --quiet --verbose --unconditional $(PREFIX)/$(DESTDIR)
install: all prepare_install install_scripts install_data install_resources install_share_data install_functions python_install ruby_install install_manuals
@$(MAKE) DESTDIR=$(DESTDIR) -C src install
@echo "Installed $(PROGRAM) into $(DESTDIR)"
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion lib/python2.7/site-packages/Corrections.py

This file was deleted.

65 changes: 42 additions & 23 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -1,55 +1,74 @@

MYCFLAGS = -O2 -Wall
DESTDIR?=
CC = gcc
CFLAGS = -O2 -Wall
INSTALL_FILE=install -s
INSTALL_DIR=install -d

STATIC=-static
ifeq ($(shell uname -s),Darwin)
STATIC=
endif

# Running on windows
IS_CYGWIN=$(shell uname | grep -i cygwin &>/dev/null && echo yes || echo no)
ifeq ($(IS_CYGWIN),yes)
RM_EXE=-rm -f *.exe
endif

STATIC_CFLAGS = $(CFLAGS) -static
ifneq ($(shell uname -s),Darwin)
STATIC_CFLAGS = $(CFLAGS)
endif

# Add compiler options
ifdef DEBUG
CFLAGS += -g -DDEBUG
STATIC_CFLAGS += -g -DDEBUG
INSTALL_FILE=install
endif

exec_files = $(patsubst %.c,%,$(wildcard *.c))

dynamic_exec = BackgroundExec SuperUserName IsExecutable usleep LinkOrExpandAll List CommandNotFound GetSupportedFilesystems
static_exec = RescueSymlinkProgram
other_exec = FindDependencies Runner

# first rule
default: all

.PHONY: all default
.PHONY: all clean static debug install

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

$(dynamic_exec): %: %.c
$(CC) $(MYCFLAGS) $< -o $@
@if [ -e "[email protected]" ]; then \
@echo "Compiling $@"
$(CC) $(CFLAGS) $< -o $@
if [ -e "[email protected]" ]; then \
mv [email protected] $@; \
fi

$(static_exec): %: %.c
$(CC) $(MYCFLAGS) $< -o $@ $(STATIC)
@if [ -e "[email protected]" ]; then \
@echo "Compiling $@"
$(CC) $(STATIC_CFLAGS) $< -o $@
if [ -e "[email protected]" ]; then \
mv [email protected] $@; \
fi

FindDependencies: %: %.c
$(CC) $(MYCFLAGS) $< -o $@ -DBUILD_MAIN
@echo "Compiling $@"
$(CC) $(CFLAGS) $< -o $@ -DBUILD_MAIN

Runner: Runner.c FindDependencies.c
$(CC) $(MYCFLAGS) $^ -o $@
chmod 4755 $@

debug: MYCFLAGS = -g -DDEBUG -Wall
debug: all

static: MYCFLAGS = $(STATIC)
static: all
@echo "Compiling $@"
$(CC) $(CFLAGS) $^ -o $@

clean:
@echo "Cleaning sources"
rm -f $(dynamic_exec) $(static_exec) $(other_exec) lib*.so lib*.so.* *.o
$(RM_EXE)

.PHONY: all clean static debug install
install: all
@echo "Installing compiled binaries"
ifndef DESTDIR
$(error DESTDIR is not set)
endif
$(INSTALL_DIR) -d -m 755 $(DESTDIR)/bin
$(foreach EXEC_FILE, $(exec_files), \
$(INSTALL_FILE) -m 755 $(EXEC_FILE) $(DESTDIR)/bin ; \
)
chmod 4755 $(DESTDIR)/bin/Runner