diff --git a/.gitignore b/.gitignore index 83265b3..5886dbf 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ spm spm-*/ *.xbps *.deb -*repodata \ No newline at end of file +*repodata +exmperimental/ \ No newline at end of file diff --git a/Makefile b/Makefile index b45adb9..cf9d887 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ WEFLAGS=-Wall -Wextra -Wno-unused-parameter -Werror -pedantic -Iinclude/ -I. -Iz CFLAGS=$(WEFLAGS) -g VERSION=1.0_3 OPT=-O1 +PKG_NAME=$(TARGET)-$(VERSION) SRCD=src HEADERD=include @@ -51,26 +52,35 @@ $(BUILDD)/$(UTILSD)/%.o: $(SRCD)/$(UTILSD)/%.c $(HEADERSUTILS) $(BUILDD)/$(CMDD)/%.o: $(SRCD)/$(CMDD)/%.c $(HEADERSCMD) $(CC) $(CFLAGS) -c $< -o $@ -installdirs: executable COPYING README.md - mkdir -p $(TARGET)-$(VERSION)/usr/share/licenses/$(TARGET) - mkdir -p $(TARGET)-$(VERSION)/usr/share/doc/$(TARGET) - mkdir -p $(TARGET)-$(VERSION)/usr/bin - mkdir -p $(TARGET)-$(VERSION)/usr/share/man/man1/ - cp COPYING $(TARGET)-$(VERSION)/usr/share/licenses/$(TARGET) - cp README.md $(TARGET)-$(VERSION)/usr/share/doc/spm - cp $(TARGET) $(TARGET)-$(VERSION)/usr/bin - cp $(TARGET).1 $(TARGET)-$(VERSION)/usr/share/man/man1/ +installdirs: release COPYING README.md + mkdir -p $(PKG_NAME)/usr/share/licenses/$(TARGET) + mkdir -p $(PKG_NAME)/usr/share/doc/$(TARGET) + mkdir -p $(PKG_NAME)/usr/bin + mkdir -p $(PKG_NAME)/usr/share/man/man1/ + cp COPYING $(PKG_NAME)/usr/share/licenses/$(TARGET) + cp README.md $(PKG_NAME)/usr/share/doc/spm + cp $(TARGET) $(PKG_NAME)/usr/bin + cp $(TARGET).1 $(PKG_NAME)/usr/share/man/man1/ deb-installdirs: installdirs - mkdir -p $(TARGET)-$(VERSION)/DEBIAN - cp ./packaging/deb/DEBIAN_control $(TARGET)-$(VERSION)/DEBIAN/control + mkdir -p $(PKG_NAME)/DEBIAN + cp ./packaging/deb/DEBIAN_control $(PKG_NAME)/DEBIAN/control include ./packaging/deb/Makefile include ./packaging/xbps/Makefile clean-pkgdirs: - rm -rf $(TARGET)-$(VERSION) + rm -rf $(PKG_NAME) + +dist: dist-zip dist-gz + +dist-zip: + git archive HEAD --format=zip > $(PKG_NAME).zip + +dist-gz: + git archive HEAD --format=tar > $(PKG_NAME).tar + gzip $(PKG_NAME).tar install: release mkdir -p $(BIND) @@ -94,3 +104,5 @@ uninstall: clean: $(RM) -r $(BUILDD) $(RM) $(TARGET) + $(RM) *gz + $(RM) *zip diff --git a/README.md b/README.md index ba659f3..c701d7e 100644 --- a/README.md +++ b/README.md @@ -5,15 +5,15 @@ Suckless software starting to gain some popularity nowadays in Linux community. However, it is unlikely to become mainstream because of its suckless nature... People do not like to manually compile and patch (resolve conflicts) suckless software. Another thing that may scareaway some amount of newcomers is suckless.org website... It is so suckless that it consists of markdown files and of course doesn't have any kind of search system. So in order to patch dwm, for example, you should walk through the list of 250 patches and find that you want... -So initially this project intended to be a command line tool for searching patches on suckless.org. However later on spm got some additional functionality like downloading applying patches. It may sound like Spm now violates suckless principals :) but I don't think so. In fact it just operates on a local clone of suckless.org page, so downloading a patch literally means copying the file, viewing a patch means ```cat```ting the file... So Spm is pretty much suckless :) +So initially this project intended to be a command line tool for searching patches on suckless.org. However later on spm got some additional functionality like downloading applying patches. It may sound like Spm now violates suckless principals :) but I don't think so. In fact it just operates on a local clone of suckless.org page, so downloading a patch literally means copying the file, viewing a patch means ```cat```ting the file... --- -### Using Spm +### Using Spmn There is really not much more to say about the usage. All the commands are pretty intuitive with at most of one command line option: ``` Usage: - spm [command] [args] [options] + spmn [command] [args] [options] Commands: search [keywords] - search a patch for a with given [keywords] (default command). load - download patch for given with name. @@ -28,7 +28,7 @@ There is really not much more to say about the usage. All the commands are prett open: -b: show the web page on suckless.org for given patch in browser. load: - -a: load and apply patch at once (the same as spm apply). + -a: load and apply patch at once (the same as spmn apply). search: -f: show patch description for each patch found. apply: diff --git a/experimental/multithreaded-search-template.h b/experimental/multithreaded-search-template.h deleted file mode 100644 index b30b4a8..0000000 --- a/experimental/multithreaded-search-template.h +++ /dev/null @@ -1,88 +0,0 @@ -/* -static size_t calc_threadcount(int entrycnt) { - int optentrycnt = OPTWORK_AMOUNT * OPTTHREAD_COUNT; - if (entrycnt > optentrycnt) { - return OPTTHREAD_COUNT; - } else { - float actualthrcount = (double)entrycnt / (double)OPTWORK_AMOUNT; - int nearest_thrcount = floor((double)actualthrcount); - int workdiff = (actualthrcount * 100) - (nearest_thrcount * 100); - - if (workdiff < MIN_WORKAMOUNT) - return nearest_thrcount; - - return nearest_thrcount + 1; - } -} -*/ - - - - -/* -int -run_multithreaded(char *patchdir, searchsyms *searchargs, const int entrycnt) { - pthread_t *threadpool; - pthread_mutex_t fmutex; - lookupthread_args *thargs; - FILE *rescache; - int rescachefd; - size_t thpoolsize, thcount; - char rescachename[] = RESULTCACHE, resc; - int res = EXIT_FAILURE; - - rescachefd = mkstemp(rescachename); - if (rescachefd == -1) { - EPERROR(); - return res; - } - - thcount = calc_threadcount(entrycnt); - thpoolsize = sizeof(*threadpool) * thcount; - - threadpool = calloc(1, thpoolsize); - if (!threadpool) { - perrfatal(); - goto cleanup; - } - - thargs = malloc(sizeof(*thargs) * thcount); - if (!thargs) { - perrfatal(); - goto cleanup; - } - - pthread_mutex_init(&fmutex, NULL); - - for (size_t tid = 0; tid < thcount; tid++) { - if (setup_threadargs(thargs, tid, thcount, entrycnt, rescachefd, - searchargs, patchdir, &fmutex)) { - return res; - } - pthread_create(threadpool + tid, NULL, &search_entry, thargs + tid); - } - - for (size_t tid = 0; tid < thcount; tid++) { - pthread_join(threadpool[tid], NULL); - res |= thargs[tid].result; - cleanup_threadargs(thargs + tid); - } - - UNWRAP_L (pthread_mutex_destroy(&fmutex)) - free(threadpool); - TRY(rescache = fdopen(rescachefd, "r")) - WITH( - fcache_error(); - res = 1; - goto cleanup) - - while ((resc = fgetc(rescache)) != EOF) { - fputc(resc, stdout); - } - -cleanup: - fclose(rescache); - remove(rescachename); - return !!res; - return 0; -}*/ diff --git a/packaging/deb/DEBIAN_control b/packaging/deb/DEBIAN_control index 79d4b32..d59ab7d 100644 --- a/packaging/deb/DEBIAN_control +++ b/packaging/deb/DEBIAN_control @@ -1,8 +1,8 @@ -Package: spm +Package: spmn Version: 0.3.1 Section: development Priority: optional Architecture: amd64 Depends: xdg-utils, git, libbsd0 -Maintainer: Viacheslav +Maintainer: Viacheslav Description: Suckless patch manager diff --git a/packaging/deb/Dockerfile b/packaging/deb/Dockerfile index 10f3823..2ff5dc1 100644 --- a/packaging/deb/Dockerfile +++ b/packaging/deb/Dockerfile @@ -1,9 +1,8 @@ FROM gcc:12.1-bullseye -RUN mkdir -p /usr/src/spm -COPY . /usr/src/spm -WORKDIR /usr/src/spm +RUN mkdir -p /usr/src/spmn +COPY . /usr/src/spmn +WORKDIR /usr/src/spmn RUN apt update && apt upgrade -y RUN apt install -y apt-utils -RUN apt install -y make build-essential binutils lintian debhelper dh-make devscripts - +RUN apt install -y make build-essential binutils lintian debhelper dh-make devscripts libbsd0 libbsd-dev diff --git a/packaging/deb/Makefile b/packaging/deb/Makefile index b2fbd9f..a4d6de1 100644 --- a/packaging/deb/Makefile +++ b/packaging/deb/Makefile @@ -1,18 +1,18 @@ -build-base-img: +build-deb-base-img: docker build -t deb-pkg-base -f ./packaging/deb/Dockerfile . -build-bin-img: - @docker build -t deb-pkg-bin-$(TARGET)-$(VERSION) -f ./packaging/deb/bin/Dockerfile . +build-deb-bin-img: + @docker build -t deb-pkg-bin-$(PKG_NAME) -f ./packaging/deb/bin/Dockerfile . build-deb: - @docker run -v $(shell pwd):/usr/src/$(TARGET) deb-pkg-bin-$(TARGET)-$(VERSION) + @docker run -v $(shell pwd):/usr/src/$(TARGET) --env PKG_FULL_NAME=$(PKG_NAME) deb-pkg-bin-$(PKG_NAME) -build-src-img: - @docker build -t deb-pkg-src-$(TARGET)-$(VERSION) -f ./packaging/deb/src/Dockerfile . +build-deb-src-img: + @docker build -t deb-pkg-src-$(PKG_NAME) -f ./packaging/deb/src/Dockerfile . build-src-deb: - @docker run -v $(shell pwd):/usr/src/$(TARGET) deb-pkg-src-$(TARGET)-$(VERSION) + @docker run -v $(shell pwd):/usr/src/$(TARGET) deb-pkg-src-$(PKG_NAME) clean-deb: rm -f *.deb diff --git a/packaging/deb/bin/deb-build.sh b/packaging/deb/bin/deb-build.sh index 35b1922..c21a812 100755 --- a/packaging/deb/bin/deb-build.sh +++ b/packaging/deb/bin/deb-build.sh @@ -1,5 +1,5 @@ #!/bin/sh make deb-installdirs -dpkg-deb --build spm-1.0_3/ +dpkg-deb --build "$PKG_FULL_NAME"/ make clean-pkgdirs diff --git a/packaging/xbps/Makefile b/packaging/xbps/Makefile index cd2ded0..b05ece9 100644 --- a/packaging/xbps/Makefile +++ b/packaging/xbps/Makefile @@ -1,6 +1,6 @@ build-xbps: installdirs - ./packaging/xbps/xbps-create.sh $(TARGET)-$(VERSION) "x86_64" - ./packaging/xbps/xbps-create.sh $(TARGET)-$(VERSION) "amd64" + ./packaging/xbps/xbps-create.sh $(PKG_NAME) "x86_64" + ./packaging/xbps/xbps-create.sh $(PKG_NAME) "amd64" clean-xbps: $(RM) *.xbps diff --git a/spm.1 b/spmn.1 similarity index 100% rename from spm.1 rename to spmn.1 diff --git a/src/main.c b/src/main.c index 8a45ac6..822d8a9 100644 --- a/src/main.c +++ b/src/main.c @@ -48,17 +48,8 @@ typedef int (*commandp)(int, char **, const char *); #define CMD_CNT 7 -result help(int argc, char **argv, const char *basecacherepo) { - KINDA_USE_3ARG(argc, argv, basecacherepo); - print_usage(); - RET_OK() -} - -result version(int argc, char **argv, const char *basecacherepo) { - KINDA_USE_3ARG(argc, argv, basecacherepo); - print_version(); - RET_OK() -} +result help(int, char **, const char *); +result version(int, char **, const char *); static const commandp commands[CMD_CNT] = { &parse_sync_args, &parse_search_args, &parse_open_args, @@ -84,6 +75,18 @@ static int local_repo_is_obsolete(struct tm *cttm, struct tm *lmttm) { (cttm->tm_year > lmttm->tm_year && cttm->tm_mday > SYNC_INTERVAL_D); } +result help(int argc, char **argv, const char *basecacherepo) { + KINDA_USE_3ARG(argc, argv, basecacherepo); + print_usage(); + RET_OK() +} + +result version(int argc, char **argv, const char *basecacherepo) { + KINDA_USE_3ARG(argc, argv, basecacherepo); + print_version(); + RET_OK() +} + static result try_sync_caches(const char *basecacherepo) { struct stat cache_sb = {0}; time_t lastmtime, curtime;